{"id":18499265,"url":"https://github.com/caremessageplatform/rspec-request_snapshot","last_synced_at":"2025-04-09T01:31:37.175Z","repository":{"id":33548817,"uuid":"157854208","full_name":"CareMessagePlatform/rspec-request_snapshot","owner":"CareMessagePlatform","description":null,"archived":false,"fork":false,"pushed_at":"2024-02-07T12:31:27.000Z","size":87,"stargazers_count":12,"open_issues_count":0,"forks_count":3,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-03-19T19:18:05.069Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/CareMessagePlatform.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-16T10:50:14.000Z","updated_at":"2024-07-12T07:55:30.000Z","dependencies_parsed_at":"2024-11-06T13:47:58.284Z","dependency_job_id":"875ea783-cc21-47e0-a182-5c4eb2877ae9","html_url":"https://github.com/CareMessagePlatform/rspec-request_snapshot","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CareMessagePlatform%2Frspec-request_snapshot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CareMessagePlatform%2Frspec-request_snapshot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CareMessagePlatform%2Frspec-request_snapshot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CareMessagePlatform%2Frspec-request_snapshot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CareMessagePlatform","download_url":"https://codeload.github.com/CareMessagePlatform/rspec-request_snapshot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247956552,"owners_count":21024570,"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":[],"created_at":"2024-11-06T13:45:11.480Z","updated_at":"2025-04-09T01:31:36.789Z","avatar_url":"https://github.com/CareMessagePlatform.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rspec::RequestSnapshot\n\nGold master testing for RSpec API request specs. Make sure API behavior is not changing by taking and storing a snapshot from an API response on a first run and check if they match on next spec runs.\n\nBy default, snapshots are stored under `spec/fixtures/snapshots` and should be code reviewed as well. The syntax is inspired by Jest.\n\nReferences:\n\n* [Gold Master Testing article by CodeClimate](https://codeclimate.com/blog/gold-master-testing/)\n* [Jest Snapshot Testing](https://jestjs.io/docs/en/snapshot-testing)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'rspec-request_snapshot'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install rspec-request_snapshot\n\n## Usage\n\n### Configuration\n\n```ruby\nRSpec.configure do |config|\n  # The place where snapshots will be stored\n  # Default value is spec/fixtures/snapshots\n  config.request_snapshots_dir = \"spec/fixtures/snapshots\"\n\n  # The json attributes that you want to ignore when comparing snapshots\n  # Default value is [id, created_at, updated_at]\n  config.request_snapshots_dynamic_attributes = %w(id created_at updated_at)\n\n  # The json attributes that ignore order when comparing nodes\n  # Default value is []\n  config.request_snapshots_ignore_order = %w(array_node)\n\n  # The default format to use, other formats must be specified using the :format option\n  # Default value is :json\n  config.request_snapshots_default_format = :json\nend\n```\n\n### Snapshot files\n\nOn the first run, the `match_snapshot` matcher will always return success and it will store a snapshot file. On the next runs, it will compare the response with the file content.\n\nIf you need to replace snapshots, run the specs with:\n\n    REPLACE_SNAPSHOTS=true bundle exec rspec\n\nIf you only need to add, remove or replace data without replacing the whole snapshot:\n\n    CONSERVATIVE_UPDATE_SNAPSHOTS=true bundle exec rspec\n\n**Note:** Conservative update will not work along with ignore_order option. It should only be used when there is\nno major changes in the snapshots that will be updated.\n\nIf you want tests to fail in case a snapshot file does not exist (ie: when running on a CI):\n\n    BLOCK_CREATE_SNAPSHOTS=true bundle exec rspec\n\n### Matcher\n\n```ruby\n# Stores snapshot under spec/fixtures/snapshots/api/resources_index.json\nexpect(response.body).to match_snapshot(\"api/resources_index\")\n\n# Using plain text instead of parsing JSON\nexpect(response.body).to match_snapshot(\"api/resources_index\", format: :text)\n```\n\n#### Matcher options\n\n##### dynamic_attributes\n\nUsing `dynamic_attributes` inline allows to ignore attributes for a specific snapshot.\nThis is useful to ignore changing attributes, like `id` or `created_at`.\nNotice that **all** nodes matching those (nested or not) will be ignored. Usage:\n\n```ruby\n# Defining specific test dynamic attributes\nexpect(response.body).to match_snapshot(\"api/resources_index\", dynamic_attributes: %w(confirmed_at relation_id))\n```\n\n##### dynamic_attributes with regex\n\nSometimes you don't want to fully ignore an attribute. For example, you want to make sure\nthat `generated_id` is present and following a given pattern, but that attribute can change\nrandonly, use `dynamic_attributes` with object/regex notation:\n\n```ruby\n# Example generated_id: ABC-001\nexpect(response.body).to match_snapshot(\"api/resources_index\", dynamic_attributes: [{ generated_id: /^\\w{3}-\\d{3}$/ }])\n```\n\n**Note:** Partial matches are also possible, so use the start/end of line characters for a strict match\n\n##### ignore_order\n\nIt is possible to use the `ignore_order` inline option to mark which array nodes are unsorted and that elements position\nshould not be taken into consideration.\n\n```ruby\n# Ignoring order for certain arrays (this will ignore the ordering for the countries array inside the json response)\nexpect(response.body).to match_snapshot(\"api/resources_index\", ignore_order: %w(countries))\n```\n\n**Note:** If you are using `ignore_order` for arrays of objects/hashes (ie: `[{name: \"name\", value: \"value\"}, ...]`),\nit won't perform well depending on the array and hash size (number of keys)\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\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/CareMessagePlatform/rspec-request_snapshot.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaremessageplatform%2Frspec-request_snapshot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaremessageplatform%2Frspec-request_snapshot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaremessageplatform%2Frspec-request_snapshot/lists"}