rspec-expectations 2.13.0 → 2.14.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.
- data/Changelog.md +46 -0
- data/README.md +43 -87
- data/features/README.md +8 -9
- data/features/built_in_matchers/README.md +41 -41
- data/features/built_in_matchers/be_within.feature +3 -3
- data/features/built_in_matchers/expect_change.feature +6 -6
- data/features/built_in_matchers/expect_error.feature +2 -2
- data/features/built_in_matchers/start_with.feature +1 -1
- data/features/built_in_matchers/throw_symbol.feature +11 -11
- data/features/built_in_matchers/yield.feature +18 -3
- data/features/custom_matchers/define_diffable_matcher.feature +1 -1
- data/features/custom_matchers/define_matcher_outside_rspec.feature +6 -6
- data/features/custom_matchers/define_matcher_with_fluent_interface.feature +1 -1
- data/features/customized_message.feature +1 -1
- data/features/support/env.rb +10 -1
- data/features/syntax_configuration.feature +3 -0
- data/features/test_frameworks/test_unit.feature +15 -17
- data/lib/rspec/expectations/deprecation.rb +12 -33
- data/lib/rspec/expectations/differ.rb +25 -7
- data/lib/rspec/expectations/expectation_target.rb +7 -8
- data/lib/rspec/expectations/extensions/object.rb +2 -12
- data/lib/rspec/expectations/fail_with.rb +11 -1
- data/lib/rspec/expectations/handler.rb +11 -6
- data/lib/rspec/expectations/syntax.rb +2 -2
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/expectations.rb +1 -1
- data/lib/rspec/matchers/be_close.rb +1 -1
- data/lib/rspec/matchers/built_in/be.rb +2 -0
- data/lib/rspec/matchers/built_in/be_within.rb +1 -1
- data/lib/rspec/matchers/built_in/change.rb +9 -1
- data/lib/rspec/matchers/built_in/have.rb +20 -4
- data/lib/rspec/matchers/built_in/include.rb +2 -10
- data/lib/rspec/matchers/built_in/raise_error.rb +23 -7
- data/lib/rspec/matchers/built_in/yield.rb +78 -3
- data/lib/rspec/matchers/operator_matcher.rb +1 -1
- data/lib/rspec/matchers/pretty.rb +7 -1
- data/lib/rspec/matchers/test_unit_integration.rb +11 -0
- data/lib/rspec/matchers.rb +141 -143
- data/spec/rspec/expectations/differ_spec.rb +27 -5
- data/spec/rspec/expectations/expectation_target_spec.rb +10 -3
- data/spec/rspec/expectations/extensions/kernel_spec.rb +5 -5
- data/spec/rspec/expectations/fail_with_spec.rb +19 -0
- data/spec/rspec/expectations/handler_spec.rb +42 -21
- data/spec/rspec/expectations/syntax_spec.rb +45 -3
- data/spec/rspec/matchers/be_close_spec.rb +6 -6
- data/spec/rspec/matchers/be_spec.rb +36 -36
- data/spec/rspec/matchers/be_within_spec.rb +8 -0
- data/spec/rspec/matchers/change_spec.rb +17 -6
- data/spec/rspec/matchers/configuration_spec.rb +57 -89
- data/spec/rspec/matchers/description_generation_spec.rb +16 -2
- data/spec/rspec/matchers/exist_spec.rb +9 -9
- data/spec/rspec/matchers/has_spec.rb +1 -1
- data/spec/rspec/matchers/have_spec.rb +12 -2
- data/spec/rspec/matchers/include_matcher_integration_spec.rb +2 -2
- data/spec/rspec/matchers/include_spec.rb +4 -4
- data/spec/rspec/matchers/match_array_spec.rb +1 -1
- data/spec/rspec/matchers/match_spec.rb +1 -1
- data/spec/rspec/matchers/raise_error_spec.rb +189 -99
- data/spec/rspec/matchers/respond_to_spec.rb +4 -4
- data/spec/rspec/matchers/satisfy_spec.rb +1 -1
- data/spec/rspec/matchers/start_with_end_with_spec.rb +2 -2
- data/spec/rspec/matchers/yield_spec.rb +81 -4
- data/spec/spec_helper.rb +1 -1
- metadata +8 -7
|
@@ -22,7 +22,12 @@ module RSpec
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
before do
|
|
25
|
-
RSpec.configuration.
|
|
25
|
+
@old_patterns = RSpec.configuration.backtrace_exclusion_patterns
|
|
26
|
+
RSpec.configuration.backtrace_exclusion_patterns = [/clean-me/]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
after do
|
|
30
|
+
RSpec.configuration.backtrace_exclusion_patterns = @old_patterns
|
|
26
31
|
end
|
|
27
32
|
|
|
28
33
|
it "defaults to rspec-core's backtrace formatter when rspec-core is loaded" do
|
|
@@ -36,7 +41,7 @@ module RSpec
|
|
|
36
41
|
end
|
|
37
42
|
|
|
38
43
|
it "can be set to another backtrace formatter" do
|
|
39
|
-
config.backtrace_formatter =
|
|
44
|
+
config.backtrace_formatter = double(:format_backtrace => ['a'])
|
|
40
45
|
expect(formatted_backtrace).to eq(['a'])
|
|
41
46
|
end
|
|
42
47
|
end
|
|
@@ -60,134 +65,97 @@ module RSpec
|
|
|
60
65
|
end
|
|
61
66
|
|
|
62
67
|
shared_examples_for "configuring the expectation syntax" do
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
# On jRuby we just re-enable both syntaxes at the end of the example;
|
|
70
|
-
# however, this is a generally inferior approach because it depends on
|
|
71
|
-
# the code-under-test working properly; if it doesn't work properly,
|
|
72
|
-
# it could leave things in a "broken" state where tons of other examples fail.
|
|
73
|
-
if RUBY_PLATFORM == "java"
|
|
74
|
-
def sandboxed
|
|
75
|
-
orig_syntax = RSpec::Matchers.configuration.syntax
|
|
76
|
-
yield
|
|
77
|
-
ensure
|
|
78
|
-
configure_syntax(orig_syntax)
|
|
79
|
-
end
|
|
80
|
-
else
|
|
81
|
-
include InSubProcess
|
|
82
|
-
alias sandboxed in_sub_process
|
|
68
|
+
before do
|
|
69
|
+
@orig_syntax = RSpec::Matchers.configuration.syntax
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
after do
|
|
73
|
+
configure_syntax(@orig_syntax)
|
|
83
74
|
end
|
|
84
75
|
|
|
85
76
|
it 'can limit the syntax to :should' do
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
configured_syntax.should eq([:should])
|
|
77
|
+
configure_syntax :should
|
|
78
|
+
configured_syntax.should eq([:should])
|
|
89
79
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
end
|
|
80
|
+
3.should eq(3)
|
|
81
|
+
3.should_not eq(4)
|
|
82
|
+
lambda { expect(6).to eq(6) }.should raise_error(NameError)
|
|
94
83
|
end
|
|
95
84
|
|
|
96
85
|
it 'is a no-op when configured to :should twice' do
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
stub(:method_added).
|
|
102
|
-
and_raise("no methods should be added here")
|
|
103
|
-
|
|
104
|
-
configure_syntax :should
|
|
105
|
-
end
|
|
86
|
+
configure_syntax :should
|
|
87
|
+
Expectations::Syntax.default_should_host.should_not_receive(:method_added)
|
|
88
|
+
configure_syntax :should
|
|
89
|
+
RSpec::Mocks.verify # because configure_syntax is called again in an after hook
|
|
106
90
|
end
|
|
107
91
|
|
|
108
92
|
it 'can limit the syntax to :expect' do
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
expect(configured_syntax).to eq([:expect])
|
|
93
|
+
configure_syntax :expect
|
|
94
|
+
expect(configured_syntax).to eq([:expect])
|
|
112
95
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
end
|
|
96
|
+
expect(3).to eq(3)
|
|
97
|
+
expect { 3.should eq(3) }.to raise_error(NameError)
|
|
98
|
+
expect { 3.should_not eq(3) }.to raise_error(NameError)
|
|
117
99
|
end
|
|
118
100
|
|
|
119
101
|
it 'is a no-op when configured to :expect twice' do
|
|
120
|
-
|
|
121
|
-
RSpec::Matchers.stub(:method_added).and_raise("no methods should be added here")
|
|
102
|
+
RSpec::Matchers.stub(:method_added).and_raise("no methods should be added here")
|
|
122
103
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
end
|
|
104
|
+
configure_syntax :expect
|
|
105
|
+
configure_syntax :expect
|
|
126
106
|
end
|
|
127
107
|
|
|
128
108
|
it 'can re-enable the :should syntax' do
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
configured_syntax.should eq([:should, :expect])
|
|
109
|
+
configure_syntax :expect
|
|
110
|
+
configure_syntax [:should, :expect]
|
|
111
|
+
configured_syntax.should eq([:should, :expect])
|
|
133
112
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
end
|
|
113
|
+
3.should eq(3)
|
|
114
|
+
3.should_not eq(4)
|
|
115
|
+
expect(3).to eq(3)
|
|
138
116
|
end
|
|
139
117
|
|
|
140
118
|
it 'can re-enable the :expect syntax' do
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
configured_syntax.should eq([:should, :expect])
|
|
119
|
+
configure_syntax :should
|
|
120
|
+
configure_syntax [:should, :expect]
|
|
121
|
+
configured_syntax.should eq([:should, :expect])
|
|
145
122
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
end
|
|
123
|
+
3.should eq(3)
|
|
124
|
+
3.should_not eq(4)
|
|
125
|
+
expect(3).to eq(3)
|
|
150
126
|
end
|
|
151
127
|
|
|
152
128
|
it 'does not add the deprecated #should to ExpectationTarget when only :should is enabled' do
|
|
153
129
|
et = Expectations::ExpectationTarget
|
|
154
130
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
et.new(Proc.new {}).should_not be_a(Proc)
|
|
159
|
-
end
|
|
131
|
+
configure_syntax :should
|
|
132
|
+
et.new(Proc.new {}).should be_an(et)
|
|
133
|
+
et.new(Proc.new {}).should_not be_a(Proc)
|
|
160
134
|
end
|
|
161
135
|
|
|
162
136
|
it 'does not add the deprecated #should to ExpectationTarget when only :expect is enabled' do
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
expect(expect(3)).not_to respond_to(:should_not)
|
|
167
|
-
end
|
|
137
|
+
configure_syntax :expect
|
|
138
|
+
expect(expect(3)).not_to respond_to(:should)
|
|
139
|
+
expect(expect(3)).not_to respond_to(:should_not)
|
|
168
140
|
end
|
|
169
141
|
|
|
170
142
|
context 'when both :expect and :should are enabled' do
|
|
171
|
-
before { RSpec.
|
|
143
|
+
before { allow(RSpec).to receive(:deprecate) }
|
|
172
144
|
|
|
173
145
|
it 'allows `expect {}.should` to be used' do
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
expect { }.should_not raise_error
|
|
178
|
-
end
|
|
146
|
+
configure_syntax [:should, :expect]
|
|
147
|
+
expect { raise "boom" }.should raise_error("boom")
|
|
148
|
+
expect { }.should_not raise_error
|
|
179
149
|
end
|
|
180
150
|
|
|
181
151
|
it 'prints a deprecation notice when `expect {}.should` is used' do
|
|
182
|
-
|
|
183
|
-
configure_syntax [:should, :expect]
|
|
152
|
+
configure_syntax [:should, :expect]
|
|
184
153
|
|
|
185
|
-
|
|
186
|
-
|
|
154
|
+
expect(RSpec).to receive(:deprecate)
|
|
155
|
+
expect { raise "boom" }.should raise_error("boom")
|
|
187
156
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
end
|
|
157
|
+
expect(RSpec).to receive(:deprecate)
|
|
158
|
+
expect { }.should_not raise_error
|
|
191
159
|
end
|
|
192
160
|
end
|
|
193
161
|
end
|
|
@@ -107,11 +107,25 @@ describe "Matchers should be able to generate their own descriptions" do
|
|
|
107
107
|
expect(RSpec::Matchers.generated_description).to eq "should have at most 4 players"
|
|
108
108
|
end
|
|
109
109
|
|
|
110
|
-
it "expect(...).to include" do
|
|
110
|
+
it "expect(...).to include(x)" do
|
|
111
111
|
expect([1,2,3]).to include(3)
|
|
112
112
|
expect(RSpec::Matchers.generated_description).to eq "should include 3"
|
|
113
113
|
end
|
|
114
114
|
|
|
115
|
+
it "expect(...).to include(x) when x responds to description but is not a matcher" do
|
|
116
|
+
obj = double(:description => "description", :inspect => "inspect")
|
|
117
|
+
expect([obj]).to include(obj)
|
|
118
|
+
expect(RSpec::Matchers.generated_description).to eq "should include inspect"
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it "expect(...).to include(x) when x responds to description and is a matcher" do
|
|
122
|
+
matcher = double(:description => "description",
|
|
123
|
+
:matches? => true,
|
|
124
|
+
:failure_message_for_should => "")
|
|
125
|
+
expect([matcher]).to include(matcher)
|
|
126
|
+
expect(RSpec::Matchers.generated_description).to eq "should include description"
|
|
127
|
+
end
|
|
128
|
+
|
|
115
129
|
it "expect(array).not_to match_array [1,2,3]" do
|
|
116
130
|
expect([1,2,3]).to match_array [1,2,3]
|
|
117
131
|
expect(RSpec::Matchers.generated_description).to eq "should contain exactly 1, 2 and 3"
|
|
@@ -171,6 +185,6 @@ describe "a Matcher with no description" do
|
|
|
171
185
|
|
|
172
186
|
it "provides a helpful message when used in a string-less example block" do
|
|
173
187
|
expect(5).to matcher
|
|
174
|
-
expect(RSpec::Matchers.generated_description).to match
|
|
188
|
+
expect(RSpec::Matchers.generated_description).to match(/When you call.*description method/m)
|
|
175
189
|
end
|
|
176
190
|
end
|
|
@@ -8,7 +8,7 @@ describe "exist matcher" do
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
context "when the object does not respond to #exist? or #exists?" do
|
|
11
|
-
subject {
|
|
11
|
+
subject { double }
|
|
12
12
|
|
|
13
13
|
[:to, :not_to].each do |expect_method|
|
|
14
14
|
describe "expect(...).#{expect_method} exist" do
|
|
@@ -25,12 +25,12 @@ describe "exist matcher" do
|
|
|
25
25
|
context "when the object responds to ##{predicate}" do
|
|
26
26
|
describe "expect(...).to exist" do
|
|
27
27
|
it "passes if #{predicate}" do
|
|
28
|
-
expect(
|
|
28
|
+
expect(double(predicate => true)).to exist
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
it "fails if not #{predicate}" do
|
|
32
32
|
expect {
|
|
33
|
-
expect(
|
|
33
|
+
expect(double(predicate => false)).to exist
|
|
34
34
|
}.to fail_with(/expected .* to exist/)
|
|
35
35
|
end
|
|
36
36
|
|
|
@@ -51,12 +51,12 @@ describe "exist matcher" do
|
|
|
51
51
|
|
|
52
52
|
describe "expect(...).not_to exist" do
|
|
53
53
|
it "passes if not #{predicate}" do
|
|
54
|
-
expect(
|
|
54
|
+
expect(double(predicate => false)).not_to exist
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
it "fails if #{predicate}" do
|
|
58
58
|
expect {
|
|
59
|
-
expect(
|
|
59
|
+
expect(double(predicate => true)).not_to exist
|
|
60
60
|
}.to fail_with(/expected .* not to exist/)
|
|
61
61
|
end
|
|
62
62
|
end
|
|
@@ -65,7 +65,7 @@ describe "exist matcher" do
|
|
|
65
65
|
|
|
66
66
|
context "when the object responds to #exist? and #exists?" do
|
|
67
67
|
context "when they both return falsey values" do
|
|
68
|
-
subject {
|
|
68
|
+
subject { double(:exist? => false, :exists? => nil) }
|
|
69
69
|
|
|
70
70
|
describe "expect(...).not_to exist" do
|
|
71
71
|
it "passes" do
|
|
@@ -83,7 +83,7 @@ describe "exist matcher" do
|
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
context "when they both return truthy values" do
|
|
86
|
-
subject {
|
|
86
|
+
subject { double(:exist? => true, :exists? => "something true") }
|
|
87
87
|
|
|
88
88
|
describe "expect(...).not_to exist" do
|
|
89
89
|
it "fails" do
|
|
@@ -101,7 +101,7 @@ describe "exist matcher" do
|
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
context "when they return values with different truthiness" do
|
|
104
|
-
subject {
|
|
104
|
+
subject { double(:exist? => true, :exists? => false) }
|
|
105
105
|
|
|
106
106
|
[:to, :not_to].each do |expect_method|
|
|
107
107
|
describe "expect(...).#{expect_method} exist" do
|
|
@@ -116,7 +116,7 @@ describe "exist matcher" do
|
|
|
116
116
|
end
|
|
117
117
|
|
|
118
118
|
it 'passes any provided arguments to the call to #exist?' do
|
|
119
|
-
object =
|
|
119
|
+
object = double
|
|
120
120
|
object.should_receive(:exist?).with(:foo, :bar) { true }
|
|
121
121
|
|
|
122
122
|
expect(object).to exist(:foo, :bar)
|
|
@@ -326,13 +326,13 @@ EOF
|
|
|
326
326
|
|
|
327
327
|
describe "have(n).items(args, block)" do
|
|
328
328
|
it "passes args to target" do
|
|
329
|
-
target =
|
|
329
|
+
target = double("target")
|
|
330
330
|
target.should_receive(:items).with("arg1","arg2").and_return([1,2,3])
|
|
331
331
|
expect(target).to have(3).items("arg1","arg2")
|
|
332
332
|
end
|
|
333
333
|
|
|
334
334
|
it "passes block to target" do
|
|
335
|
-
target =
|
|
335
|
+
target = double("target")
|
|
336
336
|
block = lambda { 5 }
|
|
337
337
|
target.should_receive(:items).with("arg1","arg2", block).and_return([1,2,3])
|
|
338
338
|
expect(target).to have(3).items("arg1","arg2", block)
|
|
@@ -402,6 +402,16 @@ EOF
|
|
|
402
402
|
end
|
|
403
403
|
end
|
|
404
404
|
|
|
405
|
+
if RUBY_VERSION >= '2.0'
|
|
406
|
+
describe RSpec::Matchers::BuiltIn::Have, "for an Enumerator whose size is nil but count is supplied" do
|
|
407
|
+
let(:enumerator) { %w[a b c d].to_enum(:each) }
|
|
408
|
+
|
|
409
|
+
it 'works fine' do
|
|
410
|
+
expect(enumerator).to have(4).items
|
|
411
|
+
end
|
|
412
|
+
end
|
|
413
|
+
end
|
|
414
|
+
|
|
405
415
|
describe RSpec::Matchers::BuiltIn::Have do
|
|
406
416
|
it "has method_missing as private" do
|
|
407
417
|
expect(described_class.private_instance_methods).to include_method(:method_missing)
|
|
@@ -22,8 +22,8 @@ module RSpec
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
it "works with be_[some predicate]" do
|
|
25
|
-
expect([
|
|
26
|
-
expect([
|
|
25
|
+
expect([double("actual", :happy? => true)]).to include( be_happy )
|
|
26
|
+
expect([double("actual", :happy? => false)]).not_to include( be_happy )
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
end
|
|
@@ -137,7 +137,7 @@ describe "#include matcher" do
|
|
|
137
137
|
end
|
|
138
138
|
end
|
|
139
139
|
|
|
140
|
-
describe "expect(...).
|
|
140
|
+
describe "expect(...).not_to include(expected)" do
|
|
141
141
|
context "for a string target" do
|
|
142
142
|
it "passes if target does not include expected" do
|
|
143
143
|
expect("abc").not_to include("d")
|
|
@@ -188,7 +188,7 @@ describe "#include matcher" do
|
|
|
188
188
|
|
|
189
189
|
end
|
|
190
190
|
|
|
191
|
-
describe "expect(...).
|
|
191
|
+
describe "expect(...).not_to include(with, multiple, args)" do
|
|
192
192
|
context "for a string target" do
|
|
193
193
|
it "passes if the target does not include any of the expected" do
|
|
194
194
|
expect("abc").not_to include("d", "e", "f")
|
|
@@ -280,7 +280,7 @@ describe "#include matcher" do
|
|
|
280
280
|
end
|
|
281
281
|
end
|
|
282
282
|
|
|
283
|
-
describe "expect(...).
|
|
283
|
+
describe "expect(...).not_to include(:key => value)" do
|
|
284
284
|
context 'for a hash target' do
|
|
285
285
|
it "fails if target includes the key/value pair" do
|
|
286
286
|
expect {
|
|
@@ -364,7 +364,7 @@ describe "#include matcher" do
|
|
|
364
364
|
end
|
|
365
365
|
end
|
|
366
366
|
|
|
367
|
-
describe "expect(...).
|
|
367
|
+
describe "expect(...).not_to include(:key1 => value1, :key2 => value2)" do
|
|
368
368
|
context 'for a hash target' do
|
|
369
369
|
it "fails if target includes the key/value pairs" do
|
|
370
370
|
expect {
|
|
@@ -156,7 +156,7 @@ MESSAGE
|
|
|
156
156
|
end
|
|
157
157
|
end
|
|
158
158
|
|
|
159
|
-
describe "expect(...).
|
|
159
|
+
describe "expect(...).not_to match_array [:with, :multiple, :args]" do
|
|
160
160
|
it "is not supported" do
|
|
161
161
|
expect {
|
|
162
162
|
expect([1,2,3]).not_to match_array [1,2,3]
|
|
@@ -32,7 +32,7 @@ describe "expect(...).to match(expected)" do
|
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
describe "expect(...).
|
|
35
|
+
describe "expect(...).not_to match(expected)" do
|
|
36
36
|
it "passes when target (String) matches does not match (Regexp)" do
|
|
37
37
|
expect("string").not_to match(/rings/)
|
|
38
38
|
end
|