1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
Feature: define diffable matcher
When a matcher is defined as diffable, the output will include a diff of the submitted objects when the objects are more than simple primitives.
@skip-when-diff-lcs-1.3
Scenario: define a diffable matcher (with diff-lcs 1.4)
Given a file named "diffable_matcher_spec.rb" with:
"""ruby
RSpec::Matchers.define :be_just_like do |expected|
match do |actual|
actual == expected
end
diffable
end
RSpec.describe "two\nlines" do
it { is_expected.to be_just_like("three\nlines") }
end
"""
When I run `rspec ./diffable_matcher_spec.rb`
Then it should fail with:
"""
Diff:
@@ -1 +1 @@
-three
+two
"""
@skip-when-diff-lcs-1.4
Scenario: define a diffable matcher (with diff-lcs 1.3)
Given a file named "diffable_matcher_spec.rb" with:
"""ruby
RSpec::Matchers.define :be_just_like do |expected|
match do |actual|
actual == expected
end
diffable
end
RSpec.describe "two\nlines" do
it { is_expected.to be_just_like("three\nlines") }
end
"""
When I run `rspec ./diffable_matcher_spec.rb`
Then it should fail with:
"""
Diff:
@@ -1,3 +1,3 @@
-three
+two
lines
"""
@skip-when-diff-lcs-1.3
Scenario: Redefine actual (with diff-lcs 1.4.4)
Sometimes is neccessary to overwrite actual to make diffing work, e.g. if `actual` is a name of a file you want to read from. For this to work you need to overwrite `@actual` in your matcher.
Given a file named "redefine_actual_matcher_spec.rb" with:
"""ruby
RSpec::Matchers.define :have_content do |expected|
match do |actual|
@actual = File.read(actual).chomp
values_match? expected, @actual
end
diffable
end
RSpec.describe 'Compare files' do
context 'when content is equal' do
it { expect('data.txt').to have_content 'Data' }
end
context 'when files are different' do
it { expect('data.txt').to have_content "No\nData\nhere" }
end
end
"""
And a file named "data.txt" with:
"""
Data
"""
When I run `rspec ./redefine_actual_matcher_spec.rb --format documentation`
Then the exit status should not be 0
And the output should contain:
"""
2 examples, 1 failure
"""
And the output should contain:
"""
@@ -1,4 +1,2 @@
-No
Data
-here
"""
@skip-when-diff-lcs-1.4
Scenario: Redefine actual (with diff-lcs 1.3)
Given a file named "redefine_actual_matcher_spec.rb" with:
"""ruby
RSpec::Matchers.define :have_content do |expected|
match do |actual|
@actual = File.read(actual).chomp
values_match? expected, @actual
end
diffable
end
RSpec.describe 'Compare files' do
context 'when content is equal' do
it { expect('data.txt').to have_content 'Data' }
end
context 'when files are different' do
it { expect('data.txt').to have_content "No\nData\nhere" }
end
end
"""
And a file named "data.txt" with:
"""
Data
"""
When I run `rspec ./redefine_actual_matcher_spec.rb --format documentation`
Then the exit status should not be 0
And the output should contain:
"""
2 examples, 1 failure
"""
And the output should contain:
"""
@@ -1,4 +1,2 @@
-No
Data
-here
"""
|