rspec-expectations 3.0.0.beta1 → 3.0.0.beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +2 -2
- data/.yardopts +1 -0
- data/Changelog.md +138 -0
- data/README.md +75 -8
- data/features/README.md +2 -2
- data/features/built_in_matchers/README.md +12 -9
- data/features/built_in_matchers/comparisons.feature +2 -2
- data/features/built_in_matchers/contain_exactly.feature +46 -0
- data/features/built_in_matchers/expect_change.feature +2 -2
- data/features/built_in_matchers/include.feature +0 -48
- data/features/built_in_matchers/output.feature +70 -0
- data/features/composing_matchers.feature +250 -0
- data/features/compound_expectations.feature +45 -0
- data/features/custom_matchers/access_running_example.feature +1 -1
- data/features/custom_matchers/define_matcher.feature +6 -6
- data/features/custom_matchers/define_matcher_outside_rspec.feature +4 -8
- data/features/test_frameworks/{test_unit.feature → minitest.feature} +11 -11
- data/lib/rspec/expectations.rb +31 -42
- data/lib/rspec/expectations/diff_presenter.rb +141 -0
- data/lib/rspec/expectations/differ.rb +22 -132
- data/lib/rspec/expectations/encoded_string.rb +56 -0
- data/lib/rspec/expectations/expectation_target.rb +0 -30
- data/lib/rspec/expectations/fail_with.rb +2 -2
- data/lib/rspec/expectations/handler.rb +128 -31
- data/lib/rspec/expectations/minitest_integration.rb +16 -0
- data/lib/rspec/expectations/syntax.rb +4 -58
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/matchers.rb +298 -60
- data/lib/rspec/matchers/aliased_matcher.rb +35 -0
- data/lib/rspec/matchers/built_in.rb +37 -33
- data/lib/rspec/matchers/built_in/base_matcher.rb +25 -15
- data/lib/rspec/matchers/built_in/be.rb +23 -31
- data/lib/rspec/matchers/built_in/be_between.rb +55 -0
- data/lib/rspec/matchers/built_in/be_within.rb +15 -11
- data/lib/rspec/matchers/built_in/change.rb +198 -81
- data/lib/rspec/matchers/built_in/compound.rb +106 -0
- data/lib/rspec/matchers/built_in/contain_exactly.rb +245 -0
- data/lib/rspec/matchers/built_in/eq.rb +43 -4
- data/lib/rspec/matchers/built_in/eql.rb +2 -2
- data/lib/rspec/matchers/built_in/equal.rb +35 -18
- data/lib/rspec/matchers/built_in/has.rb +16 -15
- data/lib/rspec/matchers/built_in/include.rb +45 -23
- data/lib/rspec/matchers/built_in/match.rb +6 -3
- data/lib/rspec/matchers/built_in/operators.rb +103 -0
- data/lib/rspec/matchers/built_in/output.rb +108 -0
- data/lib/rspec/matchers/built_in/raise_error.rb +9 -15
- data/lib/rspec/matchers/built_in/respond_to.rb +5 -4
- data/lib/rspec/matchers/built_in/satisfy.rb +4 -3
- data/lib/rspec/matchers/built_in/start_and_end_with.rb +37 -16
- data/lib/rspec/matchers/built_in/throw_symbol.rb +6 -5
- data/lib/rspec/matchers/built_in/yield.rb +31 -29
- data/lib/rspec/matchers/composable.rb +138 -0
- data/lib/rspec/matchers/dsl.rb +330 -0
- data/lib/rspec/matchers/generated_descriptions.rb +6 -6
- data/lib/rspec/matchers/matcher_delegator.rb +33 -0
- data/lib/rspec/matchers/pretty.rb +13 -2
- data/spec/rspec/expectations/{differ_spec.rb → diff_presenter_spec.rb} +56 -36
- data/spec/rspec/expectations/encoded_string_spec.rb +74 -0
- data/spec/rspec/expectations/extensions/kernel_spec.rb +11 -11
- data/spec/rspec/expectations/fail_with_spec.rb +8 -8
- data/spec/rspec/expectations/handler_spec.rb +27 -49
- data/spec/rspec/expectations/minitest_integration_spec.rb +27 -0
- data/spec/rspec/expectations/syntax_spec.rb +17 -67
- data/spec/rspec/expectations_spec.rb +7 -52
- data/spec/rspec/matchers/aliased_matcher_spec.rb +48 -0
- data/spec/rspec/matchers/aliases_spec.rb +449 -0
- data/spec/rspec/matchers/{base_matcher_spec.rb → built_in/base_matcher_spec.rb} +24 -3
- data/spec/rspec/matchers/built_in/be_between_spec.rb +159 -0
- data/spec/rspec/matchers/{be_instance_of_spec.rb → built_in/be_instance_of_spec.rb} +0 -0
- data/spec/rspec/matchers/{be_kind_of_spec.rb → built_in/be_kind_of_spec.rb} +0 -0
- data/spec/rspec/matchers/{be_spec.rb → built_in/be_spec.rb} +76 -32
- data/spec/rspec/matchers/{be_within_spec.rb → built_in/be_within_spec.rb} +6 -2
- data/spec/rspec/matchers/{change_spec.rb → built_in/change_spec.rb} +310 -69
- data/spec/rspec/matchers/built_in/compound_spec.rb +292 -0
- data/spec/rspec/matchers/built_in/contain_exactly_spec.rb +441 -0
- data/spec/rspec/matchers/{cover_spec.rb → built_in/cover_spec.rb} +0 -0
- data/spec/rspec/matchers/built_in/eq_spec.rb +156 -0
- data/spec/rspec/matchers/{eql_spec.rb → built_in/eql_spec.rb} +2 -2
- data/spec/rspec/matchers/built_in/equal_spec.rb +106 -0
- data/spec/rspec/matchers/{exist_spec.rb → built_in/exist_spec.rb} +1 -1
- data/spec/rspec/matchers/{has_spec.rb → built_in/has_spec.rb} +39 -0
- data/spec/rspec/matchers/{include_spec.rb → built_in/include_spec.rb} +118 -109
- data/spec/rspec/matchers/{match_spec.rb → built_in/match_spec.rb} +30 -2
- data/spec/rspec/matchers/{operator_matcher_spec.rb → built_in/operators_spec.rb} +26 -26
- data/spec/rspec/matchers/built_in/output_spec.rb +165 -0
- data/spec/rspec/matchers/{raise_error_spec.rb → built_in/raise_error_spec.rb} +81 -11
- data/spec/rspec/matchers/{respond_to_spec.rb → built_in/respond_to_spec.rb} +0 -0
- data/spec/rspec/matchers/{satisfy_spec.rb → built_in/satisfy_spec.rb} +0 -0
- data/spec/rspec/matchers/{start_with_end_with_spec.rb → built_in/start_and_end_with_spec.rb} +82 -15
- data/spec/rspec/matchers/{throw_symbol_spec.rb → built_in/throw_symbol_spec.rb} +29 -10
- data/spec/rspec/matchers/{yield_spec.rb → built_in/yield_spec.rb} +90 -0
- data/spec/rspec/matchers/configuration_spec.rb +7 -39
- data/spec/rspec/matchers/description_generation_spec.rb +22 -6
- data/spec/rspec/matchers/dsl_spec.rb +838 -0
- data/spec/rspec/matchers/legacy_spec.rb +101 -0
- data/spec/rspec/matchers_spec.rb +74 -0
- data/spec/spec_helper.rb +35 -21
- data/spec/support/shared_examples.rb +26 -4
- metadata +172 -116
- metadata.gz.sig +3 -4
- checksums.yaml +0 -15
- checksums.yaml.gz.sig +0 -0
- data/features/built_in_matchers/match_array.feature +0 -37
- data/lib/rspec/expectations/errors.rb +0 -9
- data/lib/rspec/expectations/extensions.rb +0 -1
- data/lib/rspec/expectations/extensions/object.rb +0 -29
- data/lib/rspec/matchers/built_in/match_array.rb +0 -51
- data/lib/rspec/matchers/compatibility.rb +0 -14
- data/lib/rspec/matchers/matcher.rb +0 -301
- data/lib/rspec/matchers/method_missing.rb +0 -12
- data/lib/rspec/matchers/operator_matcher.rb +0 -99
- data/lib/rspec/matchers/test_unit_integration.rb +0 -11
- data/spec/rspec/matchers/eq_spec.rb +0 -60
- data/spec/rspec/matchers/equal_spec.rb +0 -78
- data/spec/rspec/matchers/include_matcher_integration_spec.rb +0 -30
- data/spec/rspec/matchers/match_array_spec.rb +0 -194
- data/spec/rspec/matchers/matcher_spec.rb +0 -706
- data/spec/rspec/matchers/matchers_spec.rb +0 -36
- data/spec/rspec/matchers/method_missing_spec.rb +0 -28
- data/spec/support/classes.rb +0 -56
- data/spec/support/in_sub_process.rb +0 -37
- data/spec/support/ruby_version.rb +0 -10
File without changes
|
File without changes
|
data/spec/rspec/matchers/{start_with_end_with_spec.rb → built_in/start_and_end_with_spec.rb}
RENAMED
@@ -35,23 +35,47 @@ describe "expect(...).to start_with" do
|
|
35
35
|
it "fails if it the first elements of the array do not match" do
|
36
36
|
expect {
|
37
37
|
expect([0, 1, 2]).to start_with 1, 2
|
38
|
-
}.to fail_with("expected [0, 1, 2] to start with
|
38
|
+
}.to fail_with("expected [0, 1, 2] to start with 1 and 2")
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
context "with an object that does not respond to :[]" do
|
43
|
-
it "
|
43
|
+
it "fails with a useful message" do
|
44
|
+
actual = Object.new
|
44
45
|
expect {
|
45
|
-
expect(
|
46
|
-
}.to
|
46
|
+
expect(actual).to start_with 0
|
47
|
+
}.to fail_with("expected #{actual.inspect} to start with 0, but it cannot be indexed using #[]")
|
47
48
|
end
|
48
49
|
end
|
49
50
|
|
50
51
|
context "with a hash" do
|
51
|
-
it "
|
52
|
+
it "fails with a useful error if trying to match more than one element" do
|
53
|
+
actual = { :a => 'b', :b => 'b', :c => 'c' }
|
54
|
+
expected = { :a => 'b', :b => 'b' }
|
52
55
|
expect{
|
53
|
-
expect(
|
54
|
-
}.to
|
56
|
+
expect(actual).to start_with(expected)
|
57
|
+
}.to fail_with("expected #{actual.inspect} to start with #{expected.inspect}, but it does not have ordered elements")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "composing with other matchers" do
|
62
|
+
it 'passes if the start of an array matches two given matchers' do
|
63
|
+
expect([1.01, "food", 3]).to start_with(a_value_within(0.2).of(1), a_string_matching(/foo/))
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'passes if the start of an array matches one given matcher' do
|
67
|
+
expect([1.01, "food", 3]).to start_with(a_value_within(0.2).of(1))
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'provides a description' do
|
71
|
+
description = start_with(a_value_within(0.1).of(1), a_string_matching(/abc/)).description
|
72
|
+
expect(description).to eq("start with a value within 0.1 of 1 and a string matching /abc/")
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'fails with a clear error message when the matchers do not match' do
|
76
|
+
expect {
|
77
|
+
expect([2.01, "food", 3]).to start_with(a_value_within(0.2).of(1), a_string_matching(/foo/))
|
78
|
+
}.to fail_with('expected [2.01, "food", 3] to start with a value within 0.2 of 1 and a string matching /foo/')
|
55
79
|
end
|
56
80
|
end
|
57
81
|
end
|
@@ -87,9 +111,19 @@ describe "expect(...).not_to start_with" do
|
|
87
111
|
it "fails if it the first elements of the array match" do
|
88
112
|
expect {
|
89
113
|
expect([0, 1, 2]).not_to start_with 0, 1
|
90
|
-
}.to fail_with("expected [0, 1, 2] not to start with
|
114
|
+
}.to fail_with("expected [0, 1, 2] not to start with 0 and 1")
|
91
115
|
end
|
92
116
|
end
|
117
|
+
|
118
|
+
it 'can pass when composed with another matcher' do
|
119
|
+
expect(["a"]).not_to start_with(a_string_matching(/bar/))
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'can fail when composed with another matcher' do
|
123
|
+
expect {
|
124
|
+
expect(["a"]).not_to start_with(a_string_matching(/a/))
|
125
|
+
}.to fail_with('expected ["a"] not to start with a string matching /a/')
|
126
|
+
end
|
93
127
|
end
|
94
128
|
|
95
129
|
describe "expect(...).to end_with" do
|
@@ -127,26 +161,49 @@ describe "expect(...).to end_with" do
|
|
127
161
|
it "fails if it the last elements of the array do not match" do
|
128
162
|
expect {
|
129
163
|
expect([0, 1, 2]).to end_with [0, 1]
|
130
|
-
}.to fail_with("expected [0, 1, 2] to end with
|
164
|
+
}.to fail_with("expected [0, 1, 2] to end with 0 and 1")
|
131
165
|
end
|
132
166
|
end
|
133
167
|
|
134
168
|
context "with an object that does not respond to :[]" do
|
135
|
-
it "
|
169
|
+
it "fails with a useful message" do
|
170
|
+
actual = Object.new
|
136
171
|
expect {
|
137
|
-
expect(
|
138
|
-
}.to
|
172
|
+
expect(actual).to end_with 0
|
173
|
+
}.to fail_with("expected #{actual.inspect} to end with 0, but it cannot be indexed using #[]")
|
139
174
|
end
|
140
175
|
end
|
141
176
|
|
142
177
|
context "with a hash" do
|
143
178
|
it "raises an ArgumentError if trying to match more than one element" do
|
179
|
+
actual = { :a => 'b', :b => 'b', :c => 'c' }
|
180
|
+
expected = { :a => 'b', :b => 'b' }
|
144
181
|
expect{
|
145
|
-
expect(
|
146
|
-
}.to
|
182
|
+
expect(actual).to end_with(expected)
|
183
|
+
}.to fail_with("expected #{actual.inspect} to end with #{expected.inspect}, but it does not have ordered elements")
|
147
184
|
end
|
148
185
|
end
|
149
186
|
|
187
|
+
describe "composing with other matchers" do
|
188
|
+
it 'passes if the end of an array matches two given matchers' do
|
189
|
+
expect([3, "food", 1.1]).to end_with(a_string_matching(/foo/), a_value_within(0.2).of(1))
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'passes if the end of an array matches one given matcher' do
|
193
|
+
expect([3, "food", 1.1]).to end_with(a_value_within(0.2).of(1))
|
194
|
+
end
|
195
|
+
|
196
|
+
it 'provides a description' do
|
197
|
+
description = end_with(a_value_within(0.1).of(1), a_string_matching(/abc/)).description
|
198
|
+
expect(description).to eq("end with a value within 0.1 of 1 and a string matching /abc/")
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'fails with a clear error message when the matchers do not match' do
|
202
|
+
expect {
|
203
|
+
expect([2.01, 3, "food"]).to end_with(a_value_within(0.2).of(1), a_string_matching(/foo/))
|
204
|
+
}.to fail_with('expected [2.01, 3, "food"] to end with a value within 0.2 of 1 and a string matching /foo/')
|
205
|
+
end
|
206
|
+
end
|
150
207
|
end
|
151
208
|
|
152
209
|
describe "expect(...).not_to end_with" do
|
@@ -180,7 +237,17 @@ describe "expect(...).not_to end_with" do
|
|
180
237
|
it "fails if it the last elements of the array match" do
|
181
238
|
expect {
|
182
239
|
expect([0, 1, 2]).not_to end_with [1, 2]
|
183
|
-
}.to fail_with("expected [0, 1, 2] not to end with
|
240
|
+
}.to fail_with("expected [0, 1, 2] not to end with 1 and 2")
|
184
241
|
end
|
185
242
|
end
|
243
|
+
|
244
|
+
it 'can pass when composed with another matcher' do
|
245
|
+
expect(["a"]).not_to end_with(a_string_matching(/bar/))
|
246
|
+
end
|
247
|
+
|
248
|
+
it 'can fail when composed with another matcher' do
|
249
|
+
expect {
|
250
|
+
expect(["a"]).not_to end_with(a_string_matching(/a/))
|
251
|
+
}.to fail_with('expected ["a"] not to end with a string matching /a/')
|
252
|
+
end
|
186
253
|
end
|
@@ -21,11 +21,11 @@ module RSpec::Matchers::BuiltIn
|
|
21
21
|
end
|
22
22
|
it "provides a failure message" do
|
23
23
|
@matcher.matches?(lambda{})
|
24
|
-
expect(@matcher.
|
24
|
+
expect(@matcher.failure_message).to eq "expected a Symbol to be thrown, got nothing"
|
25
25
|
end
|
26
26
|
it "provides a negative failure message" do
|
27
27
|
@matcher.matches?(lambda{ throw :sym})
|
28
|
-
expect(@matcher.
|
28
|
+
expect(@matcher.failure_message_when_negated).to eq "expected no Symbol to be thrown, got :sym"
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -46,15 +46,15 @@ module RSpec::Matchers::BuiltIn
|
|
46
46
|
end
|
47
47
|
it "provides a failure message when no Symbol is thrown" do
|
48
48
|
@matcher.matches?(lambda{})
|
49
|
-
expect(@matcher.
|
49
|
+
expect(@matcher.failure_message).to eq "expected :sym to be thrown, got nothing"
|
50
50
|
end
|
51
51
|
it "provides a failure message when wrong Symbol is thrown" do
|
52
52
|
@matcher.matches?(lambda{ throw :other_sym })
|
53
|
-
expect(@matcher.
|
53
|
+
expect(@matcher.failure_message).to eq "expected :sym to be thrown, got :other_sym"
|
54
54
|
end
|
55
55
|
it "provides a negative failure message" do
|
56
56
|
@matcher.matches?(lambda{ throw :sym })
|
57
|
-
expect(@matcher.
|
57
|
+
expect(@matcher.failure_message_when_negated).to eq "expected :sym not to be thrown, got :sym"
|
58
58
|
end
|
59
59
|
it "only matches NameErrors raised by uncaught throws" do
|
60
60
|
expect {
|
@@ -83,23 +83,23 @@ module RSpec::Matchers::BuiltIn
|
|
83
83
|
end
|
84
84
|
it "provides a failure message when no Symbol is thrown" do
|
85
85
|
@matcher.matches?(lambda{})
|
86
|
-
expect(@matcher.
|
86
|
+
expect(@matcher.failure_message).to eq %q[expected :sym with "a" to be thrown, got nothing]
|
87
87
|
end
|
88
88
|
it "provides a failure message when wrong Symbol is thrown" do
|
89
89
|
@matcher.matches?(lambda{ throw :other_sym })
|
90
|
-
expect(@matcher.
|
90
|
+
expect(@matcher.failure_message).to eq %q[expected :sym with "a" to be thrown, got :other_sym]
|
91
91
|
end
|
92
92
|
it "provides a failure message when wrong arg is thrown" do
|
93
93
|
@matcher.matches?(lambda{ throw :sym, "b" })
|
94
|
-
expect(@matcher.
|
94
|
+
expect(@matcher.failure_message).to eq %q[expected :sym with "a" to be thrown, got :sym with "b"]
|
95
95
|
end
|
96
96
|
it "provides a failure message when no arg is thrown" do
|
97
97
|
@matcher.matches?(lambda{ throw :sym })
|
98
|
-
expect(@matcher.
|
98
|
+
expect(@matcher.failure_message).to eq %q[expected :sym with "a" to be thrown, got :sym with no argument]
|
99
99
|
end
|
100
100
|
it "provides a negative failure message" do
|
101
101
|
@matcher.matches?(lambda{ throw :sym })
|
102
|
-
expect(@matcher.
|
102
|
+
expect(@matcher.failure_message_when_negated).to eq %q[expected :sym with "a" not to be thrown, got :sym with no argument]
|
103
103
|
end
|
104
104
|
it "only matches NameErrors raised by uncaught throws" do
|
105
105
|
expect {
|
@@ -112,5 +112,24 @@ module RSpec::Matchers::BuiltIn
|
|
112
112
|
}.to raise_error(/Boom/)
|
113
113
|
end
|
114
114
|
end
|
115
|
+
|
116
|
+
describe "composing with other matchers" do
|
117
|
+
it 'passes when the matcher matches the thrown arg' do
|
118
|
+
expect {
|
119
|
+
throw :foo, "bar"
|
120
|
+
}.to throw_symbol(:foo, a_string_matching(/bar/))
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'fails when the matcher does not match the thrown arg' do
|
124
|
+
expect {
|
125
|
+
expect { throw :foo, "bar" }.to throw_symbol(:foo, a_string_matching(/foo/))
|
126
|
+
}.to fail_with('expected :foo with a string matching /foo/ to be thrown, got :foo with "bar"')
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'provides a description' do
|
130
|
+
description = throw_symbol(:foo, a_string_matching(/bar/)).description
|
131
|
+
expect(description).to eq("throw :foo with a string matching /bar/")
|
132
|
+
end
|
133
|
+
end
|
115
134
|
end
|
116
135
|
end
|
@@ -362,6 +362,31 @@ describe "yield_with_args matcher" do
|
|
362
362
|
end
|
363
363
|
end
|
364
364
|
|
365
|
+
describe "expect {...}.to yield_with_args(matcher, matcher)" do
|
366
|
+
it 'passes when the matchers match the args' do
|
367
|
+
expect { |b|
|
368
|
+
_yield_with_args(1.1, "food", &b)
|
369
|
+
}.to yield_with_args(a_value_within(0.2).of(1), a_string_matching(/foo/))
|
370
|
+
end
|
371
|
+
|
372
|
+
it 'provides a description' do
|
373
|
+
description = yield_with_args(a_value_within(0.2).of(1), a_string_matching(/foo/)).description
|
374
|
+
expect(description).to eq("yield with args(a value within 0.2 of 1, a string matching /foo/)")
|
375
|
+
end
|
376
|
+
|
377
|
+
it 'fails with a useful error message when the matchers do not match the args' do
|
378
|
+
expect {
|
379
|
+
expect { |b|
|
380
|
+
_yield_with_args(2.1, "food", &b)
|
381
|
+
}.to yield_with_args(a_value_within(0.2).of(1), a_string_matching(/foo/))
|
382
|
+
}.to fail_with(dedent <<-EOS)
|
383
|
+
|expected given block to yield with arguments, but yielded with unexpected arguments
|
384
|
+
|expected: [(a value within 0.2 of 1), (a string matching /foo/)]
|
385
|
+
| got: [2.1, "food"]
|
386
|
+
EOS
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
365
390
|
describe "expect {...}.not_to yield_with_args(3, 17)" do
|
366
391
|
it 'passes if the block yields with different arguments' do
|
367
392
|
expect { |b| _yield_with_args("a", "b", &b) }.not_to yield_with_args("a", "c")
|
@@ -374,6 +399,26 @@ describe "yield_with_args matcher" do
|
|
374
399
|
end
|
375
400
|
end
|
376
401
|
|
402
|
+
describe "expect {...}.not_to yield_with_args(matcher, matcher)" do
|
403
|
+
it 'passes when the matchers do not match the args' do
|
404
|
+
expect { |b|
|
405
|
+
_yield_with_args(2.1, "food", &b)
|
406
|
+
}.not_to yield_with_args(a_value_within(0.2).of(1), a_string_matching(/foo/))
|
407
|
+
end
|
408
|
+
|
409
|
+
it 'fails with a useful error message when the matchers do not match the args' do
|
410
|
+
expect {
|
411
|
+
expect { |b|
|
412
|
+
_yield_with_args(1.1, "food", &b)
|
413
|
+
}.not_to yield_with_args(a_value_within(0.2).of(1), a_string_matching(/foo/))
|
414
|
+
}.to fail_with(dedent <<-EOS)
|
415
|
+
|expected given block not to yield with arguments, but yielded with expected arguments
|
416
|
+
|expected not: [(a value within 0.2 of 1), (a string matching /foo/)]
|
417
|
+
| got: [1.1, "food"]
|
418
|
+
EOS
|
419
|
+
end
|
420
|
+
end
|
421
|
+
|
377
422
|
describe "expect {...}.to yield_with_args( false )" do
|
378
423
|
it 'passes if the block yields with the given arguments' do
|
379
424
|
expect { |b| _yield_with_args(false, &b) }.to yield_with_args(false)
|
@@ -486,6 +531,31 @@ describe "yield_successive_args matcher" do
|
|
486
531
|
end
|
487
532
|
end
|
488
533
|
|
534
|
+
describe "expect {...}.to yield_successive_args(matcher, matcher)" do
|
535
|
+
it 'passes when the successively yielded args match the matchers' do
|
536
|
+
expect { |b|
|
537
|
+
%w[ food barn ].each(&b)
|
538
|
+
}.to yield_successive_args(a_string_matching(/foo/), a_string_matching(/bar/))
|
539
|
+
end
|
540
|
+
|
541
|
+
it 'fails when the successively yielded args do not match the matchers' do
|
542
|
+
expect {
|
543
|
+
expect { |b|
|
544
|
+
%w[ barn food ].each(&b)
|
545
|
+
}.to yield_successive_args(a_string_matching(/foo/), a_string_matching(/bar/))
|
546
|
+
}.to fail_with(dedent <<-EOS)
|
547
|
+
|expected given block to yield successively with arguments, but yielded with unexpected arguments
|
548
|
+
|expected: [(a string matching /foo/), (a string matching /bar/)]
|
549
|
+
| got: ["barn", "food"]
|
550
|
+
EOS
|
551
|
+
end
|
552
|
+
|
553
|
+
it 'provides a description' do
|
554
|
+
description = yield_successive_args(a_string_matching(/foo/), a_string_matching(/bar/)).description
|
555
|
+
expect(description).to eq("yield successive args(a string matching /foo/, a string matching /bar/)")
|
556
|
+
end
|
557
|
+
end
|
558
|
+
|
489
559
|
describe "expect {...}.not_to yield_successive_args(1, 2, 3)" do
|
490
560
|
it 'passes when the block does not yield' do
|
491
561
|
expect { |b| _dont_yield(&b) }.not_to yield_successive_args(1, 2, 3)
|
@@ -518,6 +588,26 @@ describe "yield_successive_args matcher" do
|
|
518
588
|
end
|
519
589
|
end
|
520
590
|
|
591
|
+
describe "expect {...}.not_to yield_successive_args(matcher, matcher)" do
|
592
|
+
it 'passes when the successively yielded args match the matchers' do
|
593
|
+
expect { |b|
|
594
|
+
%w[ barn food ].each(&b)
|
595
|
+
}.not_to yield_successive_args(a_string_matching(/foo/), a_string_matching(/bar/))
|
596
|
+
end
|
597
|
+
|
598
|
+
it 'fails when the successively yielded args do not match the matchers' do
|
599
|
+
expect {
|
600
|
+
expect { |b|
|
601
|
+
%w[ food barn ].each(&b)
|
602
|
+
}.not_to yield_successive_args(a_string_matching(/foo/), a_string_matching(/bar/))
|
603
|
+
}.to fail_with(dedent <<-EOS)
|
604
|
+
|expected given block not to yield successively with arguments, but yielded with expected arguments
|
605
|
+
|expected not: [(a string matching /foo/), (a string matching /bar/)]
|
606
|
+
| got: ["food", "barn"]
|
607
|
+
EOS
|
608
|
+
end
|
609
|
+
end
|
610
|
+
|
521
611
|
describe "expect {...}.to yield_successive_args(String, Fixnum)" do
|
522
612
|
it "passes if the block successively yields objects of the given types" do
|
523
613
|
expect { |b| ["string", 15].each(&b) }.to yield_successive_args(String, Fixnum)
|
@@ -87,9 +87,11 @@ module RSpec
|
|
87
87
|
|
88
88
|
it 'is a no-op when configured to :should twice' do
|
89
89
|
configure_syntax :should
|
90
|
-
|
90
|
+
method_added_count = 0
|
91
|
+
allow(Expectations::Syntax.default_should_host).to receive(:method_added) { method_added_count += 1 }
|
91
92
|
configure_syntax :should
|
92
|
-
|
93
|
+
|
94
|
+
method_added_count.should eq(0)
|
93
95
|
end
|
94
96
|
|
95
97
|
it 'can limit the syntax to :expect' do
|
@@ -102,7 +104,7 @@ module RSpec
|
|
102
104
|
end
|
103
105
|
|
104
106
|
it 'is a no-op when configured to :expect twice' do
|
105
|
-
RSpec::Matchers.
|
107
|
+
allow(RSpec::Matchers).to receive(:method_added).and_raise("no methods should be added here")
|
106
108
|
|
107
109
|
configure_syntax :expect
|
108
110
|
configure_syntax :expect
|
@@ -128,7 +130,7 @@ module RSpec
|
|
128
130
|
|
129
131
|
it "does not warn when only the should syntax is explicitly configured" do
|
130
132
|
configure_syntax(:should)
|
131
|
-
RSpec.
|
133
|
+
RSpec.should_not receive(:deprecate)
|
132
134
|
3.should eq(3)
|
133
135
|
end
|
134
136
|
|
@@ -158,40 +160,6 @@ module RSpec
|
|
158
160
|
3.should_not eq(4)
|
159
161
|
expect(3).to eq(3)
|
160
162
|
end
|
161
|
-
|
162
|
-
it 'does not add the deprecated #should to ExpectationTarget when only :should is enabled' do
|
163
|
-
et = Expectations::ExpectationTarget
|
164
|
-
|
165
|
-
configure_syntax :should
|
166
|
-
et.new(Proc.new {}).should be_an(et)
|
167
|
-
et.new(Proc.new {}).should_not be_a(Proc)
|
168
|
-
end
|
169
|
-
|
170
|
-
it 'does not add the deprecated #should to ExpectationTarget when only :expect is enabled' do
|
171
|
-
configure_syntax :expect
|
172
|
-
expect(expect(3)).not_to respond_to(:should)
|
173
|
-
expect(expect(3)).not_to respond_to(:should_not)
|
174
|
-
end
|
175
|
-
|
176
|
-
context 'when both :expect and :should are enabled' do
|
177
|
-
before { allow(RSpec).to receive(:deprecate) }
|
178
|
-
|
179
|
-
it 'allows `expect {}.should` to be used' do
|
180
|
-
configure_syntax [:should, :expect]
|
181
|
-
expect { raise "boom" }.should raise_error("boom")
|
182
|
-
expect { }.should_not raise_error
|
183
|
-
end
|
184
|
-
|
185
|
-
it 'prints a deprecation notice when `expect {}.should` is used' do
|
186
|
-
configure_syntax [:should, :expect]
|
187
|
-
|
188
|
-
expect(RSpec).to receive(:deprecate)
|
189
|
-
expect { raise "boom" }.should raise_error("boom")
|
190
|
-
|
191
|
-
expect(RSpec).to receive(:deprecate)
|
192
|
-
expect { }.should_not raise_error
|
193
|
-
end
|
194
|
-
end
|
195
163
|
end
|
196
164
|
|
197
165
|
def configure_default_syntax
|
@@ -237,7 +205,7 @@ module RSpec
|
|
237
205
|
# config setting, which makes it hard to get at the original
|
238
206
|
# default value. in spec_helper.rb we store the default value
|
239
207
|
# in $default_expectation_syntax so we can use it here.
|
240
|
-
expect($default_expectation_syntax).to
|
208
|
+
expect($default_expectation_syntax).to contain_exactly(:expect, :should)
|
241
209
|
end
|
242
210
|
end
|
243
211
|
end
|
@@ -45,9 +45,25 @@ describe "Matchers should be able to generate their own descriptions" do
|
|
45
45
|
expect(RSpec::Matchers.generated_description).to eq "should be > 3"
|
46
46
|
end
|
47
47
|
|
48
|
+
it "expect(...).to be between min and max" do
|
49
|
+
expect(10).to be_between(0, 10)
|
50
|
+
expect(RSpec::Matchers.generated_description).to eq "should be between 0 and 10 (inclusive)"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "expect(...).to be exclusively between min and max" do
|
54
|
+
expect(9).to be_between(0, 10).exclusive
|
55
|
+
expect(RSpec::Matchers.generated_description).to eq "should be between 0 and 10 (exclusive)"
|
56
|
+
end
|
57
|
+
|
48
58
|
it "expect(...).to be predicate arg1, arg2 and arg3" do
|
49
|
-
|
50
|
-
|
59
|
+
class Parent; end
|
60
|
+
class Child < Parent
|
61
|
+
def child_of?(*parents)
|
62
|
+
parents.all? { |parent| self.is_a?(parent) }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
expect(Child.new).to be_a_child_of(Parent, Object)
|
66
|
+
expect(RSpec::Matchers.generated_description).to eq "should be a child of Parent and Object"
|
51
67
|
end
|
52
68
|
|
53
69
|
it "expect(...).to equal" do
|
@@ -106,13 +122,13 @@ describe "Matchers should be able to generate their own descriptions" do
|
|
106
122
|
it "expect(...).to include(x) when x responds to description and is a matcher" do
|
107
123
|
matcher = double(:description => "description",
|
108
124
|
:matches? => true,
|
109
|
-
:
|
125
|
+
:failure_message => "")
|
110
126
|
expect([matcher]).to include(matcher)
|
111
|
-
expect(RSpec::Matchers.generated_description).to eq "should include description"
|
127
|
+
expect(RSpec::Matchers.generated_description).to eq "should include (description)"
|
112
128
|
end
|
113
129
|
|
114
|
-
it "expect(array).to
|
115
|
-
expect([1,2,3]).to
|
130
|
+
it "expect(array).to contain_exactly(1, 2, 3)" do
|
131
|
+
expect([1,2,3]).to contain_exactly(1, 2, 3)
|
116
132
|
expect(RSpec::Matchers.generated_description).to eq "should contain exactly 1, 2 and 3"
|
117
133
|
end
|
118
134
|
|