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
|
@@ -3,9 +3,9 @@ require 'spec_helper'
|
|
|
3
3
|
describe Object, "#should" do
|
|
4
4
|
before(:each) do
|
|
5
5
|
@target = "target"
|
|
6
|
-
@matcher =
|
|
7
|
-
@matcher.stub
|
|
8
|
-
@matcher.stub
|
|
6
|
+
@matcher = double("matcher")
|
|
7
|
+
@matcher.stub(:matches?).and_return(true)
|
|
8
|
+
@matcher.stub(:failure_message_for_should)
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
it "accepts and interacts with a matcher" do
|
|
@@ -47,12 +47,12 @@ end
|
|
|
47
47
|
describe Object, "#should_not" do
|
|
48
48
|
before(:each) do
|
|
49
49
|
@target = "target"
|
|
50
|
-
@matcher =
|
|
50
|
+
@matcher = double("matcher")
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
it "accepts and interacts with a matcher" do
|
|
54
54
|
@matcher.should_receive(:matches?).with(@target).and_return(false)
|
|
55
|
-
@matcher.stub
|
|
55
|
+
@matcher.stub(:failure_message_for_should_not)
|
|
56
56
|
|
|
57
57
|
expect(@target).not_to @matcher
|
|
58
58
|
end
|
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
require 'spec_helper'
|
|
3
3
|
|
|
4
|
+
|
|
5
|
+
describe RSpec::Expectations, "#fail_with with diff of arrays" do
|
|
6
|
+
before { RSpec::Matchers.configuration.stub(:color? => false) }
|
|
7
|
+
|
|
8
|
+
it "splits items with newlines" do
|
|
9
|
+
expected_diff = "\nDiff:\n@@ -1 +1,3 @@\n+a\\nb\n+c\\nd\n"
|
|
10
|
+
expect {
|
|
11
|
+
RSpec::Expectations.fail_with("", [], ["a\nb", "c\nd"])
|
|
12
|
+
}.to fail_with(expected_diff)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "shows inner arrays on a single line" do
|
|
16
|
+
expected_diff = "\nDiff:\n@@ -1 +1,3 @@\n+a\\nb\n+[\"c\\nd\"]\n"
|
|
17
|
+
expect {
|
|
18
|
+
RSpec::Expectations.fail_with("", [], ["a\nb", ["c\nd"]])
|
|
19
|
+
}.to fail_with(expected_diff)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
4
23
|
describe RSpec::Expectations, "#fail_with with diff" do
|
|
5
24
|
let(:differ) { double("differ") }
|
|
6
25
|
|
|
@@ -49,21 +49,21 @@ module RSpec
|
|
|
49
49
|
describe PositiveExpectationHandler do
|
|
50
50
|
describe "#handle_matcher" do
|
|
51
51
|
it "asks the matcher if it matches" do
|
|
52
|
-
matcher =
|
|
52
|
+
matcher = double("matcher")
|
|
53
53
|
actual = Object.new
|
|
54
54
|
matcher.should_receive(:matches?).with(actual).and_return(true)
|
|
55
55
|
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
it "returns the match value" do
|
|
59
|
-
matcher =
|
|
59
|
+
matcher = double("matcher")
|
|
60
60
|
actual = Object.new
|
|
61
61
|
matcher.should_receive(:matches?).with(actual).and_return(:this_value)
|
|
62
62
|
expect(RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)).to eq :this_value
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
it "calls failure_message_for_should if the matcher implements it" do
|
|
66
|
-
matcher =
|
|
66
|
+
matcher = double("matcher", :failure_message_for_should => "message", :matches? => false)
|
|
67
67
|
actual = Object.new
|
|
68
68
|
|
|
69
69
|
::RSpec::Expectations.should_receive(:fail_with).with("message")
|
|
@@ -72,7 +72,7 @@ module RSpec
|
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
it "calls fail if matcher.diffable?" do
|
|
75
|
-
matcher =
|
|
75
|
+
matcher = double("matcher",
|
|
76
76
|
:diffable? => true,
|
|
77
77
|
:failure_message_for_should => "message",
|
|
78
78
|
:matches? => false,
|
|
@@ -87,7 +87,7 @@ module RSpec
|
|
|
87
87
|
end
|
|
88
88
|
|
|
89
89
|
it "calls failure_message if the matcher does not implement failure_message_for_should" do
|
|
90
|
-
matcher =
|
|
90
|
+
matcher = double("matcher", :failure_message => "message", :matches? => false)
|
|
91
91
|
actual = Object.new
|
|
92
92
|
|
|
93
93
|
::RSpec::Expectations.should_receive(:fail_with).with("message")
|
|
@@ -96,45 +96,56 @@ module RSpec
|
|
|
96
96
|
|
|
97
97
|
end
|
|
98
98
|
|
|
99
|
-
it "
|
|
100
|
-
matcher =
|
|
99
|
+
it "uses the custom failure message when one is provided" do
|
|
100
|
+
matcher = double("matcher", :failure_message_for_should => "message", :matches? => false)
|
|
101
101
|
actual = Object.new
|
|
102
102
|
|
|
103
103
|
::RSpec::Expectations.should_receive(:fail_with).with("custom")
|
|
104
104
|
|
|
105
105
|
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher, "custom")
|
|
106
106
|
end
|
|
107
|
+
|
|
108
|
+
it "uses the custom failure message when one is provided as a callable object" do
|
|
109
|
+
matcher = double("matcher", :failure_message_for_should => "message", :matches? => false)
|
|
110
|
+
actual = Object.new
|
|
111
|
+
|
|
112
|
+
failure_message = double("failure message", :call => "custom")
|
|
113
|
+
|
|
114
|
+
::RSpec::Expectations.should_receive(:fail_with).with("custom")
|
|
115
|
+
|
|
116
|
+
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher, failure_message)
|
|
117
|
+
end
|
|
107
118
|
end
|
|
108
119
|
end
|
|
109
120
|
|
|
110
121
|
describe NegativeExpectationHandler do
|
|
111
122
|
describe "#handle_matcher" do
|
|
112
123
|
it "asks the matcher if it doesn't match when the matcher responds to #does_not_match?" do
|
|
113
|
-
matcher =
|
|
124
|
+
matcher = double("matcher", :does_not_match? => true, :negative_failure_message => nil)
|
|
114
125
|
actual = Object.new
|
|
115
126
|
matcher.should_receive(:does_not_match?).with(actual).and_return(true)
|
|
116
127
|
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
|
|
117
128
|
end
|
|
118
129
|
|
|
119
130
|
it "asks the matcher if it matches when the matcher doesn't respond to #does_not_match?" do
|
|
120
|
-
matcher =
|
|
131
|
+
matcher = double("matcher")
|
|
121
132
|
actual = Object.new
|
|
122
|
-
matcher.stub
|
|
133
|
+
matcher.stub(:negative_failure_message)
|
|
123
134
|
matcher.should_receive(:matches?).with(actual).and_return(false)
|
|
124
135
|
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
|
|
125
136
|
end
|
|
126
137
|
|
|
127
138
|
it "returns the match value" do
|
|
128
|
-
matcher =
|
|
139
|
+
matcher = double("matcher")
|
|
129
140
|
actual = Object.new
|
|
130
141
|
matcher.should_receive(:matches?).with(actual).and_return(false)
|
|
131
|
-
matcher.stub
|
|
142
|
+
matcher.stub(:negative_failure_message).and_return("ignore")
|
|
132
143
|
expect(RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)).to be_false
|
|
133
144
|
end
|
|
134
145
|
|
|
135
146
|
|
|
136
147
|
it "calls failure_message_for_should_not if the matcher implements it" do
|
|
137
|
-
matcher =
|
|
148
|
+
matcher = double("matcher", :failure_message_for_should_not => "message", :matches? => true)
|
|
138
149
|
actual = Object.new
|
|
139
150
|
|
|
140
151
|
::RSpec::Expectations.should_receive(:fail_with).with("message")
|
|
@@ -144,7 +155,7 @@ module RSpec
|
|
|
144
155
|
end
|
|
145
156
|
|
|
146
157
|
it "calls negative_failure_message if the matcher does not implement failure_message_for_should_not" do
|
|
147
|
-
matcher =
|
|
158
|
+
matcher = double("matcher", :negative_failure_message => "message", :matches? => true)
|
|
148
159
|
actual = Object.new
|
|
149
160
|
|
|
150
161
|
::RSpec::Expectations.should_receive(:fail_with).with("message")
|
|
@@ -155,7 +166,7 @@ module RSpec
|
|
|
155
166
|
|
|
156
167
|
|
|
157
168
|
it "calls fail if matcher.diffable?" do
|
|
158
|
-
matcher =
|
|
169
|
+
matcher = double("matcher",
|
|
159
170
|
:diffable? => true,
|
|
160
171
|
:failure_message_for_should_not => "message",
|
|
161
172
|
:matches? => true,
|
|
@@ -169,8 +180,8 @@ module RSpec
|
|
|
169
180
|
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
|
|
170
181
|
end
|
|
171
182
|
|
|
172
|
-
it "
|
|
173
|
-
matcher =
|
|
183
|
+
it "uses the custom failure message when one is provided" do
|
|
184
|
+
matcher = double("matcher", :failure_message_for_should_not => "message", :matches? => true)
|
|
174
185
|
actual = Object.new
|
|
175
186
|
|
|
176
187
|
::RSpec::Expectations.should_receive(:fail_with).with("custom")
|
|
@@ -178,6 +189,16 @@ module RSpec
|
|
|
178
189
|
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher, "custom")
|
|
179
190
|
end
|
|
180
191
|
|
|
192
|
+
it "uses the custom failure message when one is provided as a callable object" do
|
|
193
|
+
matcher = double("matcher", :failure_message_for_should_not => "message", :matches? => true)
|
|
194
|
+
actual = Object.new
|
|
195
|
+
|
|
196
|
+
failure_message = double("failure message", :call => "custom")
|
|
197
|
+
|
|
198
|
+
::RSpec::Expectations.should_receive(:fail_with).with("custom")
|
|
199
|
+
|
|
200
|
+
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher, failure_message)
|
|
201
|
+
end
|
|
181
202
|
end
|
|
182
203
|
end
|
|
183
204
|
|
|
@@ -189,10 +210,10 @@ module RSpec
|
|
|
189
210
|
expect(5).to arbitrary_matcher(:expected => "wrong").with(5)
|
|
190
211
|
expect { expect(5).to arbitrary_matcher(:expected => 4) }.to fail_with("expected 4, got 5")
|
|
191
212
|
expect { expect(5).to arbitrary_matcher(:expected => 5).with(4) }.to fail_with("expected 4, got 5")
|
|
192
|
-
expect(5).
|
|
193
|
-
expect(5).
|
|
194
|
-
expect { expect(5).
|
|
195
|
-
expect { expect(5).
|
|
213
|
+
expect(5).not_to arbitrary_matcher(:expected => 4)
|
|
214
|
+
expect(5).not_to arbitrary_matcher(:expected => 5).with(4)
|
|
215
|
+
expect { expect(5).not_to arbitrary_matcher(:expected => 5) }.to fail_with("expected not 5, got 5")
|
|
216
|
+
expect { expect(5).not_to arbitrary_matcher(:expected => 4).with(5) }.to fail_with("expected not 5, got 5")
|
|
196
217
|
end
|
|
197
218
|
|
|
198
219
|
it "handles the submitted block" do
|
|
@@ -6,9 +6,21 @@ module RSpec
|
|
|
6
6
|
context "when passing a message to an expectation" do
|
|
7
7
|
let(:warner) { ::Kernel }
|
|
8
8
|
|
|
9
|
+
let(:string_like_object) do
|
|
10
|
+
Struct.new(:to_str, :to_s).new(*(["Ceci n'est pas une Chaine."]*2))
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
let(:insufficiently_string_like_object) do
|
|
14
|
+
Struct.new(:to_s).new("Ceci n'est pas une Chaine.")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
let(:callable_object) do
|
|
18
|
+
Struct.new(:call).new("Ceci n'est pas une Chaine.")
|
|
19
|
+
end
|
|
20
|
+
|
|
9
21
|
describe "expect(...).to" do
|
|
10
22
|
it "prints a warning when the message object isn't a String" do
|
|
11
|
-
warner.should_receive(:warn).with
|
|
23
|
+
warner.should_receive(:warn).with(/ignoring.*message/)
|
|
12
24
|
expect(3).to eq(3), :not_a_string
|
|
13
25
|
end
|
|
14
26
|
|
|
@@ -16,11 +28,26 @@ module RSpec
|
|
|
16
28
|
warner.should_not_receive(:warn)
|
|
17
29
|
expect(3).to eq(3), "a string"
|
|
18
30
|
end
|
|
31
|
+
|
|
32
|
+
it "doesn't print a warning when message responds to to_str" do
|
|
33
|
+
warner.should_not_receive(:warn)
|
|
34
|
+
expect(3).to eq(3), string_like_object
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "prints a warning when the message object handles to_s but not to_str" do
|
|
38
|
+
warner.should_receive(:warn).with(/ignoring.*message/)
|
|
39
|
+
expect(3).to eq(3), insufficiently_string_like_object
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "doesn't print a warning when message responds to call" do
|
|
43
|
+
warner.should_not_receive(:warn)
|
|
44
|
+
expect(3).to eq(3), callable_object
|
|
45
|
+
end
|
|
19
46
|
end
|
|
20
47
|
|
|
21
|
-
describe "expect(...).
|
|
48
|
+
describe "expect(...).not_to" do
|
|
22
49
|
it "prints a warning when the message object isn't a String" do
|
|
23
|
-
warner.should_receive(:warn).with
|
|
50
|
+
warner.should_receive(:warn).with(/ignoring.*message/)
|
|
24
51
|
expect(3).not_to eq(4), :not_a_string
|
|
25
52
|
end
|
|
26
53
|
|
|
@@ -28,6 +55,21 @@ module RSpec
|
|
|
28
55
|
warner.should_not_receive(:warn)
|
|
29
56
|
expect(3).not_to eq(4), "a string"
|
|
30
57
|
end
|
|
58
|
+
|
|
59
|
+
it "doesn't print a warning when message responds to to_str" do
|
|
60
|
+
warner.should_not_receive(:warn)
|
|
61
|
+
expect(3).not_to eq(4), string_like_object
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "prints a warning when the message object handles to_s but not to_str" do
|
|
65
|
+
warner.should_receive(:warn).with(/ignoring.*message/)
|
|
66
|
+
expect(3).not_to eq(4), insufficiently_string_like_object
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "doesn't print a warning when message responds to call" do
|
|
70
|
+
warner.should_not_receive(:warn)
|
|
71
|
+
expect(3).not_to eq(4), callable_object
|
|
72
|
+
end
|
|
31
73
|
end
|
|
32
74
|
end
|
|
33
75
|
|
|
@@ -4,17 +4,17 @@ module RSpec
|
|
|
4
4
|
module Matchers
|
|
5
5
|
describe "expect(actual).to be_close(expected, delta)" do
|
|
6
6
|
before(:each) do
|
|
7
|
-
RSpec.
|
|
7
|
+
allow(RSpec).to receive(:deprecate)
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
it "
|
|
11
|
-
|
|
12
|
-
be_within_matcher.should_receive(:of).with(3.0)
|
|
10
|
+
it "is deprecated" do
|
|
11
|
+
expect(RSpec).to receive(:deprecate).with(/be_close.*/, :replacement => "be_within(0.5).of(3.0)")
|
|
13
12
|
be_close(3.0, 0.5)
|
|
14
13
|
end
|
|
15
14
|
|
|
16
|
-
it "
|
|
17
|
-
|
|
15
|
+
it "delegates to be_within(delta).of(expected)" do
|
|
16
|
+
should_receive(:be_within).with(0.5).and_return( be_within_matcher = double )
|
|
17
|
+
be_within_matcher.should_receive(:of).with(3.0)
|
|
18
18
|
be_close(3.0, 0.5)
|
|
19
19
|
end
|
|
20
20
|
end
|
|
@@ -2,24 +2,24 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe "expect(...).to be_predicate" do
|
|
4
4
|
it "passes when actual returns true for :predicate?" do
|
|
5
|
-
actual =
|
|
5
|
+
actual = double("actual", :happy? => true)
|
|
6
6
|
expect(actual).to be_happy
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
it "passes when actual returns true for :predicates? (present tense)" do
|
|
10
|
-
actual =
|
|
10
|
+
actual = double("actual", :exists? => true, :exist? => true)
|
|
11
11
|
expect(actual).to be_exist
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
it "fails when actual returns false for :predicate?" do
|
|
15
|
-
actual =
|
|
15
|
+
actual = double("actual", :happy? => false)
|
|
16
16
|
expect {
|
|
17
17
|
expect(actual).to be_happy
|
|
18
18
|
}.to fail_with("expected happy? to return true, got false")
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
it "fails when actual returns false for :predicate?" do
|
|
22
|
-
actual =
|
|
22
|
+
actual = double("actual", :happy? => nil)
|
|
23
23
|
expect {
|
|
24
24
|
expect(actual).to be_happy
|
|
25
25
|
}.to fail_with("expected happy? to return true, got nil")
|
|
@@ -32,7 +32,7 @@ describe "expect(...).to be_predicate" do
|
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
it "fails on error other than NameError" do
|
|
35
|
-
actual =
|
|
35
|
+
actual = double("actual")
|
|
36
36
|
actual.should_receive(:foo?).and_raise("aaaah")
|
|
37
37
|
expect {
|
|
38
38
|
expect(actual).to be_foo
|
|
@@ -50,17 +50,17 @@ end
|
|
|
50
50
|
|
|
51
51
|
describe "expect(...).not_to be_predicate" do
|
|
52
52
|
it "passes when actual returns false for :sym?" do
|
|
53
|
-
actual =
|
|
53
|
+
actual = double("actual", :happy? => false)
|
|
54
54
|
expect(actual).not_to be_happy
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
it "passes when actual returns nil for :sym?" do
|
|
58
|
-
actual =
|
|
58
|
+
actual = double("actual", :happy? => nil)
|
|
59
59
|
expect(actual).not_to be_happy
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
it "fails when actual returns true for :sym?" do
|
|
63
|
-
actual =
|
|
63
|
+
actual = double("actual", :happy? => true)
|
|
64
64
|
expect {
|
|
65
65
|
expect(actual).not_to be_happy
|
|
66
66
|
}.to fail_with("expected happy? to return false, got true")
|
|
@@ -75,13 +75,13 @@ end
|
|
|
75
75
|
|
|
76
76
|
describe "expect(...).to be_predicate(*args)" do
|
|
77
77
|
it "passes when actual returns true for :predicate?(*args)" do
|
|
78
|
-
actual =
|
|
78
|
+
actual = double("actual")
|
|
79
79
|
actual.should_receive(:older_than?).with(3).and_return(true)
|
|
80
80
|
expect(actual).to be_older_than(3)
|
|
81
81
|
end
|
|
82
82
|
|
|
83
83
|
it "fails when actual returns false for :predicate?(*args)" do
|
|
84
|
-
actual =
|
|
84
|
+
actual = double("actual")
|
|
85
85
|
actual.should_receive(:older_than?).with(3).and_return(false)
|
|
86
86
|
expect {
|
|
87
87
|
expect(actual).to be_older_than(3)
|
|
@@ -97,13 +97,13 @@ end
|
|
|
97
97
|
|
|
98
98
|
describe "expect(...).not_to be_predicate(*args)" do
|
|
99
99
|
it "passes when actual returns false for :predicate?(*args)" do
|
|
100
|
-
actual =
|
|
100
|
+
actual = double("actual")
|
|
101
101
|
actual.should_receive(:older_than?).with(3).and_return(false)
|
|
102
102
|
expect(actual).not_to be_older_than(3)
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
it "fails when actual returns true for :predicate?(*args)" do
|
|
106
|
-
actual =
|
|
106
|
+
actual = double("actual")
|
|
107
107
|
actual.should_receive(:older_than?).with(3).and_return(true)
|
|
108
108
|
expect {
|
|
109
109
|
expect(actual).not_to be_older_than(3)
|
|
@@ -119,16 +119,16 @@ end
|
|
|
119
119
|
|
|
120
120
|
describe "expect(...).to be_predicate(&block)" do
|
|
121
121
|
it "passes when actual returns true for :predicate?(&block)" do
|
|
122
|
-
actual =
|
|
123
|
-
delegate =
|
|
122
|
+
actual = double("actual")
|
|
123
|
+
delegate = double("delegate")
|
|
124
124
|
actual.should_receive(:happy?).and_yield
|
|
125
125
|
delegate.should_receive(:check_happy).and_return(true)
|
|
126
126
|
expect(actual).to be_happy { delegate.check_happy }
|
|
127
127
|
end
|
|
128
128
|
|
|
129
129
|
it "fails when actual returns false for :predicate?(&block)" do
|
|
130
|
-
actual =
|
|
131
|
-
delegate =
|
|
130
|
+
actual = double("actual")
|
|
131
|
+
delegate = double("delegate")
|
|
132
132
|
actual.should_receive(:happy?).and_yield
|
|
133
133
|
delegate.should_receive(:check_happy).and_return(false)
|
|
134
134
|
expect {
|
|
@@ -137,7 +137,7 @@ describe "expect(...).to be_predicate(&block)" do
|
|
|
137
137
|
end
|
|
138
138
|
|
|
139
139
|
it "fails when actual does not respond to :predicate?" do
|
|
140
|
-
delegate =
|
|
140
|
+
delegate = double("delegate", :check_happy => true)
|
|
141
141
|
expect {
|
|
142
142
|
expect(Object.new).to be_happy { delegate.check_happy }
|
|
143
143
|
}.to raise_error(NameError)
|
|
@@ -146,16 +146,16 @@ end
|
|
|
146
146
|
|
|
147
147
|
describe "expect(...).not_to be_predicate(&block)" do
|
|
148
148
|
it "passes when actual returns false for :predicate?(&block)" do
|
|
149
|
-
actual =
|
|
150
|
-
delegate =
|
|
149
|
+
actual = double("actual")
|
|
150
|
+
delegate = double("delegate")
|
|
151
151
|
actual.should_receive(:happy?).and_yield
|
|
152
152
|
delegate.should_receive(:check_happy).and_return(false)
|
|
153
153
|
expect(actual).not_to be_happy { delegate.check_happy }
|
|
154
154
|
end
|
|
155
155
|
|
|
156
156
|
it "fails when actual returns true for :predicate?(&block)" do
|
|
157
|
-
actual =
|
|
158
|
-
delegate =
|
|
157
|
+
actual = double("actual")
|
|
158
|
+
delegate = double("delegate")
|
|
159
159
|
actual.should_receive(:happy?).and_yield
|
|
160
160
|
delegate.should_receive(:check_happy).and_return(true)
|
|
161
161
|
expect {
|
|
@@ -164,7 +164,7 @@ describe "expect(...).not_to be_predicate(&block)" do
|
|
|
164
164
|
end
|
|
165
165
|
|
|
166
166
|
it "fails when actual does not respond to :predicate?" do
|
|
167
|
-
delegate =
|
|
167
|
+
delegate = double("delegate", :check_happy => true)
|
|
168
168
|
expect {
|
|
169
169
|
expect(Object.new).not_to be_happy { delegate.check_happy }
|
|
170
170
|
}.to raise_error(NameError)
|
|
@@ -173,16 +173,16 @@ end
|
|
|
173
173
|
|
|
174
174
|
describe "expect(...).to be_predicate(*args, &block)" do
|
|
175
175
|
it "passes when actual returns true for :predicate?(*args, &block)" do
|
|
176
|
-
actual =
|
|
177
|
-
delegate =
|
|
176
|
+
actual = double("actual")
|
|
177
|
+
delegate = double("delegate")
|
|
178
178
|
actual.should_receive(:older_than?).with(3).and_yield(3)
|
|
179
179
|
delegate.should_receive(:check_older_than).with(3).and_return(true)
|
|
180
180
|
expect(actual).to be_older_than(3) { |age| delegate.check_older_than(age) }
|
|
181
181
|
end
|
|
182
182
|
|
|
183
183
|
it "fails when actual returns false for :predicate?(*args, &block)" do
|
|
184
|
-
actual =
|
|
185
|
-
delegate =
|
|
184
|
+
actual = double("actual")
|
|
185
|
+
delegate = double("delegate")
|
|
186
186
|
actual.should_receive(:older_than?).with(3).and_yield(3)
|
|
187
187
|
delegate.should_receive(:check_older_than).with(3).and_return(false)
|
|
188
188
|
expect {
|
|
@@ -191,7 +191,7 @@ describe "expect(...).to be_predicate(*args, &block)" do
|
|
|
191
191
|
end
|
|
192
192
|
|
|
193
193
|
it "fails when actual does not respond to :predicate?" do
|
|
194
|
-
delegate =
|
|
194
|
+
delegate = double("delegate", :check_older_than => true)
|
|
195
195
|
expect {
|
|
196
196
|
expect(Object.new).to be_older_than(3) { |age| delegate.check_older_than(age) }
|
|
197
197
|
}.to raise_error(NameError)
|
|
@@ -200,16 +200,16 @@ end
|
|
|
200
200
|
|
|
201
201
|
describe "expect(...).not_to be_predicate(*args, &block)" do
|
|
202
202
|
it "passes when actual returns false for :predicate?(*args, &block)" do
|
|
203
|
-
actual =
|
|
204
|
-
delegate =
|
|
203
|
+
actual = double("actual")
|
|
204
|
+
delegate = double("delegate")
|
|
205
205
|
actual.should_receive(:older_than?).with(3).and_yield(3)
|
|
206
206
|
delegate.should_receive(:check_older_than).with(3).and_return(false)
|
|
207
207
|
expect(actual).not_to be_older_than(3) { |age| delegate.check_older_than(age) }
|
|
208
208
|
end
|
|
209
209
|
|
|
210
210
|
it "fails when actual returns true for :predicate?(*args, &block)" do
|
|
211
|
-
actual =
|
|
212
|
-
delegate =
|
|
211
|
+
actual = double("actual")
|
|
212
|
+
delegate = double("delegate")
|
|
213
213
|
actual.should_receive(:older_than?).with(3).and_yield(3)
|
|
214
214
|
delegate.should_receive(:check_older_than).with(3).and_return(true)
|
|
215
215
|
expect {
|
|
@@ -218,7 +218,7 @@ describe "expect(...).not_to be_predicate(*args, &block)" do
|
|
|
218
218
|
end
|
|
219
219
|
|
|
220
220
|
it "fails when actual does not respond to :predicate?" do
|
|
221
|
-
delegate =
|
|
221
|
+
delegate = double("delegate", :check_older_than => true)
|
|
222
222
|
expect {
|
|
223
223
|
expect(Object.new).not_to be_older_than(3) { |age| delegate.check_older_than(age) }
|
|
224
224
|
}.to raise_error(NameError)
|
|
@@ -465,10 +465,10 @@ end
|
|
|
465
465
|
|
|
466
466
|
describe "'expect(...).to be' with operator" do
|
|
467
467
|
it "includes 'be' in the description" do
|
|
468
|
-
expect((be > 6).description).to match
|
|
469
|
-
expect((be >= 6).description).to match
|
|
470
|
-
expect((be <= 6).description).to match
|
|
471
|
-
expect((be < 6).description).to match
|
|
468
|
+
expect((be > 6).description).to match(/be > 6/)
|
|
469
|
+
expect((be >= 6).description).to match(/be >= 6/)
|
|
470
|
+
expect((be <= 6).description).to match(/be <= 6/)
|
|
471
|
+
expect((be < 6).description).to match(/be < 6/)
|
|
472
472
|
end
|
|
473
473
|
end
|
|
474
474
|
|
|
@@ -27,6 +27,14 @@ module RSpec
|
|
|
27
27
|
expect(5.5).to be_within(0.5).of(5.0)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
+
it "passes with integer arguments that are near each other" do
|
|
31
|
+
expect(1.0001).to be_within(5).percent_of(1)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "passes with negative arguments" do
|
|
35
|
+
expect(-1.0001).to be_within(5).percent_of(-1)
|
|
36
|
+
end
|
|
37
|
+
|
|
30
38
|
it "fails when actual < (expected - delta)" do
|
|
31
39
|
expect {
|
|
32
40
|
expect(4.49).to be_within(0.5).of(5.0)
|
|
@@ -72,6 +72,17 @@ describe "expect { ... }.to change(actual, message)" do
|
|
|
72
72
|
expect {@instance.some_value << 1}.to change(@instance, :some_value)
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
+
it "fails when a predicate on the actual fails" do
|
|
76
|
+
expect do
|
|
77
|
+
expect {@instance.some_value << 1}.to change { @instance.some_value }.to be_empty
|
|
78
|
+
end.to fail_with(/result should have been changed to/)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "passes when a predicate on the actual passes" do
|
|
82
|
+
@instance.some_value = [1]
|
|
83
|
+
expect {@instance.some_value.pop}.to change { @instance.some_value }.to be_empty
|
|
84
|
+
end
|
|
85
|
+
|
|
75
86
|
it "fails when actual is not modified by the block" do
|
|
76
87
|
expect do
|
|
77
88
|
expect {}.to change(@instance, :some_value)
|
|
@@ -156,12 +167,12 @@ describe "expect { ... }.not_to change(actual, message)" do
|
|
|
156
167
|
end
|
|
157
168
|
|
|
158
169
|
it "passes when actual is not modified by the block" do
|
|
159
|
-
expect { }.
|
|
170
|
+
expect { }.not_to change(@instance, :some_value)
|
|
160
171
|
end
|
|
161
172
|
|
|
162
173
|
it "fails when actual is not modified by the block" do
|
|
163
174
|
expect do
|
|
164
|
-
expect {@instance.some_value = 6}.
|
|
175
|
+
expect {@instance.some_value = 6}.not_to change(@instance, :some_value)
|
|
165
176
|
end.to fail_with("some_value should not have changed, but did change from 5 to 6")
|
|
166
177
|
end
|
|
167
178
|
end
|
|
@@ -206,18 +217,18 @@ describe "expect { ... }.not_to change { block }" do
|
|
|
206
217
|
end
|
|
207
218
|
|
|
208
219
|
it "passes when actual is modified by the block" do
|
|
209
|
-
expect {}.
|
|
220
|
+
expect {}.not_to change{ @instance.some_value }
|
|
210
221
|
end
|
|
211
222
|
|
|
212
223
|
it "fails when actual is not modified by the block" do
|
|
213
224
|
expect do
|
|
214
|
-
expect {@instance.some_value = 6}.
|
|
225
|
+
expect {@instance.some_value = 6}.not_to change { @instance.some_value }
|
|
215
226
|
end.to fail_with("result should not have changed, but did change from 5 to 6")
|
|
216
227
|
end
|
|
217
228
|
|
|
218
229
|
it "warns if passed a block using do/end instead of {}" do
|
|
219
230
|
expect do
|
|
220
|
-
expect {}.
|
|
231
|
+
expect {}.not_to change do; end
|
|
221
232
|
end.to raise_error(SyntaxError, /block passed to should or should_not/)
|
|
222
233
|
end
|
|
223
234
|
end
|
|
@@ -537,6 +548,6 @@ describe RSpec::Matchers::BuiltIn::Change do
|
|
|
537
548
|
|
|
538
549
|
expect {
|
|
539
550
|
expect { @instance.some_value = "cat" }.to change(@instance, :some_value)
|
|
540
|
-
}.
|
|
551
|
+
}.not_to raise_error
|
|
541
552
|
end
|
|
542
553
|
end
|