rspec-expectations 2.12.1 → 2.13.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +31 -0
- data/README.md +1 -1
- data/features/built_in_matchers/be.feature +6 -4
- data/features/built_in_matchers/be_within.feature +3 -1
- data/features/built_in_matchers/cover.feature +2 -0
- data/features/built_in_matchers/end_with.feature +2 -0
- data/features/built_in_matchers/equality.feature +9 -15
- data/features/built_in_matchers/exist.feature +2 -0
- data/features/built_in_matchers/expect_error.feature +14 -8
- data/features/built_in_matchers/have.feature +11 -5
- data/features/built_in_matchers/include.feature +53 -0
- data/features/built_in_matchers/match.feature +2 -0
- data/features/built_in_matchers/operators.feature +17 -11
- data/features/built_in_matchers/predicates.feature +21 -13
- data/features/built_in_matchers/respond_to.feature +7 -1
- data/features/built_in_matchers/satisfy.feature +2 -0
- data/features/built_in_matchers/start_with.feature +2 -0
- data/features/built_in_matchers/throw_symbol.feature +6 -0
- data/features/built_in_matchers/types.feature +8 -6
- data/lib/rspec/expectations/deprecation.rb +1 -1
- data/lib/rspec/expectations/differ.rb +8 -8
- data/lib/rspec/expectations/fail_with.rb +17 -3
- data/lib/rspec/expectations/syntax.rb +46 -0
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/matchers/built_in/be.rb +7 -3
- data/lib/rspec/matchers/built_in/be_within.rb +13 -4
- data/lib/rspec/matchers/built_in/change.rb +2 -2
- data/lib/rspec/matchers/built_in/equal.rb +5 -1
- data/lib/rspec/matchers/built_in/exist.rb +1 -1
- data/lib/rspec/matchers/built_in/have.rb +8 -8
- data/lib/rspec/matchers/built_in/include.rb +19 -3
- data/lib/rspec/matchers/built_in/respond_to.rb +1 -1
- data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +1 -1
- data/lib/rspec/matchers/matcher.rb +4 -3
- data/lib/rspec/matchers/operator_matcher.rb +1 -1
- data/lib/rspec/matchers/pretty.rb +5 -1
- data/spec/rspec/expectations/differ_spec.rb +8 -15
- data/spec/rspec/expectations/expectation_target_spec.rb +18 -8
- data/spec/rspec/expectations/extensions/kernel_spec.rb +15 -15
- data/spec/rspec/expectations/fail_with_spec.rb +41 -16
- data/spec/rspec/expectations/handler_spec.rb +13 -13
- data/spec/rspec/expectations/syntax_spec.rb +70 -8
- data/spec/rspec/matchers/base_matcher_spec.rb +14 -12
- data/spec/rspec/matchers/be_close_spec.rb +1 -1
- data/spec/rspec/matchers/be_instance_of_spec.rb +14 -8
- data/spec/rspec/matchers/be_kind_of_spec.rb +12 -8
- data/spec/rspec/matchers/be_spec.rb +212 -148
- data/spec/rspec/matchers/be_within_spec.rb +91 -42
- data/spec/rspec/matchers/change_spec.rb +52 -38
- data/spec/rspec/matchers/configuration_spec.rb +19 -15
- data/spec/rspec/matchers/cover_spec.rb +19 -19
- data/spec/rspec/matchers/description_generation_spec.rb +86 -86
- data/spec/rspec/matchers/dsl_spec.rb +7 -7
- data/spec/rspec/matchers/eq_spec.rb +17 -11
- data/spec/rspec/matchers/eql_spec.rb +10 -10
- data/spec/rspec/matchers/equal_spec.rb +27 -9
- data/spec/rspec/matchers/exist_spec.rb +35 -21
- data/spec/rspec/matchers/has_spec.rb +33 -29
- data/spec/rspec/matchers/have_spec.rb +165 -151
- data/spec/rspec/matchers/include_matcher_integration_spec.rb +30 -0
- data/spec/rspec/matchers/include_spec.rb +282 -124
- data/spec/rspec/matchers/match_array_spec.rb +90 -49
- data/spec/rspec/matchers/match_spec.rb +21 -21
- data/spec/rspec/matchers/matcher_spec.rb +85 -48
- data/spec/rspec/matchers/matchers_spec.rb +12 -6
- data/spec/rspec/matchers/method_missing_spec.rb +5 -1
- data/spec/rspec/matchers/operator_matcher_spec.rb +216 -237
- data/spec/rspec/matchers/raise_error_spec.rb +132 -132
- data/spec/rspec/matchers/respond_to_spec.rb +109 -112
- data/spec/rspec/matchers/satisfy_spec.rb +16 -16
- data/spec/rspec/matchers/start_with_end_with_spec.rb +36 -32
- data/spec/rspec/matchers/throw_symbol_spec.rb +24 -24
- data/spec/rspec/matchers/yield_spec.rb +7 -7
- data/spec/spec_helper.rb +46 -19
- data/spec/support/in_sub_process.rb +27 -20
- metadata +81 -83
@@ -14,11 +14,50 @@ class UnsortableObject
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
describe "
|
18
|
-
|
19
|
-
|
17
|
+
describe "should =~ array", :uses_should do
|
18
|
+
it "passes a valid positive expectation" do
|
19
|
+
[1, 2].should =~ [2, 1]
|
20
|
+
end
|
21
|
+
|
22
|
+
it "fails an invalid positive expectation" do
|
23
|
+
expect {
|
24
|
+
[1, 2, 3].should =~ [2, 1]
|
25
|
+
}.to fail_with(/expected collection contained/)
|
20
26
|
end
|
21
27
|
|
28
|
+
context "when the array defines a `=~` method" do
|
29
|
+
it 'delegates to that method rather than using the match_array matcher' do
|
30
|
+
array = []
|
31
|
+
def array.=~(other)
|
32
|
+
other == :foo
|
33
|
+
end
|
34
|
+
|
35
|
+
array.should =~ :foo
|
36
|
+
expect {
|
37
|
+
array.should =~ :bar
|
38
|
+
}.to fail_with(/expected: :bar/)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when the array defines a `send` method' do
|
43
|
+
it 'still works' do
|
44
|
+
array = [1, 2]
|
45
|
+
def array.send; :sent; end
|
46
|
+
|
47
|
+
array.should =~ array
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "should_not =~ [:with, :multiple, :args]", :uses_should do
|
53
|
+
it "is not supported" do
|
54
|
+
expect {
|
55
|
+
[1,2,3].should_not =~ [1,2,3]
|
56
|
+
}.to fail_with(/Matcher does not support should_not/)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "using match_array with expect" do
|
22
61
|
it "passes a valid positive expectation" do
|
23
62
|
expect([1, 2]).to match_array [2, 1]
|
24
63
|
end
|
@@ -30,19 +69,23 @@ describe "using match_array with expect" do
|
|
30
69
|
end
|
31
70
|
end
|
32
71
|
|
33
|
-
describe "array.
|
72
|
+
describe "expect(array).to match_array other_array" do
|
73
|
+
it_behaves_like "an RSpec matcher", :valid_value => [1, 2], :invalid_value => [1] do
|
74
|
+
let(:matcher) { match_array([2, 1]) }
|
75
|
+
end
|
76
|
+
|
34
77
|
it "passes if target contains all items" do
|
35
|
-
[1,2,3].
|
78
|
+
expect([1,2,3]).to match_array [1,2,3]
|
36
79
|
end
|
37
80
|
|
38
81
|
it "passes if target contains all items out of order" do
|
39
|
-
[1,3,2].
|
82
|
+
expect([1,3,2]).to match_array [1,2,3]
|
40
83
|
end
|
41
84
|
|
42
85
|
it "fails if target includes extra items" do
|
43
|
-
|
44
|
-
[1,2,3,4].
|
45
|
-
}.
|
86
|
+
expect {
|
87
|
+
expect([1,2,3,4]).to match_array [1,2,3]
|
88
|
+
}.to fail_with(<<-MESSAGE)
|
46
89
|
expected collection contained: [1, 2, 3]
|
47
90
|
actual collection contained: [1, 2, 3, 4]
|
48
91
|
the extra elements were: [4]
|
@@ -50,9 +93,9 @@ MESSAGE
|
|
50
93
|
end
|
51
94
|
|
52
95
|
it "fails if target is missing items" do
|
53
|
-
|
54
|
-
[1,2].
|
55
|
-
}.
|
96
|
+
expect {
|
97
|
+
expect([1,2]).to match_array [1,2,3]
|
98
|
+
}.to fail_with(<<-MESSAGE)
|
56
99
|
expected collection contained: [1, 2, 3]
|
57
100
|
actual collection contained: [1, 2]
|
58
101
|
the missing elements were: [3]
|
@@ -60,10 +103,9 @@ MESSAGE
|
|
60
103
|
end
|
61
104
|
|
62
105
|
it "fails if target is missing items and has extra items" do
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
}.should fail_with(<<-MESSAGE)
|
106
|
+
expect {
|
107
|
+
expect([1,2,4]).to match_array [1,2,3]
|
108
|
+
}.to fail_with(<<-MESSAGE)
|
67
109
|
expected collection contained: [1, 2, 3]
|
68
110
|
actual collection contained: [1, 2, 4]
|
69
111
|
the missing elements were: [3]
|
@@ -72,9 +114,9 @@ MESSAGE
|
|
72
114
|
end
|
73
115
|
|
74
116
|
it "sorts items in the error message if they all respond to <=>" do
|
75
|
-
|
76
|
-
[6,2,1,5].
|
77
|
-
}.
|
117
|
+
expect {
|
118
|
+
expect([6,2,1,5]).to match_array [4,1,2,3]
|
119
|
+
}.to fail_with(<<-MESSAGE)
|
78
120
|
expected collection contained: [1, 2, 3, 4]
|
79
121
|
actual collection contained: [1, 2, 5, 6]
|
80
122
|
the missing elements were: [3, 4]
|
@@ -83,9 +125,9 @@ MESSAGE
|
|
83
125
|
end
|
84
126
|
|
85
127
|
it "does not sort items in the error message if they don't all respond to <=>" do
|
86
|
-
|
87
|
-
[UnsortableObject.new(2), UnsortableObject.new(1)].
|
88
|
-
}.
|
128
|
+
expect {
|
129
|
+
expect([UnsortableObject.new(2), UnsortableObject.new(1)]).to match_array [UnsortableObject.new(4), UnsortableObject.new(3)]
|
130
|
+
}.to fail_with(<<-MESSAGE)
|
89
131
|
expected collection contained: [4, 3]
|
90
132
|
actual collection contained: [2, 1]
|
91
133
|
the missing elements were: [4, 3]
|
@@ -94,9 +136,9 @@ MESSAGE
|
|
94
136
|
end
|
95
137
|
|
96
138
|
it "accurately reports extra elements when there are duplicates" do
|
97
|
-
|
98
|
-
[1,1,1,5].
|
99
|
-
}.
|
139
|
+
expect {
|
140
|
+
expect([1,1,1,5]).to match_array [1,5]
|
141
|
+
}.to fail_with(<<-MESSAGE)
|
100
142
|
expected collection contained: [1, 5]
|
101
143
|
actual collection contained: [1, 1, 1, 5]
|
102
144
|
the extra elements were: [1, 1]
|
@@ -104,50 +146,49 @@ MESSAGE
|
|
104
146
|
end
|
105
147
|
|
106
148
|
it "accurately reports missing elements when there are duplicates" do
|
107
|
-
|
108
|
-
[1,5].
|
109
|
-
}.
|
149
|
+
expect {
|
150
|
+
expect([1,5]).to match_array [1,1,5]
|
151
|
+
}.to fail_with(<<-MESSAGE)
|
110
152
|
expected collection contained: [1, 1, 5]
|
111
153
|
actual collection contained: [1, 5]
|
112
154
|
the missing elements were: [1]
|
113
155
|
MESSAGE
|
114
156
|
end
|
115
|
-
|
116
|
-
context "when the array defines a `=~` method" do
|
117
|
-
it 'delegates to that method rather than using the match_array matcher' do
|
118
|
-
array = []
|
119
|
-
def array.=~(other)
|
120
|
-
other == :foo
|
121
|
-
end
|
122
|
-
|
123
|
-
array.should =~ :foo
|
124
|
-
expect { array.should =~ :bar }.to fail_with(/expected: :bar/)
|
125
|
-
end
|
126
|
-
end
|
127
157
|
end
|
128
158
|
|
129
|
-
describe "
|
159
|
+
describe "expect(...).to_not match_array [:with, :multiple, :args]" do
|
130
160
|
it "is not supported" do
|
131
|
-
|
132
|
-
[1,2,3].
|
133
|
-
}.
|
161
|
+
expect {
|
162
|
+
expect([1,2,3]).not_to match_array [1,2,3]
|
163
|
+
}.to fail_with(/Matcher does not support should_not/)
|
134
164
|
end
|
135
165
|
end
|
136
166
|
|
137
167
|
describe "matching against things that aren't arrays" do
|
138
168
|
it "fails with nil and the expected error message is given" do
|
139
|
-
expect {
|
169
|
+
expect {
|
170
|
+
expect(nil).to match_array([1,2,3])
|
171
|
+
}.to fail_with(/expected an array/)
|
140
172
|
end
|
141
173
|
|
142
174
|
it "fails with a float and the expected error message is given" do
|
143
|
-
expect {
|
175
|
+
expect {
|
176
|
+
expect((3.7)).to match_array([1,2,3])
|
177
|
+
}.to fail_with(/expected an array/)
|
144
178
|
end
|
145
179
|
|
146
180
|
it "fails with a string and the expected error message is given" do
|
147
|
-
expect {
|
181
|
+
expect {
|
182
|
+
expect("I like turtles").to match_array([1,2,3])
|
183
|
+
}.to fail_with(/expected an array/)
|
148
184
|
end
|
149
185
|
|
150
|
-
|
151
|
-
|
186
|
+
context "when using the `should =~` syntax", :uses_should do
|
187
|
+
it 'fails with a clear message when given a hash' do
|
188
|
+
expect {
|
189
|
+
{}.should =~ {}
|
190
|
+
}.to fail_with(/expected an array/)
|
191
|
+
end
|
152
192
|
end
|
153
193
|
end
|
194
|
+
|
@@ -1,61 +1,61 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "
|
3
|
+
describe "expect(...).to match(expected)" do
|
4
4
|
it_behaves_like "an RSpec matcher", :valid_value => 'ab', :invalid_value => 'bc' do
|
5
5
|
let(:matcher) { match(/a/) }
|
6
6
|
end
|
7
7
|
|
8
8
|
it "passes when target (String) matches expected (Regexp)" do
|
9
|
-
"string".
|
9
|
+
expect("string").to match(/tri/)
|
10
10
|
end
|
11
11
|
|
12
12
|
it "passes when target (String) matches expected (String)" do
|
13
|
-
"string".
|
13
|
+
expect("string").to match("tri")
|
14
14
|
end
|
15
15
|
|
16
16
|
it "fails when target (String) does not match expected (Regexp)" do
|
17
|
-
|
18
|
-
"string".
|
19
|
-
}.
|
17
|
+
expect {
|
18
|
+
expect("string").to match(/rings/)
|
19
|
+
}.to fail
|
20
20
|
end
|
21
21
|
|
22
22
|
it "fails when target (String) does not match expected (String)" do
|
23
|
-
|
24
|
-
"string".
|
25
|
-
}.
|
23
|
+
expect {
|
24
|
+
expect("string").to match("rings")
|
25
|
+
}.to fail
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
it "provides message, expected and actual on failure" do
|
29
29
|
matcher = match(/rings/)
|
30
30
|
matcher.matches?("string")
|
31
|
-
matcher.failure_message_for_should.
|
31
|
+
expect(matcher.failure_message_for_should).to eq "expected \"string\" to match /rings/"
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
describe "
|
35
|
+
describe "expect(...).to_not match(expected)" do
|
36
36
|
it "passes when target (String) matches does not match (Regexp)" do
|
37
|
-
"string".
|
37
|
+
expect("string").not_to match(/rings/)
|
38
38
|
end
|
39
39
|
|
40
40
|
it "passes when target (String) matches does not match (String)" do
|
41
|
-
"string".
|
41
|
+
expect("string").not_to match("rings")
|
42
42
|
end
|
43
43
|
|
44
44
|
it "fails when target (String) matches expected (Regexp)" do
|
45
|
-
|
46
|
-
"string".
|
47
|
-
}.
|
45
|
+
expect {
|
46
|
+
expect("string").not_to match(/tri/)
|
47
|
+
}.to fail
|
48
48
|
end
|
49
49
|
|
50
50
|
it "fails when target (String) matches expected (String)" do
|
51
|
-
|
52
|
-
"string".
|
53
|
-
}.
|
51
|
+
expect {
|
52
|
+
expect("string").not_to match("tri")
|
53
|
+
}.to fail
|
54
54
|
end
|
55
55
|
|
56
56
|
it "provides message, expected and actual on failure" do
|
57
57
|
matcher = match(/tri/)
|
58
58
|
matcher.matches?("string")
|
59
|
-
matcher.failure_message_for_should_not.
|
59
|
+
expect(matcher.failure_message_for_should_not).to eq "expected \"string\" not to match /tri/"
|
60
60
|
end
|
61
61
|
end
|
@@ -33,8 +33,8 @@ module RSpec::Matchers::DSL
|
|
33
33
|
m1 = example_matcher(1)
|
34
34
|
m2 = example_matcher(2)
|
35
35
|
|
36
|
-
m1.matches?(1).
|
37
|
-
m2.matches?(2).
|
36
|
+
expect(m1.matches?(1)).to be_true
|
37
|
+
expect(m2.matches?(2)).to be_true
|
38
38
|
end
|
39
39
|
|
40
40
|
context "with an included module" do
|
@@ -50,19 +50,19 @@ module RSpec::Matchers::DSL
|
|
50
50
|
end
|
51
51
|
|
52
52
|
it "runs the module's included hook" do
|
53
|
-
matcher.
|
53
|
+
expect(matcher).to respond_to(:included_method)
|
54
54
|
end
|
55
55
|
|
56
56
|
it "does not run the module's extended hook" do
|
57
|
-
matcher.
|
57
|
+
expect(matcher).not_to respond_to(:extended_method)
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'allows multiple modules to be included at once' do
|
61
61
|
m = RSpec::Matchers::DSL::Matcher.new(:multiple_modules) do
|
62
62
|
include Enumerable, Comparable
|
63
63
|
end.for_expected
|
64
|
-
m.
|
65
|
-
m.
|
64
|
+
expect(m).to be_a(Enumerable)
|
65
|
+
expect(m).to be_a(Comparable)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -76,17 +76,17 @@ module RSpec::Matchers::DSL
|
|
76
76
|
end
|
77
77
|
|
78
78
|
it "provides a default description" do
|
79
|
-
@matcher.description.
|
79
|
+
expect(@matcher.description).to eq "be a multiple of 3"
|
80
80
|
end
|
81
81
|
|
82
82
|
it "provides a default failure message for #should" do
|
83
83
|
@matcher.matches?(8)
|
84
|
-
@matcher.failure_message_for_should.
|
84
|
+
expect(@matcher.failure_message_for_should).to eq "expected 8 to be a multiple of 3"
|
85
85
|
end
|
86
86
|
|
87
87
|
it "provides a default failure message for #should_not" do
|
88
88
|
@matcher.matches?(9)
|
89
|
-
@matcher.failure_message_for_should_not.
|
89
|
+
expect(@matcher.failure_message_for_should_not).to eq "expected 9 not to be a multiple of 3"
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
@@ -104,18 +104,18 @@ module RSpec::Matchers::DSL
|
|
104
104
|
end
|
105
105
|
|
106
106
|
it "invokes the match_for_should block for #matches?" do
|
107
|
-
matcher.matches?(77).
|
108
|
-
matcher.matches?(18).
|
107
|
+
expect(matcher.matches?(77)).to be_true
|
108
|
+
expect(matcher.matches?(18)).to be_false
|
109
109
|
end
|
110
110
|
|
111
111
|
it "invokes the match_for_should_not block for #does_not_match?" do
|
112
|
-
matcher.does_not_match?(77).
|
113
|
-
matcher.does_not_match?(18).
|
112
|
+
expect(matcher.does_not_match?(77)).to be_false
|
113
|
+
expect(matcher.does_not_match?(18)).to be_true
|
114
114
|
end
|
115
115
|
|
116
116
|
it "provides a default failure message for #should_not" do
|
117
117
|
matcher.does_not_match?(77)
|
118
|
-
matcher.failure_message_for_should_not.
|
118
|
+
expect(matcher.failure_message_for_should_not).to eq "expected 77 not to to be composed of 7 and 11"
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
@@ -124,22 +124,22 @@ module RSpec::Matchers::DSL
|
|
124
124
|
define_method(:sum) { a + b }
|
125
125
|
end.for_expected(3,4)
|
126
126
|
|
127
|
-
matcher.sum.
|
127
|
+
expect(matcher.sum).to eq 7
|
128
128
|
end
|
129
129
|
|
130
130
|
it "is not diffable by default" do
|
131
131
|
matcher = RSpec::Matchers::DSL::Matcher.new(:name) {}
|
132
|
-
matcher.
|
132
|
+
expect(matcher).not_to be_diffable
|
133
133
|
end
|
134
134
|
|
135
135
|
it "is diffable when told to be" do
|
136
136
|
matcher = RSpec::Matchers::DSL::Matcher.new(:name) { diffable }.for_expected
|
137
|
-
matcher.
|
137
|
+
expect(matcher).to be_diffable
|
138
138
|
end
|
139
139
|
|
140
140
|
it "provides expected" do
|
141
141
|
matcher = RSpec::Matchers::DSL::Matcher.new(:name) {}.for_expected('expected string')
|
142
|
-
matcher.expected.
|
142
|
+
expect(matcher.expected).to eq ['expected string']
|
143
143
|
end
|
144
144
|
|
145
145
|
it "provides actual" do
|
@@ -149,26 +149,26 @@ module RSpec::Matchers::DSL
|
|
149
149
|
|
150
150
|
matcher.matches?('actual string')
|
151
151
|
|
152
|
-
matcher.actual.
|
152
|
+
expect(matcher.actual).to eq 'actual string'
|
153
153
|
end
|
154
154
|
|
155
155
|
context "wrapping another expectation (should == ...)" do
|
156
156
|
it "returns true if the wrapped expectation passes" do
|
157
157
|
matcher = RSpec::Matchers::DSL::Matcher.new(:name) do |expected|
|
158
158
|
match do |actual|
|
159
|
-
actual.
|
159
|
+
expect(actual).to eq expected
|
160
160
|
end
|
161
161
|
end.for_expected('value')
|
162
|
-
matcher.matches?('value').
|
162
|
+
expect(matcher.matches?('value')).to be_true
|
163
163
|
end
|
164
164
|
|
165
165
|
it "returns false if the wrapped expectation fails" do
|
166
166
|
matcher = RSpec::Matchers::DSL::Matcher.new(:name) do |expected|
|
167
167
|
match do |actual|
|
168
|
-
actual.
|
168
|
+
expect(actual).to eq expected
|
169
169
|
end
|
170
170
|
end.for_expected('value')
|
171
|
-
matcher.matches?('other value').
|
171
|
+
expect(matcher.matches?('other value')).to be_false
|
172
172
|
end
|
173
173
|
end
|
174
174
|
|
@@ -191,25 +191,25 @@ module RSpec::Matchers::DSL
|
|
191
191
|
end
|
192
192
|
|
193
193
|
it "does not hide result of match block when true" do
|
194
|
-
@matcher.matches?(true).
|
194
|
+
expect(@matcher.matches?(true)).to be_true
|
195
195
|
end
|
196
196
|
|
197
197
|
it "does not hide result of match block when false" do
|
198
|
-
@matcher.matches?(false).
|
198
|
+
expect(@matcher.matches?(false)).to be_false
|
199
199
|
end
|
200
200
|
|
201
201
|
it "overrides the description" do
|
202
|
-
@matcher.description.
|
202
|
+
expect(@matcher.description).to eq "be the boolean true"
|
203
203
|
end
|
204
204
|
|
205
205
|
it "overrides the failure message for #should" do
|
206
206
|
@matcher.matches?(false)
|
207
|
-
@matcher.failure_message_for_should.
|
207
|
+
expect(@matcher.failure_message_for_should).to eq "expected false to be the boolean true"
|
208
208
|
end
|
209
209
|
|
210
210
|
it "overrides the failure message for #should_not" do
|
211
211
|
@matcher.matches?(true)
|
212
|
-
@matcher.failure_message_for_should_not.
|
212
|
+
expect(@matcher.failure_message_for_should_not).to eq "expected true not to be the boolean true"
|
213
213
|
end
|
214
214
|
end
|
215
215
|
|
@@ -220,7 +220,7 @@ module RSpec::Matchers::DSL
|
|
220
220
|
actual == 5
|
221
221
|
end
|
222
222
|
end.for_expected
|
223
|
-
matcher.matches?(5).
|
223
|
+
expect(matcher.matches?(5)).to be_true
|
224
224
|
end
|
225
225
|
|
226
226
|
it "exposes arg submitted through #new to matcher block" do
|
@@ -229,7 +229,7 @@ module RSpec::Matchers::DSL
|
|
229
229
|
actual > expected
|
230
230
|
end
|
231
231
|
end.for_expected(4)
|
232
|
-
matcher.matches?(5).
|
232
|
+
expect(matcher.matches?(5)).to be_true
|
233
233
|
end
|
234
234
|
end
|
235
235
|
|
@@ -243,11 +243,11 @@ module RSpec::Matchers::DSL
|
|
243
243
|
end
|
244
244
|
|
245
245
|
it "matches" do
|
246
|
-
@matcher.matches?(5).
|
246
|
+
expect(@matcher.matches?(5)).to be_true
|
247
247
|
end
|
248
248
|
|
249
249
|
it "describes" do
|
250
|
-
@matcher.description.
|
250
|
+
expect(@matcher.description).to eq "matcher name"
|
251
251
|
end
|
252
252
|
end
|
253
253
|
|
@@ -261,11 +261,11 @@ module RSpec::Matchers::DSL
|
|
261
261
|
end
|
262
262
|
|
263
263
|
it "matches" do
|
264
|
-
@matcher.matches?(5).
|
264
|
+
expect(@matcher.matches?(5)).to be_true
|
265
265
|
end
|
266
266
|
|
267
267
|
it "describes" do
|
268
|
-
@matcher.description.
|
268
|
+
expect(@matcher.description).to eq "matcher name 1"
|
269
269
|
end
|
270
270
|
end
|
271
271
|
|
@@ -279,11 +279,11 @@ module RSpec::Matchers::DSL
|
|
279
279
|
end
|
280
280
|
|
281
281
|
it "matches" do
|
282
|
-
@matcher.matches?(10).
|
282
|
+
expect(@matcher.matches?(10)).to be_true
|
283
283
|
end
|
284
284
|
|
285
285
|
it "describes" do
|
286
|
-
@matcher.description.
|
286
|
+
expect(@matcher.description).to eq "matcher name 1, 2, 3, and 4"
|
287
287
|
end
|
288
288
|
end
|
289
289
|
|
@@ -298,7 +298,7 @@ module RSpec::Matchers::DSL
|
|
298
298
|
end
|
299
299
|
end.for_expected([1,2,3])
|
300
300
|
|
301
|
-
matcher.matches?([2,3,1]).
|
301
|
+
expect(matcher.matches?([2,3,1])).to be_true
|
302
302
|
end
|
303
303
|
|
304
304
|
it "supports fluent interface" do
|
@@ -308,7 +308,7 @@ module RSpec::Matchers::DSL
|
|
308
308
|
end
|
309
309
|
end.for_expected
|
310
310
|
|
311
|
-
matcher.second_word.
|
311
|
+
expect(matcher.second_word).to eq matcher
|
312
312
|
end
|
313
313
|
|
314
314
|
it "treats method missing normally for undeclared methods" do
|
@@ -320,11 +320,49 @@ module RSpec::Matchers::DSL
|
|
320
320
|
matcher = RSpec::Matchers::DSL::Matcher.new(:ignore) do |expected|
|
321
321
|
match do |actual|
|
322
322
|
extend RSpec::Matchers
|
323
|
-
actual.
|
323
|
+
expect(actual).to eql(5 + expected)
|
324
324
|
end
|
325
325
|
end.for_expected(3)
|
326
326
|
|
327
|
-
matcher.matches?(8).
|
327
|
+
expect(matcher.matches?(8)).to be_true
|
328
|
+
end
|
329
|
+
|
330
|
+
context 'when multiple instances of the same matcher are used in the same example' do
|
331
|
+
RSpec::Matchers.define(:be_like_a) do |expected|
|
332
|
+
match { |actual| actual == expected }
|
333
|
+
description { "be like a #{expected}" }
|
334
|
+
failure_message_for_should { "expected to be like a #{expected}" }
|
335
|
+
failure_message_for_should_not { "expected not to be like a #{expected}" }
|
336
|
+
end
|
337
|
+
|
338
|
+
# Note: these bugs were only exposed when creating both instances
|
339
|
+
# first, then checking their descriptions/failure messages.
|
340
|
+
#
|
341
|
+
# That's why we eager-instantiate them here.
|
342
|
+
let!(:moose) { be_like_a("moose") }
|
343
|
+
let!(:horse) { be_like_a("horse") }
|
344
|
+
|
345
|
+
it 'allows them to use the expected value in the description' do
|
346
|
+
expect(horse.description).to eq("be like a horse")
|
347
|
+
expect(moose.description).to eq("be like a moose")
|
348
|
+
end
|
349
|
+
|
350
|
+
it 'allows them to use the expected value in the positive failure message' do
|
351
|
+
expect(moose.failure_message_for_should).to eq("expected to be like a moose")
|
352
|
+
expect(horse.failure_message_for_should).to eq("expected to be like a horse")
|
353
|
+
end
|
354
|
+
|
355
|
+
it 'allows them to use the expected value in the negative failure message' do
|
356
|
+
expect(moose.failure_message_for_should_not).to eq("expected not to be like a moose")
|
357
|
+
expect(horse.failure_message_for_should_not).to eq("expected not to be like a horse")
|
358
|
+
end
|
359
|
+
|
360
|
+
it 'allows them to match separately' do
|
361
|
+
expect("moose").to moose
|
362
|
+
expect("horse").to horse
|
363
|
+
expect("horse").not_to moose
|
364
|
+
expect("moose").not_to horse
|
365
|
+
end
|
328
366
|
end
|
329
367
|
|
330
368
|
describe "#match_unless_raises" do
|
@@ -348,19 +386,18 @@ module RSpec::Matchers::DSL
|
|
348
386
|
|
349
387
|
context "with passing assertion" do
|
350
388
|
it "passes" do
|
351
|
-
matcher.matches?(4).
|
389
|
+
expect(matcher.matches?(4)).to be_true
|
352
390
|
end
|
353
391
|
end
|
354
392
|
|
355
393
|
context "with failing assertion" do
|
356
394
|
it "fails" do
|
357
|
-
matcher.matches?(5).
|
395
|
+
expect(matcher.matches?(5)).to be_false
|
358
396
|
end
|
359
397
|
|
360
398
|
it "provides the raised exception" do
|
361
399
|
matcher.matches?(5)
|
362
|
-
matcher.rescued_exception.message.
|
363
|
-
should eq("5 does not equal 4")
|
400
|
+
expect(matcher.rescued_exception.message).to eq("5 does not equal 4")
|
364
401
|
end
|
365
402
|
end
|
366
403
|
end
|
@@ -391,8 +428,8 @@ module RSpec::Matchers::DSL
|
|
391
428
|
match { |actual| actual == @expected_value }
|
392
429
|
end.for_expected
|
393
430
|
|
394
|
-
matcher.expecting('value').matches?('value').
|
395
|
-
matcher.expecting('value').matches?('other value').
|
431
|
+
expect(matcher.expecting('value').matches?('value')).to be_true
|
432
|
+
expect(matcher.expecting('value').matches?('other value')).to be_false
|
396
433
|
end
|
397
434
|
|
398
435
|
it "prevents name collisions on chainable methods from different matchers" do
|
@@ -414,7 +451,7 @@ module RSpec::Matchers::DSL
|
|
414
451
|
a_method_in_the_example == "method defined in the example"
|
415
452
|
end
|
416
453
|
end
|
417
|
-
example.
|
454
|
+
expect(example).to __access_running_example
|
418
455
|
end
|
419
456
|
|
420
457
|
it "raises NoMethodError for methods not in the running_example" do
|
@@ -425,7 +462,7 @@ module RSpec::Matchers::DSL
|
|
425
462
|
end
|
426
463
|
|
427
464
|
expect do
|
428
|
-
example.
|
465
|
+
expect(example).to __raise_no_method_error
|
429
466
|
end.to raise_error(/RSpec::Matchers::DSL::Matcher/)
|
430
467
|
end
|
431
468
|
end
|