rspec-expectations 2.14.5 → 2.99.0
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.
- checksums.yaml +15 -7
- data/Changelog.md +114 -31
- data/features/README.md +2 -1
- data/features/built_in_matchers/be.feature +40 -40
- data/features/step_definitions/additional_cli_steps.rb +10 -0
- data/features/test_frameworks/test_unit.feature +40 -0
- data/lib/rspec/expectations/caller_filter.rb +60 -0
- data/lib/rspec/{matchers → expectations}/configuration.rb +5 -3
- data/lib/rspec/expectations/deprecation.rb +11 -15
- data/lib/rspec/expectations/expectation_target.rb +75 -8
- data/lib/rspec/expectations/handler.rb +5 -1
- data/lib/rspec/expectations/syntax.rb +3 -5
- data/lib/rspec/expectations/version.rb +1 -2
- data/lib/rspec/expectations.rb +1 -1
- data/lib/rspec/matchers/be_close.rb +4 -1
- data/lib/rspec/matchers/built_in/base_matcher.rb +10 -5
- data/lib/rspec/matchers/built_in/be.rb +38 -9
- data/lib/rspec/matchers/built_in/be_within.rb +8 -2
- data/lib/rspec/matchers/built_in/change.rb +39 -1
- data/lib/rspec/matchers/built_in/has.rb +40 -7
- data/lib/rspec/matchers/built_in/have.rb +151 -2
- data/lib/rspec/matchers/built_in/include.rb +1 -1
- data/lib/rspec/matchers/built_in/match_array.rb +1 -1
- data/lib/rspec/matchers/built_in/raise_error.rb +7 -1
- data/lib/rspec/matchers/built_in/respond_to.rb +7 -1
- data/lib/rspec/matchers/built_in/satisfy.rb +7 -1
- data/lib/rspec/matchers/built_in/throw_symbol.rb +10 -2
- data/lib/rspec/matchers/built_in/yield.rb +25 -3
- data/lib/rspec/matchers/built_in.rb +2 -2
- data/lib/rspec/matchers/differentiate_block_method_types.rb +55 -0
- data/lib/rspec/matchers/dsl.rb +2 -1
- data/lib/rspec/matchers/match_aliases.rb +22 -0
- data/lib/rspec/matchers/matcher.rb +131 -10
- data/lib/rspec/matchers/operator_matcher.rb +70 -70
- data/lib/rspec/matchers/pretty.rb +4 -0
- data/lib/rspec/matchers/test_unit_integration.rb +22 -5
- data/lib/rspec/matchers.rb +41 -7
- data/lib/rspec-expectations.rb +5 -0
- data/spec/rspec/{matchers → expectations}/configuration_spec.rb +21 -2
- data/spec/rspec/expectations/expectation_target_spec.rb +62 -0
- data/spec/rspec/expectations/extensions/kernel_spec.rb +4 -0
- data/spec/rspec/expectations/handler_spec.rb +1 -1
- data/spec/rspec/expectations/syntax_spec.rb +6 -6
- data/spec/rspec/expectations_spec.rb +22 -1
- data/spec/rspec/matchers/base_matcher_spec.rb +15 -21
- data/spec/rspec/matchers/be_close_spec.rb +4 -1
- data/spec/rspec/matchers/be_spec.rb +105 -10
- data/spec/rspec/matchers/change_spec.rb +76 -1
- data/spec/rspec/matchers/description_generation_spec.rb +22 -18
- data/spec/rspec/matchers/differentiate_block_method_types_spec.rb +39 -0
- data/spec/rspec/matchers/eq_spec.rb +1 -1
- data/spec/rspec/matchers/has_spec.rb +24 -0
- data/spec/rspec/matchers/have_spec.rb +399 -1
- data/spec/rspec/matchers/matcher_spec.rb +213 -24
- data/spec/rspec/matchers/operator_matcher_spec.rb +28 -9
- data/spec/rspec/matchers/pretty_spec.rb +23 -0
- data/spec/rspec/matchers/raise_error_spec.rb +3 -3
- data/spec/rspec/matchers/throw_symbol_spec.rb +14 -14
- data/spec/spec_helper.rb +4 -2
- data/spec/support/helper_methods.rb +42 -0
- data/spec/support/shared_examples.rb +42 -0
- metadata +85 -64
- data/spec/rspec/matchers/matchers_spec.rb +0 -37
|
@@ -91,8 +91,8 @@ module RSpec
|
|
|
91
91
|
|
|
92
92
|
context "when only :expect is enabled" do
|
|
93
93
|
before do
|
|
94
|
-
expect(Syntax.should_enabled?).to
|
|
95
|
-
expect(Syntax.expect_enabled?).to
|
|
94
|
+
expect(Syntax.should_enabled?).to be_falsey
|
|
95
|
+
expect(Syntax.expect_enabled?).to be_truthy
|
|
96
96
|
end
|
|
97
97
|
|
|
98
98
|
it 'generates a positive expression using the expect syntax' do
|
|
@@ -106,8 +106,8 @@ module RSpec
|
|
|
106
106
|
|
|
107
107
|
context "when both :should and :expect are enabled", :uses_should do
|
|
108
108
|
before do
|
|
109
|
-
expect(Syntax.should_enabled?).to
|
|
110
|
-
expect(Syntax.expect_enabled?).to
|
|
109
|
+
expect(Syntax.should_enabled?).to be_truthy
|
|
110
|
+
expect(Syntax.expect_enabled?).to be_truthy
|
|
111
111
|
end
|
|
112
112
|
|
|
113
113
|
it 'generates a positive expression using the expect syntax' do
|
|
@@ -121,8 +121,8 @@ module RSpec
|
|
|
121
121
|
|
|
122
122
|
context "when only :should is enabled", :uses_only_should do
|
|
123
123
|
before do
|
|
124
|
-
Syntax.should_enabled?.should
|
|
125
|
-
Syntax.expect_enabled?.should
|
|
124
|
+
Syntax.should_enabled?.should be_truthy
|
|
125
|
+
Syntax.expect_enabled?.should be_falsey
|
|
126
126
|
end
|
|
127
127
|
|
|
128
128
|
it 'generates a positive expression using the expect syntax' do
|
|
@@ -1,5 +1,26 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
1
3
|
module RSpec
|
|
2
4
|
describe Expectations do
|
|
5
|
+
def file_contents_for(lib, filename)
|
|
6
|
+
# http://rubular.com/r/HYpUMftlG2
|
|
7
|
+
path = $LOAD_PATH.find { |p| p.match(/\/rspec-#{lib}(-[a-f0-9]+)?\/lib/) }
|
|
8
|
+
file = File.join(path, filename)
|
|
9
|
+
File.read(file)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'has an up-to-date caller_filter file' do
|
|
13
|
+
expectations = file_contents_for("expectations", "rspec/expectations/caller_filter.rb")
|
|
14
|
+
core = file_contents_for("core", "rspec/core/caller_filter.rb")
|
|
15
|
+
|
|
16
|
+
expect(expectations).to eq(core)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'prints a deprecation warning when the root file is loaded' do
|
|
20
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /rspec-expectations/)
|
|
21
|
+
load "rspec-expectations.rb"
|
|
22
|
+
end
|
|
23
|
+
|
|
3
24
|
describe '.method_handle_for(object, method_name)' do
|
|
4
25
|
|
|
5
26
|
class UntamperedClass
|
|
@@ -36,7 +57,7 @@ module RSpec
|
|
|
36
57
|
expect(Expectations.method_handle_for(object, :foo).call).to eq :bar
|
|
37
58
|
end
|
|
38
59
|
|
|
39
|
-
it 'fetches method definitions for basic objects', :if => RUBY_VERSION.to_i >= 2 do
|
|
60
|
+
it 'fetches method definitions for basic objects', :if => (RUBY_VERSION.to_i >= 2 && RUBY_ENGINE != 'rbx') do
|
|
40
61
|
object = BasicClass.new
|
|
41
62
|
expect(Expectations.method_handle_for(object, :foo).call).to eq :bar
|
|
42
63
|
end
|
|
@@ -8,21 +8,21 @@ module RSpec::Matchers::BuiltIn
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
it "returns true if there are no errors" do
|
|
11
|
-
expect(matcher.match_unless_raises {}).to
|
|
11
|
+
expect(matcher.match_unless_raises {}).to be_truthy
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
it "returns false if there is an error" do
|
|
15
|
-
expect(matcher.match_unless_raises { raise }).to
|
|
15
|
+
expect(matcher.match_unless_raises { raise }).to be_falsey
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
it "returns false if the only submitted error is raised" do
|
|
19
|
-
expect(matcher.match_unless_raises(RuntimeError){ raise "foo" }).to
|
|
19
|
+
expect(matcher.match_unless_raises(RuntimeError){ raise "foo" }).to be_falsey
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
it "returns false if any of several errors submitted is raised" do
|
|
23
|
-
expect(matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise "foo" }).to
|
|
24
|
-
expect(matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise ArgumentError.new('') }).to
|
|
25
|
-
expect(matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise NameError.new('') }).to
|
|
23
|
+
expect(matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise "foo" }).to be_falsey
|
|
24
|
+
expect(matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise ArgumentError.new('') }).to be_falsey
|
|
25
|
+
expect(matcher.match_unless_raises(RuntimeError, ArgumentError, NameError) { raise NameError.new('') }).to be_falsey
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
it "re-raises any error other than one of those specified" do
|
|
@@ -60,24 +60,18 @@ module RSpec::Matchers::BuiltIn
|
|
|
60
60
|
end
|
|
61
61
|
end
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
@expected = expected
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def matches?(actual)
|
|
71
|
-
(@actual = actual) == @expected
|
|
72
|
-
end
|
|
63
|
+
it_behaves_like "an RSpec matcher", :valid_value => 3, :invalid_value => 4 do
|
|
64
|
+
matcher_class = Class.new(BaseMatcher) do
|
|
65
|
+
def initialize(expected)
|
|
66
|
+
@expected = expected
|
|
73
67
|
end
|
|
74
68
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
expect(matcher.new(3).matches?(4)).to be_false
|
|
79
|
-
expect(matcher.new(3)).not_to eq(4)
|
|
69
|
+
def matches?(actual)
|
|
70
|
+
(@actual = actual) == @expected
|
|
71
|
+
end
|
|
80
72
|
end
|
|
73
|
+
|
|
74
|
+
let(:matcher) { matcher_class.new(3) }
|
|
81
75
|
end
|
|
82
76
|
end
|
|
83
77
|
end
|
|
@@ -8,7 +8,10 @@ module RSpec
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
it "is deprecated" do
|
|
11
|
-
|
|
11
|
+
expect_deprecation_with_type('be_close(3.0, 0.5)',
|
|
12
|
+
'be_within(0.5).of(3.0)',
|
|
13
|
+
'the be_close matcher'
|
|
14
|
+
)
|
|
12
15
|
be_close(3.0, 0.5)
|
|
13
16
|
end
|
|
14
17
|
|
|
@@ -31,6 +31,22 @@ describe "expect(...).to be_predicate" do
|
|
|
31
31
|
}.to raise_error(NameError, /happy\?/)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
it 'warns of deprecation when :predicate? is private' do
|
|
35
|
+
privately_happy = Class.new do
|
|
36
|
+
private
|
|
37
|
+
def happy?
|
|
38
|
+
true
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
allow(RSpec).to receive(:deprecate)
|
|
42
|
+
expect(RSpec).to receive(:deprecate).with(
|
|
43
|
+
"matching with be_happy on private method happy?",
|
|
44
|
+
:replacement => "`expect(object.send(:happy?)).to be_true` or change the method's visibility to public",
|
|
45
|
+
:call_site => RSpec::Mocks::ArgumentMatchers::RegexpMatcher.new(/#{__FILE__}:#{__LINE__ + 2}/)
|
|
46
|
+
)
|
|
47
|
+
expect(privately_happy.new).to be_happy
|
|
48
|
+
end
|
|
49
|
+
|
|
34
50
|
it "fails on error other than NameError" do
|
|
35
51
|
actual = double("actual")
|
|
36
52
|
actual.should_receive(:foo?).and_raise("aaaah")
|
|
@@ -50,7 +66,27 @@ describe "expect(...).to be_predicate" do
|
|
|
50
66
|
it "does not support operator chaining like a basic `be` matcher does" do
|
|
51
67
|
matcher = be_happy
|
|
52
68
|
value = double(:happy? => false)
|
|
53
|
-
expect(
|
|
69
|
+
expect(matcher == value).to be false
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it 'warns of deprecation when actual does not respond to :predicate?' do
|
|
73
|
+
oddly_happy_class = Class.new do
|
|
74
|
+
def method_missing(method)
|
|
75
|
+
return true if method == :happy?
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /Matching with be_happy on an object that doesn't respond to `happy\?`/)
|
|
79
|
+
expect(oddly_happy_class.new).to be_happy
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it 'does not warn of deprecation when actual responds to present tense predicate' do
|
|
83
|
+
present_happy_class = Class.new do
|
|
84
|
+
def exists?
|
|
85
|
+
true
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
expect_no_deprecation
|
|
89
|
+
expect(present_happy_class.new).to be_exist
|
|
54
90
|
end
|
|
55
91
|
end
|
|
56
92
|
|
|
@@ -231,35 +267,94 @@ describe "expect(...).not_to be_predicate(*args, &block)" do
|
|
|
231
267
|
end
|
|
232
268
|
end
|
|
233
269
|
|
|
234
|
-
describe "expect(...).to
|
|
270
|
+
describe "expect(...).to be_truthy" do
|
|
235
271
|
it "passes when actual equal?(true)" do
|
|
236
|
-
expect(true).to
|
|
272
|
+
expect(true).to be_truthy
|
|
237
273
|
end
|
|
238
274
|
|
|
239
275
|
it "passes when actual is 1" do
|
|
240
|
-
expect(1).to
|
|
276
|
+
expect(1).to be_truthy
|
|
241
277
|
end
|
|
242
278
|
|
|
243
279
|
it "fails when actual equal?(false)" do
|
|
244
280
|
expect {
|
|
245
|
-
expect(false).to
|
|
246
|
-
}.to fail_with("expected:
|
|
281
|
+
expect(false).to be_truthy
|
|
282
|
+
}.to fail_with("expected: truthy value\n got: false")
|
|
247
283
|
end
|
|
248
284
|
end
|
|
249
285
|
|
|
250
286
|
describe "expect(...).to be_false" do
|
|
251
|
-
it "
|
|
287
|
+
it "is deprecated" do
|
|
288
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /be_false/)
|
|
289
|
+
expect(false).to be_false
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
it "has the correct call site in the deprecation message" do
|
|
293
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1)
|
|
294
|
+
expect(false).to be_false
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
it "still passes" do
|
|
298
|
+
allow(RSpec).to receive(:deprecate)
|
|
252
299
|
expect(false).to be_false
|
|
253
300
|
end
|
|
254
301
|
|
|
302
|
+
it "still fails" do
|
|
303
|
+
allow(RSpec).to receive(:deprecate)
|
|
304
|
+
expect {
|
|
305
|
+
expect(true).to be_false
|
|
306
|
+
}.to fail_with(/expected: falsey value/)
|
|
307
|
+
end
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
describe "expect(...).to be_true" do
|
|
311
|
+
it "is deprecated" do
|
|
312
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /be_true/)
|
|
313
|
+
expect(true).to be_true
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
it "still passes" do
|
|
317
|
+
allow(RSpec).to receive(:deprecate)
|
|
318
|
+
expect(true).to be_true
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
it "still fails" do
|
|
322
|
+
allow(RSpec).to receive(:deprecate)
|
|
323
|
+
expect {
|
|
324
|
+
expect(false).to be_true
|
|
325
|
+
}.to fail_with(/expected: truthy value/)
|
|
326
|
+
end
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
describe "expect(...).to be_falsey" do
|
|
330
|
+
it "passes when actual equal?(false)" do
|
|
331
|
+
expect(false).to be_falsey
|
|
332
|
+
end
|
|
333
|
+
|
|
255
334
|
it "passes when actual equal?(nil)" do
|
|
256
|
-
expect(nil).to
|
|
335
|
+
expect(nil).to be_falsey
|
|
257
336
|
end
|
|
258
337
|
|
|
259
338
|
it "fails when actual equal?(true)" do
|
|
260
339
|
expect {
|
|
261
|
-
expect(true).to
|
|
262
|
-
}.to fail_with("expected:
|
|
340
|
+
expect(true).to be_falsey
|
|
341
|
+
}.to fail_with("expected: falsey value\n got: true")
|
|
342
|
+
end
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
describe "expect(...).to be_falsy" do
|
|
346
|
+
it "passes when actual equal?(false)" do
|
|
347
|
+
expect(false).to be_falsy
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
it "passes when actual equal?(nil)" do
|
|
351
|
+
expect(nil).to be_falsy
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
it "fails when actual equal?(true)" do
|
|
355
|
+
expect {
|
|
356
|
+
expect(true).to be_falsy
|
|
357
|
+
}.to fail_with("expected: falsey value\n got: true")
|
|
263
358
|
end
|
|
264
359
|
end
|
|
265
360
|
|
|
@@ -193,7 +193,8 @@ end
|
|
|
193
193
|
|
|
194
194
|
describe "expect { ... }.to change { block }" do
|
|
195
195
|
o = SomethingExpected.new
|
|
196
|
-
|
|
196
|
+
o.some_value = 1
|
|
197
|
+
it_behaves_like "an RSpec matcher", :valid_value => lambda { o.some_value += 1 },
|
|
197
198
|
:invalid_value => lambda { } do
|
|
198
199
|
let(:matcher) { change { o.some_value } }
|
|
199
200
|
end
|
|
@@ -247,6 +248,80 @@ describe "expect { ... }.not_to change { block }" do
|
|
|
247
248
|
end
|
|
248
249
|
end
|
|
249
250
|
|
|
251
|
+
describe "expect { ... }.not_to change { }.from" do
|
|
252
|
+
context 'when the value starts at the from value' do
|
|
253
|
+
it 'passes when the value does not change' do
|
|
254
|
+
k = 5
|
|
255
|
+
expect { }.not_to change { k }.from(5)
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
it 'fails when the value does change' do
|
|
259
|
+
expect {
|
|
260
|
+
k = 5
|
|
261
|
+
expect { k += 1 }.not_to change { k }.from(5)
|
|
262
|
+
}.to fail_with(/but did change from 5 to 6/)
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
it 'does not issue a deprecation warning' do
|
|
266
|
+
expect(RSpec.configuration.reporter).not_to receive(:deprecation)
|
|
267
|
+
k = 5
|
|
268
|
+
expect { }.not_to change { k }.from(5)
|
|
269
|
+
end
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
context 'when the value starts at a different value' do
|
|
273
|
+
before { allow_deprecation }
|
|
274
|
+
|
|
275
|
+
it 'passes when the value does not change' do
|
|
276
|
+
k = 6
|
|
277
|
+
expect { }.not_to change { k }.from(5)
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
it 'passes when the value does change' do
|
|
281
|
+
k = 6
|
|
282
|
+
expect { k += 1 }.not_to change { k }.from(5)
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
it 'issues a deprecation warning' do
|
|
286
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 2, /#{Regexp.escape("expect { }.not_to change { }.from()")}/)
|
|
287
|
+
k = 6
|
|
288
|
+
expect { }.not_to change { k }.from(5)
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
describe "expect { ... }.not_to change { }.to" do
|
|
294
|
+
it 'issues a deprecation warning' do
|
|
295
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /#{Regexp.escape("expect { }.not_to change { }.to()")}/)
|
|
296
|
+
expect {
|
|
297
|
+
}.not_to change { }.to(3)
|
|
298
|
+
end
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
describe "expect { ... }.not_to change { }.by" do
|
|
302
|
+
it 'issues a deprecation warning' do
|
|
303
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /#{Regexp.escape("expect { }.not_to change { }.by()")}/)
|
|
304
|
+
expect {
|
|
305
|
+
}.not_to change { }.by(3)
|
|
306
|
+
end
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
describe "expect { ... }.not_to change { }.by_at_least" do
|
|
310
|
+
it 'issues a deprecation warning' do
|
|
311
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /#{Regexp.escape("expect { }.not_to change { }.by_at_least()")}/)
|
|
312
|
+
expect {
|
|
313
|
+
}.not_to change { }.by_at_least(3)
|
|
314
|
+
end
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
describe "expect { ... }.not_to change { }.by_at_most" do
|
|
318
|
+
it 'issues a deprecation warning' do
|
|
319
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /#{Regexp.escape("expect { }.not_to change { }.by_at_most()")}/)
|
|
320
|
+
expect {
|
|
321
|
+
}.not_to change { }.by_at_most(3)
|
|
322
|
+
end
|
|
323
|
+
end
|
|
324
|
+
|
|
250
325
|
describe "expect { ... }.to change(actual, message).by(expected)" do
|
|
251
326
|
before(:each) do
|
|
252
327
|
@instance = SomethingExpected.new
|
|
@@ -25,14 +25,14 @@ describe "Matchers should be able to generate their own descriptions" do
|
|
|
25
25
|
expect(RSpec::Matchers.generated_description).to eq "should not be empty"
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
it "expect(...).to be
|
|
29
|
-
expect(true).to
|
|
30
|
-
expect(RSpec::Matchers.generated_description).to eq "should be
|
|
28
|
+
it "expect(...).to be truthy" do
|
|
29
|
+
expect(true).to be_truthy
|
|
30
|
+
expect(RSpec::Matchers.generated_description).to eq "should be truthy"
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
it "expect(...).to be
|
|
34
|
-
expect(false).to
|
|
35
|
-
expect(RSpec::Matchers.generated_description).to eq "should be
|
|
33
|
+
it "expect(...).to be falsey" do
|
|
34
|
+
expect(false).to be_falsey
|
|
35
|
+
expect(RSpec::Matchers.generated_description).to eq "should be falsey"
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
it "expect(...).to be nil" do
|
|
@@ -92,19 +92,23 @@ describe "Matchers should be able to generate their own descriptions" do
|
|
|
92
92
|
expect(RSpec::Matchers.generated_description).to eq 'should have taste for "wine", "cheese"'
|
|
93
93
|
end
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
expect(RSpec::Matchers.generated_description).to eq "should have 3 players"
|
|
98
|
-
end
|
|
95
|
+
context "the deprecated collection cardinality matchers" do
|
|
96
|
+
before { allow_deprecation }
|
|
99
97
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
98
|
+
it "expect(...).to have n items" do
|
|
99
|
+
expect(team).to have(3).players
|
|
100
|
+
expect(RSpec::Matchers.generated_description).to eq "should have 3 players"
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it "expect(...).to have at least n items" do
|
|
104
|
+
expect(team).to have_at_least(2).players
|
|
105
|
+
expect(RSpec::Matchers.generated_description).to eq "should have at least 2 players"
|
|
106
|
+
end
|
|
104
107
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
+
it "expect(...).to have at most n items" do
|
|
109
|
+
expect(team).to have_at_most(4).players
|
|
110
|
+
expect(RSpec::Matchers.generated_description).to eq "should have at most 4 players"
|
|
111
|
+
end
|
|
108
112
|
end
|
|
109
113
|
|
|
110
114
|
it "expect(...).to include(x)" do
|
|
@@ -128,7 +132,7 @@ describe "Matchers should be able to generate their own descriptions" do
|
|
|
128
132
|
|
|
129
133
|
it "expect(array).not_to match_array [1,2,3]" do
|
|
130
134
|
expect([1,2,3]).to match_array [1,2,3]
|
|
131
|
-
expect(RSpec::Matchers.generated_description).to eq "should contain exactly 1, 2 and 3"
|
|
135
|
+
expect(RSpec::Matchers.generated_description).to eq "should contain exactly 1, 2, and 3"
|
|
132
136
|
end
|
|
133
137
|
|
|
134
138
|
it "expect(...).to match" do
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module RSpec
|
|
4
|
+
module Matchers
|
|
5
|
+
describe DifferentiateBlockMethodTypes do
|
|
6
|
+
let(:differentiator) do
|
|
7
|
+
DifferentiateBlockMethodTypes.new do
|
|
8
|
+
def some_instance_method_1; end
|
|
9
|
+
def self.some_singleton_method_1; end
|
|
10
|
+
define_method(:some_instance_method_2) { }
|
|
11
|
+
|
|
12
|
+
if RUBY_VERSION.to_f > 1.8
|
|
13
|
+
define_singleton_method(:some_singleton_method_2) { }
|
|
14
|
+
else
|
|
15
|
+
def self.some_singleton_method_2; end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'differentiates singleton method defs from instance method defs' do
|
|
21
|
+
expect(differentiator.instance_methods).to eq([:some_instance_method_1, :some_instance_method_2])
|
|
22
|
+
expect(differentiator.singleton_methods).to eq([:some_singleton_method_1, :some_singleton_method_2])
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'passes the given args through to the block' do
|
|
26
|
+
expect { |b|
|
|
27
|
+
DifferentiateBlockMethodTypes.new(1, 2, &b)
|
|
28
|
+
}.to yield_with_args(1, 2)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'ignores unrecognized DSL methods called in the block' do
|
|
32
|
+
expect {
|
|
33
|
+
DifferentiateBlockMethodTypes.new { foo.bar; some_dsl { nested } }
|
|
34
|
+
}.not_to raise_error
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
@@ -48,6 +48,20 @@ describe "expect(...).to have_sym(*args)" do
|
|
|
48
48
|
}.to raise_error(NoMethodError)
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
+
it "warns of deprecation if #has_sym?(*args) is private" do
|
|
52
|
+
klass = Class.new do
|
|
53
|
+
def has_foo?
|
|
54
|
+
true
|
|
55
|
+
end
|
|
56
|
+
private :has_foo?
|
|
57
|
+
|
|
58
|
+
# prevents double deprecation
|
|
59
|
+
def respond_to?(_); true; end
|
|
60
|
+
end
|
|
61
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /matching with have_foo on private method/)
|
|
62
|
+
expect(klass.new).to have_foo
|
|
63
|
+
end
|
|
64
|
+
|
|
51
65
|
it "reraises an exception thrown in #has_sym?(*args)" do
|
|
52
66
|
o = Object.new
|
|
53
67
|
def o.has_sym?(*args)
|
|
@@ -57,6 +71,16 @@ describe "expect(...).to have_sym(*args)" do
|
|
|
57
71
|
expect(o).to have_sym(:foo)
|
|
58
72
|
}.to raise_error("Funky exception")
|
|
59
73
|
end
|
|
74
|
+
|
|
75
|
+
it 'warns of deprecation when actual does not respond to #has_sym?' do
|
|
76
|
+
foo_class = Class.new do
|
|
77
|
+
def method_missing(method)
|
|
78
|
+
return true if method == :has_foo?
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /Matching with have_foo on an object that doesn't respond to `has_foo\?`/)
|
|
82
|
+
expect(foo_class.new).to have_foo
|
|
83
|
+
end
|
|
60
84
|
end
|
|
61
85
|
|
|
62
86
|
describe "expect(...).not_to have_sym(*args)" do
|