Skip to content

Commit

Permalink
Add examples of named snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
rzane committed Dec 26, 2019
1 parent d6165c1 commit c656fa5
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ cache: bundler
rvm:
- 2.6.3
before_install: gem install bundler -v 2.0.2

script:
- bundle exec rspec
- bundle exec rake examples
1 change: 1 addition & 0 deletions examples/__snapshots__/named.minitest.spec.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
named
1 change: 1 addition & 0 deletions examples/__snapshots__/named.minitest.test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
named
1 change: 1 addition & 0 deletions examples/__snapshots__/named.rspec.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
named
1 change: 1 addition & 0 deletions examples/__snapshots__/named.unit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
named
12 changes: 10 additions & 2 deletions examples/minitest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@ def test_snapshot
assert_snapshot "hello"
assert_snapshot "goodbye"
end

def test_named_snapshot
assert_snapshot "named.minitest.test.txt", "named"
end
end

class ExampleSpec < Minitest::Spec
include SnapshotTesting::Minitest

it "takes a snapshot" do
"hello".must_match_snapshot
"goodbye".must_match_snapshot
_("hello").must_match_snapshot
_("goodbye").must_match_snapshot
end

it "takes a named snapshot" do
_("named").must_match_snapshot "named.minitest.spec.txt"
end
end
4 changes: 4 additions & 0 deletions examples/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@
expect("hello").to match_snapshot
expect("goodbye").to match_snapshot
end

it "takes a named snapshot" do
expect("named").to match_snapshot("named.rspec.txt")
end
end
4 changes: 4 additions & 0 deletions examples/test_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ def test_snapshot
assert_snapshot "hello"
assert_snapshot "goodbye"
end

def test_named_snapshot
assert_snapshot "named.unit.txt", "named"
end
end
2 changes: 1 addition & 1 deletion lib/snapshot_testing/minitest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Minitest
def self.included(_)
return unless defined?(::Minitest::Expectations)
return if ::Minitest::Expectations.method_defined?(:must_match_snapshot)
::Minitest::Expectations.infect_an_assertion(:assert_snapshot, :must_match_snapshot, true)
::Minitest::Expectations.infect_an_assertion(:assert_snapshot, :must_match_snapshot)
end

def before_setup
Expand Down

0 comments on commit c656fa5

Please sign in to comment.