项目作者: gadget-inc

项目描述 :
Minitest plugin for asserting that strings are the same as a saved snapshot, jest style
高级语言: Ruby
项目地址: git://github.com/gadget-inc/minitest-snapshots.git
创建时间: 2019-09-11T21:32:37Z
项目社区:https://github.com/gadget-inc/minitest-snapshots

开源协议:MIT License

下载


Minitest::Snapshots

Gem Version
Gem Downloads
GitHub Workflow Status

Simple minitest plugin gem implementing Jest-style snapshot testing. It’s like VCR, but for any value.

Requirements

  • Ruby 2.7 or later

Usage

Instead of copying and pasting large segments of machine generated text into your test files, and updating them all the time, assert against a snapshot managed by this library. The first time the snapshot assertion is run it will write the value to disk, and then then next time, it will check against that value.

Example:

  1. class QueryCompilerText < Minitest::Test
  2. def test_it_can_compile_a_query
  3. assert_matches_snapshot QueryCompiler.new.compile
  4. end
  5. end

Command line options

  • -u or --update-snapshots: Update snapshots on disk to the new actual value when re-running the test. Useful when you know the new output of a test case is correct and the snapshot is out of date.
  • -l or --lock-snapshots: Prevents new snapshots from being written. This is enabled by default in CI (i.e. when the CI env var is present).

For example, to update snapshots on a Rails project:

  1. bin/rails test -u

In a Rake project:

  1. rake test TESTOPTS=-u

Installation

Add this line to your application’s Gemfile:

  1. gem 'minitest-snapshots'

And then execute:

  1. $ bundle

Or install it yourself as:

  1. $ gem install minitest-snapshots

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

To 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.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/mattbrictson/minitest-snapshots.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the this project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

History

minitest-snapshots was created by Harry Brundage (@airhorns) and originally published to rubygems in 2019. Significant contributions were added by @chocolateboy in 2020. In June 2023, ownership of the project was transferred to Matt Brictson (@mattbrictson).