rspec-expectations 2.0.0.beta.22 → 2.6.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/.gitignore +1 -1
- data/.travis.yml +7 -0
- data/Gemfile +35 -13
- data/Guardfile +5 -0
- data/License.txt +1 -1
- data/README.md +43 -0
- data/Rakefile +51 -9
- data/cucumber.yml +9 -2
- data/features/.nav +29 -0
- data/features/Changelog.md +101 -0
- data/features/README.markdown +45 -8
- data/features/built_in_matchers/README.md +71 -0
- data/features/built_in_matchers/be.feature +135 -0
- data/features/built_in_matchers/be_within.feature +43 -0
- data/features/built_in_matchers/cover.feature +45 -0
- data/features/{matchers → built_in_matchers}/equality.feature +16 -13
- data/features/built_in_matchers/exist.feature +43 -0
- data/features/built_in_matchers/expect_change.feature +59 -0
- data/features/built_in_matchers/expect_error.feature +105 -0
- data/features/built_in_matchers/have.feature +103 -0
- data/features/built_in_matchers/include.feature +121 -0
- data/features/built_in_matchers/match.feature +50 -0
- data/features/built_in_matchers/operators.feature +221 -0
- data/features/built_in_matchers/predicates.feature +128 -0
- data/features/built_in_matchers/respond_to.feature +78 -0
- data/features/built_in_matchers/satisfy.feature +31 -0
- data/features/built_in_matchers/throw_symbol.feature +85 -0
- data/features/built_in_matchers/types.feature +114 -0
- data/features/{matchers → custom_matchers}/access_running_example.feature +2 -2
- data/features/{matchers → custom_matchers}/define_diffable_matcher.feature +1 -1
- data/features/{matchers → custom_matchers}/define_matcher.feature +91 -9
- data/features/{matchers → custom_matchers}/define_matcher_outside_rspec.feature +1 -1
- data/features/{matchers → custom_matchers}/define_matcher_with_fluent_interface.feature +8 -11
- data/features/customized_message.feature +22 -0
- data/features/{expectations/diffing.feature → diffing.feature} +16 -16
- data/features/{expectations/implicit_docstrings.feature → implicit_docstrings.feature} +4 -4
- data/features/step_definitions/additional_cli_steps.rb +22 -0
- data/features/support/env.rb +5 -1
- data/features/test_frameworks/test_unit.feature +46 -0
- data/lib/rspec/expectations/backward_compatibility.rb +22 -1
- data/lib/rspec/expectations/deprecation.rb +36 -0
- data/lib/rspec/expectations/extensions.rb +0 -1
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/expectations.rb +2 -1
- data/lib/rspec/matchers/be.rb +4 -4
- data/lib/rspec/matchers/be_close.rb +2 -17
- data/lib/rspec/matchers/be_within.rb +40 -0
- data/lib/rspec/matchers/block_aliases.rb +19 -0
- data/lib/rspec/matchers/change.rb +74 -49
- data/lib/rspec/matchers/cover.rb +35 -0
- data/lib/rspec/matchers/exist.rb +13 -3
- data/lib/rspec/matchers/has.rb +15 -11
- data/lib/rspec/matchers/have.rb +5 -5
- data/lib/rspec/matchers/include.rb +14 -5
- data/lib/rspec/matchers/matcher.rb +39 -13
- data/lib/rspec/matchers/method_missing.rb +6 -3
- data/lib/rspec/matchers/operator_matcher.rb +12 -3
- data/lib/rspec/matchers/respond_to.rb +23 -9
- data/lib/rspec/matchers/satisfy.rb +4 -0
- data/lib/rspec/matchers/throw_symbol.rb +43 -26
- data/lib/rspec/matchers.rb +15 -3
- data/rspec-expectations.gemspec +2 -6
- data/spec/rspec/matchers/be_close_spec.rb +11 -39
- data/spec/rspec/matchers/be_spec.rb +8 -8
- data/spec/rspec/matchers/be_within_spec.rb +64 -0
- data/spec/rspec/matchers/change_spec.rb +88 -9
- data/spec/rspec/matchers/cover_spec.rb +65 -0
- data/spec/rspec/matchers/description_generation_spec.rb +41 -25
- data/spec/rspec/matchers/exist_spec.rb +90 -51
- data/spec/rspec/matchers/has_spec.rb +2 -2
- data/spec/rspec/matchers/have_spec.rb +291 -291
- data/spec/rspec/matchers/include_spec.rb +318 -65
- data/spec/rspec/matchers/matcher_spec.rb +91 -0
- data/spec/rspec/matchers/matchers_spec.rb +29 -0
- data/spec/rspec/matchers/method_missing_spec.rb +23 -0
- data/spec/rspec/matchers/operator_matcher_spec.rb +36 -10
- data/spec/rspec/matchers/respond_to_spec.rb +177 -1
- data/spec/rspec/matchers/satisfy_spec.rb +4 -0
- data/spec/rspec/matchers/throw_symbol_spec.rb +27 -10
- data/spec/spec_helper.rb +10 -35
- data/spec/support/classes.rb +1 -1
- data/spec/support/matchers.rb +22 -0
- data/spec/support/ruby_version.rb +10 -0
- metadata +95 -114
- data/History.md +0 -16
- data/README.markdown +0 -23
- data/features/expectations/attribute_of_subject.feature +0 -19
- data/features/expectations/customized_message.feature +0 -54
- data/features/matchers/expect_change.feature +0 -65
- data/features/matchers/expect_error.feature +0 -44
- data/lib/rspec/expectations/extensions/rspec/core/example_group.rb +0 -19
- data/spec/suite.rb +0 -1
- /data/{Upgrade.markdown → features/Upgrade.md} +0 -0
|
@@ -15,12 +15,38 @@ describe "should ==" do
|
|
|
15
15
|
|
|
16
16
|
it "fails when target.==(actual) returns false" do
|
|
17
17
|
subject = "apple"
|
|
18
|
-
RSpec::Expectations.should_receive(:fail_with).with(%[expected: "orange"
|
|
18
|
+
RSpec::Expectations.should_receive(:fail_with).with(%[expected: "orange"\n got: "apple" (using ==)], "orange", "apple")
|
|
19
19
|
subject.should == "orange"
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
+
describe "unsupported operators", :if => RUBY_VERSION.to_f == 1.9 do
|
|
25
|
+
it "raises an appropriate error for should != expected" do
|
|
26
|
+
expect {
|
|
27
|
+
"apple".should != "pear"
|
|
28
|
+
}.to raise_error(/does not support `should != expected`. Use `should_not == expected`/)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "raises an appropriate error for should_not != expected" do
|
|
32
|
+
expect {
|
|
33
|
+
"apple".should_not != "pear"
|
|
34
|
+
}.to raise_error(/does not support `should_not != expected`. Use `should == expected`/)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "raises an appropriate error for should !~ expected" do
|
|
38
|
+
expect {
|
|
39
|
+
"apple".should !~ /regex/
|
|
40
|
+
}.to raise_error(/does not support `should !~ expected`. Use `should_not =~ expected`/)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "raises an appropriate error for should_not !~ expected" do
|
|
44
|
+
expect {
|
|
45
|
+
"apple".should_not !~ /regex/
|
|
46
|
+
}.to raise_error(/does not support `should_not !~ expected`. Use `should =~ expected`/)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
24
50
|
describe "should_not ==" do
|
|
25
51
|
|
|
26
52
|
it "delegates message to target" do
|
|
@@ -36,7 +62,7 @@ describe "should_not ==" do
|
|
|
36
62
|
|
|
37
63
|
it "fails when target.==(actual) returns false" do
|
|
38
64
|
subject = "apple"
|
|
39
|
-
RSpec::Expectations.should_receive(:fail_with).with(%[expected not: == "apple"
|
|
65
|
+
RSpec::Expectations.should_receive(:fail_with).with(%[expected not: == "apple"\n got: "apple"], "apple", "apple")
|
|
40
66
|
subject.should_not == "apple"
|
|
41
67
|
end
|
|
42
68
|
|
|
@@ -53,7 +79,7 @@ describe "should ===" do
|
|
|
53
79
|
it "fails when target.===(actual) returns false" do
|
|
54
80
|
subject = "apple"
|
|
55
81
|
subject.should_receive(:===).with("orange").and_return(false)
|
|
56
|
-
RSpec::Expectations.should_receive(:fail_with).with(%[expected: "orange"
|
|
82
|
+
RSpec::Expectations.should_receive(:fail_with).with(%[expected: "orange"\n got: "apple" (using ===)], "orange", "apple")
|
|
57
83
|
subject.should === "orange"
|
|
58
84
|
end
|
|
59
85
|
|
|
@@ -70,7 +96,7 @@ describe "should_not ===" do
|
|
|
70
96
|
it "fails when target.===(actual) returns false" do
|
|
71
97
|
subject = "apple"
|
|
72
98
|
subject.should_receive(:===).with("apple").and_return(true)
|
|
73
|
-
RSpec::Expectations.should_receive(:fail_with).with(%[expected not: === "apple"
|
|
99
|
+
RSpec::Expectations.should_receive(:fail_with).with(%[expected not: === "apple"\n got: "apple"], "apple", "apple")
|
|
74
100
|
subject.should_not === "apple"
|
|
75
101
|
end
|
|
76
102
|
|
|
@@ -87,7 +113,7 @@ describe "should =~" do
|
|
|
87
113
|
it "fails when target.=~(actual) returns false" do
|
|
88
114
|
subject = "fu"
|
|
89
115
|
subject.should_receive(:=~).with(/oo/).and_return(false)
|
|
90
|
-
RSpec::Expectations.should_receive(:fail_with).with(%[expected: /oo
|
|
116
|
+
RSpec::Expectations.should_receive(:fail_with).with(%[expected: /oo/\n got: "fu" (using =~)], /oo/, "fu")
|
|
91
117
|
subject.should =~ /oo/
|
|
92
118
|
end
|
|
93
119
|
|
|
@@ -104,7 +130,7 @@ describe "should_not =~" do
|
|
|
104
130
|
it "fails when target.=~(actual) returns false" do
|
|
105
131
|
subject = "foo"
|
|
106
132
|
subject.should_receive(:=~).with(/oo/).and_return(true)
|
|
107
|
-
RSpec::Expectations.should_receive(:fail_with).with(%[expected not: =~ /oo
|
|
133
|
+
RSpec::Expectations.should_receive(:fail_with).with(%[expected not: =~ /oo/\n got: "foo"], /oo/, "foo")
|
|
108
134
|
subject.should_not =~ /oo/
|
|
109
135
|
end
|
|
110
136
|
|
|
@@ -117,7 +143,7 @@ describe "should >" do
|
|
|
117
143
|
end
|
|
118
144
|
|
|
119
145
|
it "fails if > fails" do
|
|
120
|
-
RSpec::Expectations.should_receive(:fail_with).with(%[expected: > 5
|
|
146
|
+
RSpec::Expectations.should_receive(:fail_with).with(%[expected: > 5\n got: 4], 5, 4)
|
|
121
147
|
4.should > 5
|
|
122
148
|
end
|
|
123
149
|
|
|
@@ -131,7 +157,7 @@ describe "should >=" do
|
|
|
131
157
|
end
|
|
132
158
|
|
|
133
159
|
it "fails if > fails" do
|
|
134
|
-
RSpec::Expectations.should_receive(:fail_with).with(%[expected: >= 5
|
|
160
|
+
RSpec::Expectations.should_receive(:fail_with).with(%[expected: >= 5\n got: 4], 5, 4)
|
|
135
161
|
4.should >= 5
|
|
136
162
|
end
|
|
137
163
|
|
|
@@ -144,7 +170,7 @@ describe "should <" do
|
|
|
144
170
|
end
|
|
145
171
|
|
|
146
172
|
it "fails if > fails" do
|
|
147
|
-
RSpec::Expectations.should_receive(:fail_with).with(%[expected: < 3
|
|
173
|
+
RSpec::Expectations.should_receive(:fail_with).with(%[expected: < 3\n got: 4], 3, 4)
|
|
148
174
|
4.should < 3
|
|
149
175
|
end
|
|
150
176
|
|
|
@@ -158,7 +184,7 @@ describe "should <=" do
|
|
|
158
184
|
end
|
|
159
185
|
|
|
160
186
|
it "fails if > fails" do
|
|
161
|
-
RSpec::Expectations.should_receive(:fail_with).with(%[expected: <= 3
|
|
187
|
+
RSpec::Expectations.should_receive(:fail_with).with(%[expected: <= 3\n got: 4], 3, 4)
|
|
162
188
|
4.should <= 3
|
|
163
189
|
end
|
|
164
190
|
|
|
@@ -20,6 +20,18 @@ describe "should respond_to(:sym).with(1).argument" do
|
|
|
20
20
|
def obj.foo(arg); end
|
|
21
21
|
obj.should respond_to(:foo).with(1).argument
|
|
22
22
|
end
|
|
23
|
+
|
|
24
|
+
it "passes if target responds to any number of arguments" do
|
|
25
|
+
obj = Object.new
|
|
26
|
+
def obj.foo(*args); end
|
|
27
|
+
obj.should respond_to(:foo).with(1).argument
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "passes if target responds to one or more arguments" do
|
|
31
|
+
obj = Object.new
|
|
32
|
+
def obj.foo(a, *args); end
|
|
33
|
+
obj.should respond_to(:foo).with(1).argument
|
|
34
|
+
end
|
|
23
35
|
|
|
24
36
|
it "fails if target does not respond to :sym" do
|
|
25
37
|
obj = Object.new
|
|
@@ -43,6 +55,14 @@ describe "should respond_to(:sym).with(1).argument" do
|
|
|
43
55
|
obj.should respond_to(:foo).with(1).argument
|
|
44
56
|
}.should fail_with(/expected #<Object.*> to respond to :foo with 1 argument/)
|
|
45
57
|
end
|
|
58
|
+
|
|
59
|
+
it "fails if :sym expects 2 or more args" do
|
|
60
|
+
obj = Object.new
|
|
61
|
+
def obj.foo(arg, arg2, *args); end
|
|
62
|
+
lambda {
|
|
63
|
+
obj.should respond_to(:foo).with(1).argument
|
|
64
|
+
}.should fail_with(/expected #<Object.*> to respond to :foo with 1 argument/)
|
|
65
|
+
end
|
|
46
66
|
end
|
|
47
67
|
|
|
48
68
|
describe "should respond_to(message1, message2)" do
|
|
@@ -76,6 +96,24 @@ describe "should respond_to(:sym).with(2).arguments" do
|
|
|
76
96
|
def obj.foo(a1, a2); end
|
|
77
97
|
obj.should respond_to(:foo).with(2).arguments
|
|
78
98
|
end
|
|
99
|
+
|
|
100
|
+
it "passes if target responds to any number of arguments" do
|
|
101
|
+
obj = Object.new
|
|
102
|
+
def obj.foo(*args); end
|
|
103
|
+
obj.should respond_to(:foo).with(2).arguments
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
it "passes if target responds to one or more arguments" do
|
|
107
|
+
obj = Object.new
|
|
108
|
+
def obj.foo(a, *args); end
|
|
109
|
+
obj.should respond_to(:foo).with(2).arguments
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it "passes if target responds to two or more arguments" do
|
|
113
|
+
obj = Object.new
|
|
114
|
+
def obj.foo(a, b, *args); end
|
|
115
|
+
obj.should respond_to(:foo).with(2).arguments
|
|
116
|
+
end
|
|
79
117
|
|
|
80
118
|
it "fails if target does not respond to :sym" do
|
|
81
119
|
obj = Object.new
|
|
@@ -92,13 +130,21 @@ describe "should respond_to(:sym).with(2).arguments" do
|
|
|
92
130
|
}.should fail_with(/expected #<Object.*> to respond to :foo with 2 arguments/)
|
|
93
131
|
end
|
|
94
132
|
|
|
95
|
-
it "fails if :sym expects
|
|
133
|
+
it "fails if :sym expects 1 args" do
|
|
96
134
|
obj = Object.new
|
|
97
135
|
def obj.foo(arg); end
|
|
98
136
|
lambda {
|
|
99
137
|
obj.should respond_to(:foo).with(2).arguments
|
|
100
138
|
}.should fail_with(/expected #<Object.*> to respond to :foo with 2 arguments/)
|
|
101
139
|
end
|
|
140
|
+
|
|
141
|
+
it "fails if :sym expects 3 or more args" do
|
|
142
|
+
obj = Object.new
|
|
143
|
+
def obj.foo(arg, arg2, arg3, *args); end
|
|
144
|
+
lambda {
|
|
145
|
+
obj.should respond_to(:foo).with(2).arguments
|
|
146
|
+
}.should fail_with(/expected #<Object.*> to respond to :foo with 2 arguments/)
|
|
147
|
+
end
|
|
102
148
|
end
|
|
103
149
|
|
|
104
150
|
describe "should_not respond_to(:sym)" do
|
|
@@ -114,3 +160,133 @@ describe "should_not respond_to(:sym)" do
|
|
|
114
160
|
end
|
|
115
161
|
|
|
116
162
|
end
|
|
163
|
+
|
|
164
|
+
describe "should_not respond_to(:sym).with(1).argument" do
|
|
165
|
+
it "fails if target responds to :sym with 1 arg" do
|
|
166
|
+
obj = Object.new
|
|
167
|
+
def obj.foo(arg); end
|
|
168
|
+
lambda {
|
|
169
|
+
obj.should_not respond_to(:foo).with(1).argument
|
|
170
|
+
}.should fail_with(/expected #<Object:.*> not to respond to :foo with 1 argument/)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
it "fails if target responds to :sym with any number of args" do
|
|
174
|
+
obj = Object.new
|
|
175
|
+
def obj.foo(*args); end
|
|
176
|
+
lambda {
|
|
177
|
+
obj.should_not respond_to(:foo).with(1).argument
|
|
178
|
+
}.should fail_with(/expected #<Object:.*> not to respond to :foo with 1 argument/)
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
it "fails if target responds to :sym with one or more args" do
|
|
182
|
+
obj = Object.new
|
|
183
|
+
def obj.foo(a, *args); end
|
|
184
|
+
lambda {
|
|
185
|
+
obj.should_not respond_to(:foo).with(1).argument
|
|
186
|
+
}.should fail_with(/expected #<Object:.*> not to respond to :foo with 1 argument/)
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
it "passes if target does not respond to :sym" do
|
|
190
|
+
obj = Object.new
|
|
191
|
+
obj.should_not respond_to(:some_method).with(1).argument
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
it "passes if :sym expects 0 args" do
|
|
195
|
+
obj = Object.new
|
|
196
|
+
def obj.foo; end
|
|
197
|
+
obj.should_not respond_to(:foo).with(1).argument
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
it "passes if :sym expects 2 args" do
|
|
201
|
+
obj = Object.new
|
|
202
|
+
def obj.foo(arg, arg2); end
|
|
203
|
+
obj.should_not respond_to(:foo).with(1).argument
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
it "passes if :sym expects 2 or more args" do
|
|
207
|
+
obj = Object.new
|
|
208
|
+
def obj.foo(arg, arg2, *args); end
|
|
209
|
+
obj.should_not respond_to(:foo).with(1).argument
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
describe "should_not respond_to(message1, message2)" do
|
|
214
|
+
it "passes if target does not respond to either message1 or message2" do
|
|
215
|
+
Object.new.should_not respond_to(:some_method, :some_other_method)
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
it "fails if target responds to message1 but not message2" do
|
|
219
|
+
lambda {
|
|
220
|
+
Object.new.should_not respond_to(:object_id, :some_method)
|
|
221
|
+
}.should fail_with(/expected #<Object:.*> not to respond to :object_id/)
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
it "fails if target responds to message2 but not message1" do
|
|
225
|
+
lambda {
|
|
226
|
+
Object.new.should_not respond_to(:some_method, :object_id)
|
|
227
|
+
}.should fail_with(/expected #<Object:.*> not to respond to :object_id/)
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
it "fails if target responds to both message1 and message2" do
|
|
231
|
+
lambda {
|
|
232
|
+
Object.new.should_not respond_to(:class, :object_id)
|
|
233
|
+
}.should fail_with(/expected #<Object:.*> not to respond to :class, :object_id/)
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
describe "should_not respond_to(:sym).with(2).arguments" do
|
|
238
|
+
it "fails if target responds to :sym with 2 args" do
|
|
239
|
+
obj = Object.new
|
|
240
|
+
def obj.foo(a1, a2); end
|
|
241
|
+
lambda {
|
|
242
|
+
obj.should_not respond_to(:foo).with(2).arguments
|
|
243
|
+
}.should fail_with(/expected .* not to respond to :foo with 2 arguments/)
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
it "fails if target responds to :sym with any number args" do
|
|
247
|
+
obj = Object.new
|
|
248
|
+
def obj.foo(*args); end
|
|
249
|
+
lambda {
|
|
250
|
+
obj.should_not respond_to(:foo).with(2).arguments
|
|
251
|
+
}.should fail_with(/expected .* not to respond to :foo with 2 arguments/)
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
it "fails if target responds to :sym with one or more args" do
|
|
255
|
+
obj = Object.new
|
|
256
|
+
def obj.foo(a, *args); end
|
|
257
|
+
lambda {
|
|
258
|
+
obj.should_not respond_to(:foo).with(2).arguments
|
|
259
|
+
}.should fail_with(/expected .* not to respond to :foo with 2 arguments/)
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
it "fails if target responds to :sym with two or more args" do
|
|
263
|
+
obj = Object.new
|
|
264
|
+
def obj.foo(a, b, *args); end
|
|
265
|
+
lambda {
|
|
266
|
+
obj.should_not respond_to(:foo).with(2).arguments
|
|
267
|
+
}.should fail_with(/expected .* not to respond to :foo with 2 arguments/)
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
it "passes if target does not respond to :sym" do
|
|
271
|
+
obj = Object.new
|
|
272
|
+
obj.should_not respond_to(:some_method).with(2).arguments
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
it "passes if :sym expects 0 args" do
|
|
276
|
+
obj = Object.new
|
|
277
|
+
def obj.foo; end
|
|
278
|
+
obj.should_not respond_to(:foo).with(2).arguments
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
it "passes if :sym expects 2 args" do
|
|
282
|
+
obj = Object.new
|
|
283
|
+
def obj.foo(arg); end
|
|
284
|
+
obj.should_not respond_to(:foo).with(2).arguments
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
it "passes if :sym expects 3 or more args" do
|
|
288
|
+
obj = Object.new
|
|
289
|
+
def obj.foo(a, b, c, *arg); end
|
|
290
|
+
obj.should_not respond_to(:foo).with(2).arguments
|
|
291
|
+
end
|
|
292
|
+
end
|
|
@@ -17,11 +17,11 @@ module RSpec
|
|
|
17
17
|
end
|
|
18
18
|
it "provides a failure message" do
|
|
19
19
|
@matcher.matches?(lambda{})
|
|
20
|
-
@matcher.failure_message_for_should.should == "expected a Symbol
|
|
20
|
+
@matcher.failure_message_for_should.should == "expected a Symbol to be thrown, got nothing"
|
|
21
21
|
end
|
|
22
22
|
it "provides a negative failure message" do
|
|
23
23
|
@matcher.matches?(lambda{ throw :sym})
|
|
24
|
-
@matcher.failure_message_for_should_not.should == "expected no Symbol, got :sym"
|
|
24
|
+
@matcher.failure_message_for_should_not.should == "expected no Symbol to be thrown, got :sym"
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
|
|
@@ -42,18 +42,20 @@ module RSpec
|
|
|
42
42
|
end
|
|
43
43
|
it "provides a failure message when no Symbol is thrown" do
|
|
44
44
|
@matcher.matches?(lambda{})
|
|
45
|
-
@matcher.failure_message_for_should.should == "expected :sym
|
|
45
|
+
@matcher.failure_message_for_should.should == "expected :sym to be thrown, got nothing"
|
|
46
46
|
end
|
|
47
47
|
it "provides a failure message when wrong Symbol is thrown" do
|
|
48
48
|
@matcher.matches?(lambda{ throw :other_sym })
|
|
49
|
-
@matcher.failure_message_for_should.should == "expected :sym, got :other_sym"
|
|
49
|
+
@matcher.failure_message_for_should.should == "expected :sym to be thrown, got :other_sym"
|
|
50
50
|
end
|
|
51
51
|
it "provides a negative failure message" do
|
|
52
52
|
@matcher.matches?(lambda{ throw :sym })
|
|
53
|
-
@matcher.failure_message_for_should_not.should == "expected :sym not to be thrown"
|
|
53
|
+
@matcher.failure_message_for_should_not.should == "expected :sym not to be thrown, got :sym"
|
|
54
54
|
end
|
|
55
55
|
it "only matches NameErrors raised by uncaught throws" do
|
|
56
|
-
|
|
56
|
+
expect {
|
|
57
|
+
@matcher.matches?(lambda{ sym }).should be_false
|
|
58
|
+
}.to raise_error(NameError)
|
|
57
59
|
end
|
|
58
60
|
end
|
|
59
61
|
|
|
@@ -77,18 +79,33 @@ module RSpec
|
|
|
77
79
|
end
|
|
78
80
|
it "provides a failure message when no Symbol is thrown" do
|
|
79
81
|
@matcher.matches?(lambda{})
|
|
80
|
-
@matcher.failure_message_for_should.should == %q[expected :sym with "a"
|
|
82
|
+
@matcher.failure_message_for_should.should == %q[expected :sym with "a" to be thrown, got nothing]
|
|
81
83
|
end
|
|
82
84
|
it "provides a failure message when wrong Symbol is thrown" do
|
|
83
85
|
@matcher.matches?(lambda{ throw :other_sym })
|
|
84
|
-
@matcher.failure_message_for_should.should == %q[expected :sym with "a", got :other_sym]
|
|
86
|
+
@matcher.failure_message_for_should.should == %q[expected :sym with "a" to be thrown, got :other_sym]
|
|
87
|
+
end
|
|
88
|
+
it "provides a failure message when wrong arg is thrown" do
|
|
89
|
+
@matcher.matches?(lambda{ throw :sym, "b" })
|
|
90
|
+
@matcher.failure_message_for_should.should == %q[expected :sym with "a" to be thrown, got :sym with "b"]
|
|
91
|
+
end
|
|
92
|
+
it "provides a failure message when no arg is thrown" do
|
|
93
|
+
@matcher.matches?(lambda{ throw :sym })
|
|
94
|
+
@matcher.failure_message_for_should.should == %q[expected :sym with "a" to be thrown, got :sym with no argument]
|
|
85
95
|
end
|
|
86
96
|
it "provides a negative failure message" do
|
|
87
97
|
@matcher.matches?(lambda{ throw :sym })
|
|
88
|
-
@matcher.failure_message_for_should_not.should == %q[expected :sym with "a" not to be thrown]
|
|
98
|
+
@matcher.failure_message_for_should_not.should == %q[expected :sym with "a" not to be thrown, got :sym with no argument]
|
|
89
99
|
end
|
|
90
100
|
it "only matches NameErrors raised by uncaught throws" do
|
|
91
|
-
|
|
101
|
+
expect {
|
|
102
|
+
@matcher.matches?(lambda{ sym }).should be_false
|
|
103
|
+
}.to raise_error(NameError)
|
|
104
|
+
end
|
|
105
|
+
it "raises other errors" do
|
|
106
|
+
expect {
|
|
107
|
+
@matcher.matches?(lambda { raise "Boom" })
|
|
108
|
+
}.to raise_error(/Boom/)
|
|
92
109
|
end
|
|
93
110
|
end
|
|
94
111
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
def add_to_load_path(path, prepend=false)
|
|
2
|
-
path = File.expand_path("
|
|
2
|
+
path = File.expand_path("../../#{path}/lib", __FILE__)
|
|
3
3
|
if prepend
|
|
4
4
|
$LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
|
|
5
5
|
else
|
|
@@ -7,45 +7,20 @@ def add_to_load_path(path, prepend=false)
|
|
|
7
7
|
end
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
add_to_load_path("../../rspec-core/lib")
|
|
12
|
-
add_to_load_path("../../rspec-mocks/lib")
|
|
10
|
+
require 'test/unit'
|
|
13
11
|
|
|
12
|
+
add_to_load_path("rspec-expectations", :prepend)
|
|
13
|
+
add_to_load_path("rspec-core")
|
|
14
|
+
add_to_load_path("rspec-mocks")
|
|
15
|
+
|
|
16
|
+
require 'rspec/expectations'
|
|
14
17
|
require 'rspec/core'
|
|
15
18
|
require 'rspec/mocks'
|
|
16
19
|
|
|
17
|
-
Dir['./spec/support/**/*'].each
|
|
18
|
-
require f
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def with_ruby(version)
|
|
22
|
-
yield if RUBY_PLATFORM =~ Regexp.compile("^#{version}")
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
module RSpec
|
|
26
|
-
module Ruby
|
|
27
|
-
class << self
|
|
28
|
-
def version
|
|
29
|
-
RUBY_VERSION
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
module RSpec
|
|
36
|
-
module Matchers
|
|
37
|
-
def fail
|
|
38
|
-
raise_error(RSpec::Expectations::ExpectationNotMetError)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def fail_with(message)
|
|
42
|
-
raise_error(RSpec::Expectations::ExpectationNotMetError, message)
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
20
|
+
Dir['./spec/support/**/*'].each {|f| require f}
|
|
46
21
|
|
|
47
22
|
RSpec::configure do |config|
|
|
48
|
-
config.mock_with(:rspec)
|
|
49
|
-
config.include RSpec::Mocks::Methods
|
|
50
23
|
config.color_enabled = true
|
|
24
|
+
config.filter_run :focused => true
|
|
25
|
+
config.run_all_when_everything_filtered = true
|
|
51
26
|
end
|
data/spec/support/classes.rb
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
RSpec::Matchers.define :include_method do |expected|
|
|
2
|
+
match do |actual|
|
|
3
|
+
actual.map { |m| m.to_s }.include?(expected.to_s)
|
|
4
|
+
end
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
module RSpec
|
|
8
|
+
module Matchers
|
|
9
|
+
def fail
|
|
10
|
+
raise_error(RSpec::Expectations::ExpectationNotMetError)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def fail_with(message)
|
|
14
|
+
raise_error(RSpec::Expectations::ExpectationNotMetError, message)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def fail_matching(message)
|
|
18
|
+
raise_error(RSpec::Expectations::ExpectationNotMetError, /#{Regexp.escape(message)}/)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|