rspec 1.2.9 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +34 -1
- data/License.txt +1 -1
- data/Manifest.txt +11 -4
- data/README.rdoc +2 -3
- data/Rakefile +17 -13
- data/Upgrade.rdoc +63 -2
- data/features/formatters/nested_formatter.feature +32 -0
- data/features/interop/cucumber_stubs_dont_leak.feature +11 -0
- data/features/matchers/define_matcher_with_fluent_interface.feature +21 -0
- data/features/matchers/define_wrapped_matcher.feature +28 -1
- data/features/matchers/match_unless_raises.feature +60 -0
- data/features/matchers/match_unless_raises_unexpected_error.feature +39 -0
- data/features/mocks/block_local_expectations.feature +62 -0
- data/features/step_definitions/running_rspec_steps.rb +9 -0
- data/features/step_definitions/stubbing_steps.rb +16 -0
- data/features/support/env.rb +1 -0
- data/features/support/matchers/smart_match.rb +23 -4
- data/geminstaller.yml +28 -0
- data/lib/autotest/rspec.rb +14 -7
- data/lib/spec/dsl/main.rb +1 -1
- data/lib/spec/example/example_methods.rb +4 -0
- data/lib/spec/{matchers/extensions → extensions}/instance_exec.rb +0 -0
- data/lib/spec/interop/test.rb +1 -1
- data/lib/spec/matchers.rb +21 -2
- data/lib/spec/matchers/be.rb +167 -128
- data/lib/spec/matchers/has.rb +3 -3
- data/lib/spec/matchers/have.rb +1 -0
- data/lib/spec/matchers/matcher.rb +55 -10
- data/lib/spec/matchers/method_missing.rb +2 -2
- data/lib/spec/matchers/raise_exception.rb +131 -0
- data/lib/spec/matchers/throw_symbol.rb +16 -20
- data/lib/spec/mocks/message_expectation.rb +63 -48
- data/lib/spec/mocks/methods.rb +13 -8
- data/lib/spec/mocks/proxy.rb +43 -22
- data/lib/spec/runner/differs/default.rb +1 -1
- data/lib/spec/runner/drb_command_line.rb +8 -2
- data/lib/spec/runner/example_group_runner.rb +1 -2
- data/lib/spec/runner/formatter/nested_text_formatter.rb +6 -3
- data/lib/spec/runner/option_parser.rb +2 -0
- data/lib/spec/runner/options.rb +6 -1
- data/lib/spec/stubs/cucumber.rb +2 -2
- data/lib/spec/version.rb +2 -2
- data/spec/autotest/autotest_helper.rb +1 -1
- data/spec/autotest/discover_spec.rb +2 -2
- data/spec/autotest/failed_results_re_spec.rb +2 -2
- data/spec/autotest/rspec_spec.rb +21 -6
- data/spec/spec/example/example_group_methods_spec.rb +2 -1
- data/spec/spec/interop/test/unit/spec_spec.rb +7 -7
- data/spec/spec/interop/test/unit/testcase_spec.rb +7 -7
- data/spec/spec/interop/test/unit/testsuite_adapter_spec.rb +1 -1
- data/spec/spec/matchers/be_spec.rb +159 -10
- data/spec/spec/matchers/has_spec.rb +109 -0
- data/spec/spec/matchers/matcher_spec.rb +70 -9
- data/spec/spec/matchers/raise_exception_spec.rb +345 -0
- data/spec/spec/matchers/throw_symbol_spec.rb +83 -58
- data/spec/spec/mocks/and_yield_spec.rb +117 -0
- data/spec/spec/mocks/mock_spec.rb +2 -2
- data/spec/spec/runner/command_line_spec.rb +26 -5
- data/spec/spec/runner/drb_command_line_spec.rb +39 -0
- data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +35 -11
- data/spec/spec/runner/option_parser_spec.rb +12 -6
- data/spec/spec/runner/options_spec.rb +7 -0
- data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +23 -5
- metadata +17 -10
- data/lib/spec/matchers/raise_error.rb +0 -129
- data/spec/spec/matchers/matcher_methods_spec.rb +0 -63
- data/spec/spec/matchers/raise_error_spec.rb +0 -333
@@ -4,6 +4,6 @@ describe "TestSuiteAdapter" do
|
|
4
4
|
include TestUnitSpecHelper
|
5
5
|
it "should pass" do
|
6
6
|
dir = File.dirname(__FILE__)
|
7
|
-
run_script "#{dir}/resources/testsuite_adapter_spec_with_test_unit.rb"
|
7
|
+
run_script "'#{dir}/resources/testsuite_adapter_spec_with_test_unit.rb'"
|
8
8
|
end
|
9
9
|
end
|
@@ -117,27 +117,143 @@ describe "should_not be_predicate(*args)" do
|
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
+
describe "should be_predicate(&block)" do
|
121
|
+
it "should pass when actual returns true for :predicate?(&block)" do
|
122
|
+
actual = mock("actual")
|
123
|
+
delegate = mock("delegate")
|
124
|
+
actual.should_receive(:happy?).and_yield
|
125
|
+
delegate.should_receive(:check_happy).and_return(true)
|
126
|
+
actual.should be_happy { delegate.check_happy }
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should fail when actual returns false for :predicate?(&block)" do
|
130
|
+
actual = mock("actual")
|
131
|
+
delegate = mock("delegate")
|
132
|
+
actual.should_receive(:happy?).and_yield
|
133
|
+
delegate.should_receive(:check_happy).and_return(false)
|
134
|
+
lambda {
|
135
|
+
actual.should be_happy { delegate.check_happy }
|
136
|
+
}.should fail_with("expected happy? to return true, got false")
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should fail when actual does not respond to :predicate?" do
|
140
|
+
delegate = mock("delegate", :check_happy => true)
|
141
|
+
lambda {
|
142
|
+
Object.new.should be_happy { delegate.check_happy }
|
143
|
+
}.should raise_error(NameError)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe "should_not be_predicate(&block)" do
|
148
|
+
it "should pass when actual returns false for :predicate?(&block)" do
|
149
|
+
actual = mock("actual")
|
150
|
+
delegate = mock("delegate")
|
151
|
+
actual.should_receive(:happy?).and_yield
|
152
|
+
delegate.should_receive(:check_happy).and_return(false)
|
153
|
+
actual.should_not be_happy { delegate.check_happy }
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should fail when actual returns true for :predicate?(&block)" do
|
157
|
+
actual = mock("actual")
|
158
|
+
delegate = mock("delegate")
|
159
|
+
actual.should_receive(:happy?).and_yield
|
160
|
+
delegate.should_receive(:check_happy).and_return(true)
|
161
|
+
lambda {
|
162
|
+
actual.should_not be_happy { delegate.check_happy }
|
163
|
+
}.should fail_with("expected happy? to return false, got true")
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should fail when actual does not respond to :predicate?" do
|
167
|
+
delegate = mock("delegate", :check_happy => true)
|
168
|
+
lambda {
|
169
|
+
Object.new.should_not be_happy { delegate.check_happy }
|
170
|
+
}.should raise_error(NameError)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
describe "should be_predicate(*args, &block)" do
|
175
|
+
it "should pass when actual returns true for :predicate?(*args, &block)" do
|
176
|
+
actual = mock("actual")
|
177
|
+
delegate = mock("delegate")
|
178
|
+
actual.should_receive(:older_than?).with(3).and_yield(3)
|
179
|
+
delegate.should_receive(:check_older_than).with(3).and_return(true)
|
180
|
+
actual.should be_older_than(3) { |age| delegate.check_older_than(age) }
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should fail when actual returns false for :predicate?(*args, &block)" do
|
184
|
+
actual = mock("actual")
|
185
|
+
delegate = mock("delegate")
|
186
|
+
actual.should_receive(:older_than?).with(3).and_yield(3)
|
187
|
+
delegate.should_receive(:check_older_than).with(3).and_return(false)
|
188
|
+
lambda {
|
189
|
+
actual.should be_older_than(3) { |age| delegate.check_older_than(age) }
|
190
|
+
}.should fail_with("expected older_than?(3) to return true, got false")
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should fail when actual does not respond to :predicate?" do
|
194
|
+
delegate = mock("delegate", :check_older_than => true)
|
195
|
+
lambda {
|
196
|
+
Object.new.should be_older_than(3) { |age| delegate.check_older_than(age) }
|
197
|
+
}.should raise_error(NameError)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
describe "should_not be_predicate(*args, &block)" do
|
202
|
+
it "should pass when actual returns false for :predicate?(*args, &block)" do
|
203
|
+
actual = mock("actual")
|
204
|
+
delegate = mock("delegate")
|
205
|
+
actual.should_receive(:older_than?).with(3).and_yield(3)
|
206
|
+
delegate.should_receive(:check_older_than).with(3).and_return(false)
|
207
|
+
actual.should_not be_older_than(3) { |age| delegate.check_older_than(age) }
|
208
|
+
end
|
209
|
+
|
210
|
+
it "should fail when actual returns true for :predicate?(*args, &block)" do
|
211
|
+
actual = mock("actual")
|
212
|
+
delegate = mock("delegate")
|
213
|
+
actual.should_receive(:older_than?).with(3).and_yield(3)
|
214
|
+
delegate.should_receive(:check_older_than).with(3).and_return(true)
|
215
|
+
lambda {
|
216
|
+
actual.should_not be_older_than(3) { |age| delegate.check_older_than(age) }
|
217
|
+
}.should fail_with("expected older_than?(3) to return false, got true")
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should fail when actual does not respond to :predicate?" do
|
221
|
+
delegate = mock("delegate", :check_older_than => true)
|
222
|
+
lambda {
|
223
|
+
Object.new.should_not be_older_than(3) { |age| delegate.check_older_than(age) }
|
224
|
+
}.should raise_error(NameError)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
120
228
|
describe "should be_true" do
|
121
|
-
it "should pass when actual equal(true)" do
|
229
|
+
it "should pass when actual equal?(true)" do
|
122
230
|
true.should be_true
|
123
231
|
end
|
124
232
|
|
125
|
-
it "should
|
233
|
+
it "should pass when actual is 1" do
|
234
|
+
1.should be_true
|
235
|
+
end
|
236
|
+
|
237
|
+
it "should fail when actual equal?(false)" do
|
126
238
|
lambda {
|
127
239
|
false.should be_true
|
128
|
-
}.should fail_with("expected
|
240
|
+
}.should fail_with("expected false to be true")
|
129
241
|
end
|
130
242
|
end
|
131
243
|
|
132
244
|
describe "should be_false" do
|
133
|
-
it "should pass when actual equal(false)" do
|
245
|
+
it "should pass when actual equal?(false)" do
|
134
246
|
false.should be_false
|
135
247
|
end
|
136
248
|
|
137
|
-
it "should
|
249
|
+
it "should pass when actual equal?(nil)" do
|
250
|
+
nil.should be_false
|
251
|
+
end
|
252
|
+
|
253
|
+
it "should fail when actual equal?(true)" do
|
138
254
|
lambda {
|
139
255
|
true.should be_false
|
140
|
-
}.should fail_with("expected
|
256
|
+
}.should fail_with("expected true to be false")
|
141
257
|
end
|
142
258
|
end
|
143
259
|
|
@@ -173,6 +289,10 @@ describe "should be <" do
|
|
173
289
|
it "should fail when < operator returns false" do
|
174
290
|
lambda { 3.should be < 3 }.should fail_with("expected < 3, got 3")
|
175
291
|
end
|
292
|
+
|
293
|
+
it "should describe itself" do
|
294
|
+
be.<(4).description.should == "be < 4"
|
295
|
+
end
|
176
296
|
end
|
177
297
|
|
178
298
|
describe "should be <=" do
|
@@ -236,17 +356,32 @@ describe "should_not with operators" do
|
|
236
356
|
end
|
237
357
|
|
238
358
|
describe "should be" do
|
239
|
-
it "should pass if actual is
|
359
|
+
it "should pass if actual is truthy" do
|
240
360
|
true.should be
|
241
361
|
1.should be
|
242
362
|
end
|
243
363
|
|
244
364
|
it "should fail if actual is false" do
|
245
|
-
lambda {false.should be}.should fail_with("expected
|
365
|
+
lambda {false.should be}.should fail_with("expected false to evaluate to true")
|
246
366
|
end
|
247
367
|
|
248
368
|
it "should fail if actual is nil" do
|
249
|
-
lambda {nil.should be}.should fail_with("expected
|
369
|
+
lambda {nil.should be}.should fail_with("expected nil to evaluate to true")
|
370
|
+
end
|
371
|
+
|
372
|
+
it "should describe itself" do
|
373
|
+
be.description.should == "be"
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
describe "should_not be" do
|
378
|
+
it "should pass if actual is falsy" do
|
379
|
+
false.should_not be
|
380
|
+
nil.should_not be
|
381
|
+
end
|
382
|
+
|
383
|
+
it "should fail on true" do
|
384
|
+
lambda {true.should_not be}.should fail_with("expected true to evaluate to false")
|
250
385
|
end
|
251
386
|
end
|
252
387
|
|
@@ -254,9 +389,23 @@ describe "should be(value)" do
|
|
254
389
|
it "should pass if actual.equal?(value)" do
|
255
390
|
5.should be(5)
|
256
391
|
end
|
392
|
+
|
257
393
|
it "should fail if !actual.equal?(value)" do
|
258
394
|
lambda { 5.should be(6) }.should fail_with("expected 6, got 5")
|
259
395
|
end
|
396
|
+
|
397
|
+
it "should describe itself" do
|
398
|
+
be(5).description.should == "be 5"
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
describe "should_not be(value)" do
|
403
|
+
it "should pass if !actual.equal?(value)" do
|
404
|
+
5.should_not be(6)
|
405
|
+
end
|
406
|
+
it "should fail if !actual.equal?(value)" do
|
407
|
+
lambda { 5.should_not be(5) }.should fail_with("expected not 5, got 5")
|
408
|
+
end
|
260
409
|
end
|
261
410
|
|
262
411
|
describe "'should be' with operator" do
|
@@ -308,4 +457,4 @@ describe "be_an_instance_of" do
|
|
308
457
|
it "fails when class is higher up hierarchy" do
|
309
458
|
5.should_not be_an_instance_of(Numeric)
|
310
459
|
end
|
311
|
-
end
|
460
|
+
end
|
@@ -70,6 +70,115 @@ describe "should_not have_sym(*args)" do
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
+
describe "should have_sym(&block)" do
|
74
|
+
it "should pass when actual returns true for :has_sym?(&block)" do
|
75
|
+
actual = mock("actual")
|
76
|
+
delegate = mock("delegate")
|
77
|
+
actual.should_receive(:has_foo?).and_yield
|
78
|
+
delegate.should_receive(:check_has_foo).and_return(true)
|
79
|
+
actual.should have_foo { delegate.check_has_foo }
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should fail when actual returns false for :has_sym?(&block)" do
|
83
|
+
actual = mock("actual")
|
84
|
+
delegate = mock("delegate")
|
85
|
+
actual.should_receive(:has_foo?).and_yield
|
86
|
+
delegate.should_receive(:check_has_foo).and_return(false)
|
87
|
+
lambda {
|
88
|
+
actual.should have_foo { delegate.check_has_foo }
|
89
|
+
}.should fail_with("expected #has_foo?(nil) to return true, got false")
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should fail when actual does not respond to :has_sym?" do
|
93
|
+
delegate = mock("delegate", :check_has_foo => true)
|
94
|
+
lambda {
|
95
|
+
Object.new.should have_foo { delegate.check_has_foo }
|
96
|
+
}.should raise_error(NameError)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "should_not have_sym(&block)" do
|
101
|
+
it "should pass when actual returns false for :has_sym?(&block)" do
|
102
|
+
actual = mock("actual")
|
103
|
+
delegate = mock("delegate")
|
104
|
+
actual.should_receive(:has_foo?).and_yield
|
105
|
+
delegate.should_receive(:check_has_foo).and_return(false)
|
106
|
+
actual.should_not have_foo { delegate.check_has_foo }
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should fail when actual returns true for :has_sym?(&block)" do
|
110
|
+
actual = mock("actual")
|
111
|
+
delegate = mock("delegate")
|
112
|
+
actual.should_receive(:has_foo?).and_yield
|
113
|
+
delegate.should_receive(:check_has_foo).and_return(true)
|
114
|
+
lambda {
|
115
|
+
actual.should_not have_foo { delegate.check_has_foo }
|
116
|
+
}.should fail_with("expected #has_foo?(nil) to return false, got true")
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should fail when actual does not respond to :has_sym?" do
|
120
|
+
delegate = mock("delegate", :check_has_foo => true)
|
121
|
+
lambda {
|
122
|
+
Object.new.should_not have_foo { delegate.check_has_foo }
|
123
|
+
}.should raise_error(NameError)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "should have_sym(*args, &block)" do
|
128
|
+
it "should pass when actual returns true for :has_sym?(*args, &block)" do
|
129
|
+
actual = mock("actual")
|
130
|
+
delegate = mock("delegate")
|
131
|
+
actual.should_receive(:has_foo?).with(:a).and_yield(:a)
|
132
|
+
delegate.should_receive(:check_has_foo).with(:a).and_return(true)
|
133
|
+
actual.should have_foo(:a) { |foo| delegate.check_has_foo(foo) }
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should fail when actual returns false for :has_sym?(*args, &block)" do
|
137
|
+
actual = mock("actual")
|
138
|
+
delegate = mock("delegate")
|
139
|
+
actual.should_receive(:has_foo?).with(:a).and_yield(:a)
|
140
|
+
delegate.should_receive(:check_has_foo).with(:a).and_return(false)
|
141
|
+
lambda {
|
142
|
+
actual.should have_foo(:a) { |foo| delegate.check_has_foo(foo) }
|
143
|
+
}.should fail_with("expected #has_foo?(:a) to return true, got false")
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should fail when actual does not respond to :has_sym?" do
|
147
|
+
delegate = mock("delegate", :check_has_foo => true)
|
148
|
+
lambda {
|
149
|
+
Object.new.should have_foo(:a) { |foo| delegate.check_has_foo(foo) }
|
150
|
+
}.should raise_error(NameError)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "should_not have_sym(*args, &block)" do
|
155
|
+
it "should pass when actual returns false for :has_sym?(*args, &block)" do
|
156
|
+
actual = mock("actual")
|
157
|
+
delegate = mock("delegate")
|
158
|
+
actual.should_receive(:has_foo?).with(:a).and_yield(:a)
|
159
|
+
delegate.should_receive(:check_has_foo).with(:a).and_return(false)
|
160
|
+
actual.should_not have_foo(:a) { |foo| delegate.check_has_foo(foo) }
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should fail when actual returns true for :has_sym?(*args, &block)" do
|
164
|
+
actual = mock("actual")
|
165
|
+
delegate = mock("delegate")
|
166
|
+
actual.should_receive(:has_foo?).with(:a).and_yield(:a)
|
167
|
+
delegate.should_receive(:check_has_foo).with(:a).and_return(true)
|
168
|
+
lambda {
|
169
|
+
actual.should_not have_foo(:a) { |foo| delegate.check_has_foo(foo) }
|
170
|
+
}.should fail_with("expected #has_foo?(:a) to return false, got true")
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should fail when actual does not respond to :has_sym?" do
|
174
|
+
delegate = mock("delegate", :check_has_foo => true)
|
175
|
+
lambda {
|
176
|
+
Object.new.should_not have_foo(:a) { |foo| delegate.check_has_foo(foo) }
|
177
|
+
}.should raise_error(NameError)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
|
73
182
|
describe "has" do
|
74
183
|
it "should work when the target implements #send" do
|
75
184
|
o = {:a => "A"}
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
class UnexpectedError < StandardError; end
|
4
|
+
|
3
5
|
module Spec
|
4
6
|
module Matchers
|
5
7
|
describe Matcher do
|
@@ -52,6 +54,26 @@ module Spec
|
|
52
54
|
matcher.actual.should == 'actual string'
|
53
55
|
end
|
54
56
|
|
57
|
+
context "wrapping another expectation (should == ...)" do
|
58
|
+
it "returns true if the wrapped expectation passes" do
|
59
|
+
matcher = Spec::Matchers::Matcher.new(:name, 'value') do |expected|
|
60
|
+
match do |actual|
|
61
|
+
actual.should == expected
|
62
|
+
end
|
63
|
+
end
|
64
|
+
matcher.matches?('value').should be_true
|
65
|
+
end
|
66
|
+
|
67
|
+
it "returns false if the wrapped expectation fails" do
|
68
|
+
matcher = Spec::Matchers::Matcher.new(:name, 'value') do |expected|
|
69
|
+
match do |actual|
|
70
|
+
actual.should == expected
|
71
|
+
end
|
72
|
+
end
|
73
|
+
matcher.matches?('other value').should be_false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
55
77
|
context "with overrides" do
|
56
78
|
before(:each) do
|
57
79
|
@matcher = Spec::Matchers::Matcher.new(:be_boolean, true) do |boolean|
|
@@ -207,22 +229,61 @@ module Spec
|
|
207
229
|
matcher.matches?(8).should be_true
|
208
230
|
end
|
209
231
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
232
|
+
describe "#match_unless_raises" do
|
233
|
+
context "with a passing assertion" do
|
234
|
+
let(:mod) do
|
235
|
+
Module.new do
|
236
|
+
def assert_equal(a,b)
|
237
|
+
a == b ? nil : (raise UnexpectedError.new("#{a} does not equal #{b}"))
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
let(:matcher) do
|
242
|
+
m = mod
|
243
|
+
Spec::Matchers::Matcher.new :equal, 4 do |expected|
|
244
|
+
extend m
|
245
|
+
match_unless_raises UnexpectedError do
|
246
|
+
assert_equal expected, actual
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
it "passes as you would expect" do
|
251
|
+
matcher.matches?(4).should be_true
|
215
252
|
end
|
253
|
+
it "fails as you would expect" do
|
254
|
+
matcher.matches?(5).should be_false
|
255
|
+
end
|
256
|
+
end
|
216
257
|
|
217
|
-
|
218
|
-
|
258
|
+
context "with an unexpected error" do
|
259
|
+
let(:matcher) do
|
260
|
+
Spec::Matchers::Matcher.new :foo, :bar do |expected|
|
261
|
+
match_unless_raises SyntaxError do |actual|
|
262
|
+
raise "unexpected exception"
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
it "raises the error" do
|
268
|
+
expect do
|
269
|
+
matcher.matches?(:bar)
|
270
|
+
end.to raise_error("unexpected exception")
|
219
271
|
end
|
220
272
|
end
|
221
273
|
|
222
|
-
matcher.matches?("foo")
|
223
|
-
matcher.failure_message_for_should.should =~ /replaced/
|
224
274
|
end
|
225
275
|
|
276
|
+
it "can define chainable methods" do
|
277
|
+
matcher = Spec::Matchers::Matcher.new(:name) do
|
278
|
+
chain(:expecting) do |expected_value|
|
279
|
+
@expected_value = expected_value
|
280
|
+
end
|
281
|
+
match { |actual| actual == @expected_value }
|
282
|
+
end
|
283
|
+
|
284
|
+
matcher.expecting('value').matches?('value').should be_true
|
285
|
+
matcher.expecting('value').matches?('other value').should be_false
|
286
|
+
end
|
226
287
|
end
|
227
288
|
end
|
228
289
|
end
|