{"id":15240463,"url":"https://github.com/juanmanuelramallo/rspec-log_matcher","last_synced_at":"2025-10-10T08:40:12.773Z","repository":{"id":56892903,"uuid":"297106005","full_name":"juanmanuelramallo/rspec-log_matcher","owner":"juanmanuelramallo","description":"An RSpec custom matcher to test code that logs information into log files.","archived":false,"fork":false,"pushed_at":"2020-10-03T22:53:01.000Z","size":28,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T12:21:47.134Z","etag":null,"topics":["logging","rspec","rspec-matchers","rspec-rails"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/juanmanuelramallo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-09-20T15:30:03.000Z","updated_at":"2024-07-16T22:49:52.000Z","dependencies_parsed_at":"2022-08-21T01:20:57.166Z","dependency_job_id":null,"html_url":"https://github.com/juanmanuelramallo/rspec-log_matcher","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanmanuelramallo%2Frspec-log_matcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanmanuelramallo%2Frspec-log_matcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanmanuelramallo%2Frspec-log_matcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanmanuelramallo%2Frspec-log_matcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juanmanuelramallo","download_url":"https://codeload.github.com/juanmanuelramallo/rspec-log_matcher/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248226285,"owners_count":21068177,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["logging","rspec","rspec-matchers","rspec-rails"],"created_at":"2024-09-29T11:05:07.284Z","updated_at":"2025-10-10T08:40:07.742Z","avatar_url":"https://github.com/juanmanuelramallo.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RSpec::LogMatcher\n\n[![Gem Version](https://badge.fury.io/rb/rspec-log_matcher.svg)](https://badge.fury.io/rb/rspec-log_matcher)\n[![ci](https://github.com/juanmanuelramallo/rspec-log_matcher/workflows/ci/badge.svg?branch=master)](https://github.com/juanmanuelramallo/rspec-log_matcher/actions)\n[![Maintainability](https://api.codeclimate.com/v1/badges/145ad4334a67d5e1f8a2/maintainability)](https://codeclimate.com/github/juanmanuelramallo/rspec-log_matcher/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/145ad4334a67d5e1f8a2/test_coverage)](https://codeclimate.com/github/juanmanuelramallo/rspec-log_matcher/test_coverage)\n\n## What is this?\nAn RSpec custom matcher to test code that logs information into log files.\n\nWriting logs is an easy way to store any kind of information for further analysis later on. It's commonly used to store analytics events and then make the logs a data source for data engineering tasks. This matcher makes application-logging-testing easier.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngroup :test do\n  gem 'rspec-log_matcher'\nend\n```\n\nAnd then execute:\n\n    $ bundle install\n\nLastly, in your `spec_helper.rb` (or `rails_helper.rb`) add the following line inside the configuration block:\n\n```ruby\nRSpec.configure do |config|\n  # [snip]\n\n  RSpec::LogMatcher.configure!(config)\nend\n```\n\n## Usage\n\n### Plain old ruby objects\n\n```ruby\n# app/services/payment_service.rb\nclass PaymentService\n  def self.call\n    # [snip]\n\n    logger.info \"event=payment-successful properties=#{data.to_json}\"\n  end\nend\n```\n\n```ruby\n# spec/services/payment_service_spec.rb\nrequire 'spec_helper'\n\nRSpec.describe PaymentService do\n  describe '.call' do\n    subject { described_class.call }\n\n    it 'logs event information' do\n      expect { subject }.to log(\"event=payment-successful properties=#{build_expected_json}\")\n    end\n  end\nend\n```\n\n### Request specs\n```ruby\n# spec/requests/users_spec.rb\nrequire 'spec_helper'\n\nRSpec.describe 'Users' do\n  describe 'GET /index' do\n    expect { get(users_path) }.to log('Page view - Users index')\n  end\nend\n```\n\n### Feature specs\n\n```ruby\n# spec/features/sign_in_spec.rb\nrequire 'spec_helper'\n\nRSpec.feature 'Sign in' do\n  scenario 'successful sign in' do\n    user = create(:user)\n\n    visit sign_in_path\n    fill_form(user)\n    submit_form\n\n    expect(page).to have_text('Welcome!')\n    expect(page).to log(\"User #{user.id} has logged in\")\n  end\nend\n```\n\nRegular expressions and procs are also valid object types for the expected logs, for more use cases refer to the [spec file](https://github.com/juanmanuelramallo/rspec-log_matcher/blob/master/spec/rspec-log_matcher_spec.rb).\n\n## Configuration\n\nThe default path for the log file is `log/test.log`. It can be configured via an environment variable called `LOG_PATH`.\n\nThis is useful when tests are run parallely, and each process has their own log file.\n\n## How it works?\n\nThe matcher reads into the log file and looks for the expected logs to be present in the log file.\n\nWhen the subject is a proc, the matcher will execute proc and compare against the logs introduced by the proc execution.\n\nWhen the subject is a Capybara::Session (from a feature spec, system tests), the matcher will store the position in the file to the last byte in a before hook. Then, when the example is run, it will compare against the changes introduced by the example using the position stored as the beginning of the logs.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/juanmanuelramallo/rspec-log_matcher. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/juanmanuelramallo/rspec-log_matcher/blob/master/CODE_OF_CONDUCT.md).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Rspec::LogMatcher project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/juanmanuelramallo/rspec-log_matcher/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuanmanuelramallo%2Frspec-log_matcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuanmanuelramallo%2Frspec-log_matcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuanmanuelramallo%2Frspec-log_matcher/lists"}