rspec-expectations 2.11.3 → 3.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/.document +1 -1
- data/.yardopts +1 -1
- data/Changelog.md +1026 -21
- data/{License.txt → LICENSE.md} +5 -3
- data/README.md +174 -78
- data/lib/rspec/expectations/block_snippet_extractor.rb +253 -0
- data/lib/rspec/expectations/configuration.rb +230 -0
- data/lib/rspec/expectations/expectation_target.rb +130 -55
- data/lib/rspec/expectations/fail_with.rb +17 -33
- data/lib/rspec/expectations/failure_aggregator.rb +212 -0
- data/lib/rspec/expectations/handler.rb +163 -29
- data/lib/rspec/expectations/minitest_integration.rb +58 -0
- data/lib/rspec/expectations/syntax.rb +68 -54
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/expectations.rb +59 -24
- data/lib/rspec/matchers/aliased_matcher.rb +116 -0
- data/lib/rspec/matchers/built_in/all.rb +86 -0
- data/lib/rspec/matchers/built_in/base_matcher.rb +150 -20
- data/lib/rspec/matchers/built_in/be.rb +115 -109
- data/lib/rspec/matchers/built_in/be_between.rb +77 -0
- data/lib/rspec/matchers/built_in/be_instance_of.rb +16 -1
- data/lib/rspec/matchers/built_in/be_kind_of.rb +10 -1
- data/lib/rspec/matchers/built_in/be_within.rb +43 -17
- data/lib/rspec/matchers/built_in/change.rb +392 -75
- data/lib/rspec/matchers/built_in/compound.rb +290 -0
- data/lib/rspec/matchers/built_in/contain_exactly.rb +302 -0
- data/lib/rspec/matchers/built_in/count_expectation.rb +169 -0
- data/lib/rspec/matchers/built_in/cover.rb +3 -0
- data/lib/rspec/matchers/built_in/eq.rb +26 -8
- data/lib/rspec/matchers/built_in/eql.rb +19 -8
- data/lib/rspec/matchers/built_in/equal.rb +56 -19
- data/lib/rspec/matchers/built_in/exist.rb +74 -10
- data/lib/rspec/matchers/built_in/has.rb +141 -22
- data/lib/rspec/matchers/built_in/have_attributes.rb +114 -0
- data/lib/rspec/matchers/built_in/include.rb +175 -20
- data/lib/rspec/matchers/built_in/match.rb +95 -1
- data/lib/rspec/matchers/built_in/operators.rb +128 -0
- data/lib/rspec/matchers/built_in/output.rb +207 -0
- data/lib/rspec/matchers/built_in/raise_error.rb +212 -38
- data/lib/rspec/matchers/built_in/respond_to.rb +155 -29
- data/lib/rspec/matchers/built_in/satisfy.rb +39 -9
- data/lib/rspec/matchers/built_in/start_or_end_with.rb +94 -0
- data/lib/rspec/matchers/built_in/throw_symbol.rb +58 -14
- data/lib/rspec/matchers/built_in/yield.rb +252 -98
- data/lib/rspec/matchers/built_in.rb +47 -33
- data/lib/rspec/matchers/composable.rb +171 -0
- data/lib/rspec/matchers/dsl.rb +530 -10
- data/lib/rspec/matchers/english_phrasing.rb +58 -0
- data/lib/rspec/matchers/expecteds_for_multiple_diffs.rb +82 -0
- data/lib/rspec/matchers/fail_matchers.rb +42 -0
- data/lib/rspec/matchers/generated_descriptions.rb +15 -10
- data/lib/rspec/matchers/matcher_delegator.rb +35 -0
- data/lib/rspec/matchers/matcher_protocol.rb +105 -0
- data/lib/rspec/matchers.rb +604 -252
- data.tar.gz.sig +0 -0
- metadata +178 -278
- metadata.gz.sig +0 -0
- data/features/README.md +0 -49
- data/features/Upgrade.md +0 -53
- data/features/built_in_matchers/README.md +0 -90
- data/features/built_in_matchers/be.feature +0 -173
- data/features/built_in_matchers/be_within.feature +0 -46
- data/features/built_in_matchers/cover.feature +0 -45
- data/features/built_in_matchers/end_with.feature +0 -46
- data/features/built_in_matchers/equality.feature +0 -145
- data/features/built_in_matchers/exist.feature +0 -43
- data/features/built_in_matchers/expect_change.feature +0 -59
- data/features/built_in_matchers/expect_error.feature +0 -138
- data/features/built_in_matchers/have.feature +0 -103
- data/features/built_in_matchers/include.feature +0 -121
- data/features/built_in_matchers/match.feature +0 -50
- data/features/built_in_matchers/operators.feature +0 -221
- data/features/built_in_matchers/predicates.feature +0 -128
- data/features/built_in_matchers/respond_to.feature +0 -78
- data/features/built_in_matchers/satisfy.feature +0 -31
- data/features/built_in_matchers/start_with.feature +0 -46
- data/features/built_in_matchers/throw_symbol.feature +0 -85
- data/features/built_in_matchers/types.feature +0 -114
- data/features/built_in_matchers/yield.feature +0 -146
- data/features/custom_matchers/access_running_example.feature +0 -53
- data/features/custom_matchers/define_diffable_matcher.feature +0 -27
- data/features/custom_matchers/define_matcher.feature +0 -340
- data/features/custom_matchers/define_matcher_outside_rspec.feature +0 -38
- data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
- data/features/customized_message.feature +0 -22
- data/features/diffing.feature +0 -85
- data/features/implicit_docstrings.feature +0 -52
- data/features/step_definitions/additional_cli_steps.rb +0 -22
- data/features/support/env.rb +0 -5
- data/features/syntax_configuration.feature +0 -68
- data/features/test_frameworks/test_unit.feature +0 -46
- data/lib/rspec/expectations/deprecation.rb +0 -38
- data/lib/rspec/expectations/differ.rb +0 -81
- data/lib/rspec/expectations/errors.rb +0 -9
- data/lib/rspec/expectations/extensions/array.rb +0 -9
- data/lib/rspec/expectations/extensions/object.rb +0 -39
- data/lib/rspec/expectations/extensions.rb +0 -2
- data/lib/rspec/matchers/be_close.rb +0 -9
- data/lib/rspec/matchers/built_in/have.rb +0 -108
- data/lib/rspec/matchers/built_in/match_array.rb +0 -45
- data/lib/rspec/matchers/built_in/start_and_end_with.rb +0 -48
- data/lib/rspec/matchers/compatibility.rb +0 -14
- data/lib/rspec/matchers/configuration.rb +0 -66
- data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
- data/lib/rspec/matchers/matcher.rb +0 -299
- data/lib/rspec/matchers/method_missing.rb +0 -12
- data/lib/rspec/matchers/operator_matcher.rb +0 -84
- data/lib/rspec/matchers/pretty.rb +0 -60
- data/lib/rspec-expectations.rb +0 -1
- data/spec/rspec/expectations/differ_spec.rb +0 -153
- data/spec/rspec/expectations/expectation_target_spec.rb +0 -65
- data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
- data/spec/rspec/expectations/fail_with_spec.rb +0 -70
- data/spec/rspec/expectations/handler_spec.rb +0 -206
- data/spec/rspec/matchers/base_matcher_spec.rb +0 -60
- data/spec/rspec/matchers/be_close_spec.rb +0 -22
- data/spec/rspec/matchers/be_instance_of_spec.rb +0 -40
- data/spec/rspec/matchers/be_kind_of_spec.rb +0 -37
- data/spec/rspec/matchers/be_spec.rb +0 -452
- data/spec/rspec/matchers/be_within_spec.rb +0 -80
- data/spec/rspec/matchers/change_spec.rb +0 -528
- data/spec/rspec/matchers/configuration_spec.rb +0 -202
- data/spec/rspec/matchers/cover_spec.rb +0 -69
- data/spec/rspec/matchers/description_generation_spec.rb +0 -176
- data/spec/rspec/matchers/dsl_spec.rb +0 -57
- data/spec/rspec/matchers/eq_spec.rb +0 -54
- data/spec/rspec/matchers/eql_spec.rb +0 -41
- data/spec/rspec/matchers/equal_spec.rb +0 -60
- data/spec/rspec/matchers/exist_spec.rb +0 -110
- data/spec/rspec/matchers/has_spec.rb +0 -118
- data/spec/rspec/matchers/have_spec.rb +0 -461
- data/spec/rspec/matchers/include_spec.rb +0 -367
- data/spec/rspec/matchers/match_array_spec.rb +0 -124
- data/spec/rspec/matchers/match_spec.rb +0 -61
- data/spec/rspec/matchers/matcher_spec.rb +0 -434
- data/spec/rspec/matchers/matchers_spec.rb +0 -31
- data/spec/rspec/matchers/method_missing_spec.rb +0 -24
- data/spec/rspec/matchers/operator_matcher_spec.rb +0 -221
- data/spec/rspec/matchers/raise_error_spec.rb +0 -344
- data/spec/rspec/matchers/respond_to_spec.rb +0 -295
- data/spec/rspec/matchers/satisfy_spec.rb +0 -44
- data/spec/rspec/matchers/start_with_end_with_spec.rb +0 -182
- data/spec/rspec/matchers/throw_symbol_spec.rb +0 -116
- data/spec/rspec/matchers/yield_spec.rb +0 -402
- data/spec/spec_helper.rb +0 -27
- data/spec/support/classes.rb +0 -56
- data/spec/support/in_sub_process.rb +0 -31
- data/spec/support/matchers.rb +0 -22
- data/spec/support/ruby_version.rb +0 -10
- data/spec/support/shared_examples.rb +0 -13
@@ -1,344 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "should raise_error" do
|
4
|
-
it_behaves_like("an RSpec matcher", :valid_value => lambda { raise "boom" },
|
5
|
-
:invalid_value => lambda { }) do
|
6
|
-
let(:matcher) { raise_error(/boom/) }
|
7
|
-
end
|
8
|
-
|
9
|
-
it "passes if anything is raised" do
|
10
|
-
lambda {raise}.should raise_error
|
11
|
-
end
|
12
|
-
|
13
|
-
it "fails if nothing is raised" do
|
14
|
-
lambda {
|
15
|
-
lambda {}.should raise_error
|
16
|
-
}.should fail_with("expected Exception but nothing was raised")
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "raise_exception aliased to raise_error" do
|
21
|
-
it "passes if anything is raised" do
|
22
|
-
lambda {raise}.should raise_exception
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "should raise_error {|err| ... }" do
|
27
|
-
it "passes if there is an error" do
|
28
|
-
ran = false
|
29
|
-
lambda { non_existent_method }.should raise_error {|e|
|
30
|
-
ran = true
|
31
|
-
}
|
32
|
-
ran.should be_true
|
33
|
-
end
|
34
|
-
|
35
|
-
it "passes the error to the block" do
|
36
|
-
error = nil
|
37
|
-
lambda { non_existent_method }.should raise_error {|e|
|
38
|
-
error = e
|
39
|
-
}
|
40
|
-
error.should be_kind_of(NameError)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "should_not raise_error" do
|
45
|
-
it "passes if nothing is raised" do
|
46
|
-
lambda {}.should_not raise_error
|
47
|
-
end
|
48
|
-
|
49
|
-
it "fails if anything is raised" do
|
50
|
-
lambda {
|
51
|
-
lambda { raise RuntimeError, "example message" }.should_not raise_error
|
52
|
-
}.should fail_with("expected no Exception, got #<RuntimeError: example message>")
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe "should raise_error(message)" do
|
57
|
-
it "passes if RuntimeError is raised with the right message" do
|
58
|
-
lambda {raise 'blah'}.should raise_error('blah')
|
59
|
-
end
|
60
|
-
it "passes if RuntimeError is raised with a matching message" do
|
61
|
-
lambda {raise 'blah'}.should raise_error(/blah/)
|
62
|
-
end
|
63
|
-
it "passes if any other error is raised with the right message" do
|
64
|
-
lambda {raise NameError.new('blah')}.should raise_error('blah')
|
65
|
-
end
|
66
|
-
it "fails if RuntimeError error is raised with the wrong message" do
|
67
|
-
lambda do
|
68
|
-
lambda {raise 'blarg'}.should raise_error('blah')
|
69
|
-
end.should fail_with("expected Exception with \"blah\", got #<RuntimeError: blarg>")
|
70
|
-
end
|
71
|
-
it "fails if any other error is raised with the wrong message" do
|
72
|
-
lambda do
|
73
|
-
lambda {raise NameError.new('blarg')}.should raise_error('blah')
|
74
|
-
end.should fail_with("expected Exception with \"blah\", got #<NameError: blarg>")
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe "should_not raise_error(message)" do
|
79
|
-
it "passes if RuntimeError error is raised with the different message" do
|
80
|
-
lambda {raise 'blarg'}.should_not raise_error('blah')
|
81
|
-
end
|
82
|
-
it "passes if any other error is raised with the wrong message" do
|
83
|
-
lambda {raise NameError.new('blarg')}.should_not raise_error('blah')
|
84
|
-
end
|
85
|
-
it "fails if RuntimeError is raised with message" do
|
86
|
-
lambda do
|
87
|
-
lambda {raise 'blah'}.should_not raise_error('blah')
|
88
|
-
end.should fail_with(%Q|expected no Exception with "blah", got #<RuntimeError: blah>|)
|
89
|
-
end
|
90
|
-
it "fails if any other error is raised with message" do
|
91
|
-
lambda do
|
92
|
-
lambda {raise NameError.new('blah')}.should_not raise_error('blah')
|
93
|
-
end.should fail_with(%Q|expected no Exception with "blah", got #<NameError: blah>|)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
describe "should raise_error(NamedError)" do
|
98
|
-
it "passes if named error is raised" do
|
99
|
-
lambda { non_existent_method }.should raise_error(NameError)
|
100
|
-
end
|
101
|
-
|
102
|
-
it "fails if nothing is raised" do
|
103
|
-
lambda {
|
104
|
-
lambda { }.should raise_error(NameError)
|
105
|
-
}.should fail_with("expected NameError but nothing was raised")
|
106
|
-
end
|
107
|
-
|
108
|
-
it "fails if another error is raised (NameError)" do
|
109
|
-
lambda {
|
110
|
-
lambda { raise RuntimeError, "example message" }.should raise_error(NameError)
|
111
|
-
}.should fail_with("expected NameError, got #<RuntimeError: example message>")
|
112
|
-
end
|
113
|
-
|
114
|
-
it "fails if another error is raised (NameError)" do
|
115
|
-
lambda {
|
116
|
-
lambda { load "non/existent/file" }.should raise_error(NameError)
|
117
|
-
}.should fail_with(/expected NameError, got #<LoadError/)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
describe "should_not raise_error(NamedError)" do
|
122
|
-
it "passes if nothing is raised" do
|
123
|
-
lambda { }.should_not raise_error(NameError)
|
124
|
-
end
|
125
|
-
|
126
|
-
it "passes if another error is raised" do
|
127
|
-
lambda { raise }.should_not raise_error(NameError)
|
128
|
-
end
|
129
|
-
|
130
|
-
it "fails if named error is raised" do
|
131
|
-
lambda {
|
132
|
-
lambda { 1 + 'b' }.should_not raise_error(TypeError)
|
133
|
-
}.should fail_with(/expected no TypeError, got #<TypeError: String can't be/)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
describe "should raise_error(NamedError, error_message) with String" do
|
138
|
-
it "passes if named error is raised with same message" do
|
139
|
-
lambda { raise "example message" }.should raise_error(RuntimeError, "example message")
|
140
|
-
end
|
141
|
-
|
142
|
-
it "fails if nothing is raised" do
|
143
|
-
lambda {
|
144
|
-
lambda {}.should raise_error(RuntimeError, "example message")
|
145
|
-
}.should fail_with("expected RuntimeError with \"example message\" but nothing was raised")
|
146
|
-
end
|
147
|
-
|
148
|
-
it "fails if incorrect error is raised" do
|
149
|
-
lambda {
|
150
|
-
lambda { raise RuntimeError, "example message" }.should raise_error(NameError, "example message")
|
151
|
-
}.should fail_with("expected NameError with \"example message\", got #<RuntimeError: example message>")
|
152
|
-
end
|
153
|
-
|
154
|
-
it "fails if correct error is raised with incorrect message" do
|
155
|
-
lambda {
|
156
|
-
lambda { raise RuntimeError.new("not the example message") }.should raise_error(RuntimeError, "example message")
|
157
|
-
}.should fail_with(/expected RuntimeError with \"example message\", got #<RuntimeError: not the example message/)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
describe "should raise_error(NamedError, error_message) { |err| ... }" do
|
162
|
-
it "yields exception if named error is raised with same message" do
|
163
|
-
ran = false
|
164
|
-
|
165
|
-
lambda {
|
166
|
-
raise "example message"
|
167
|
-
}.should raise_error(RuntimeError, "example message") { |err|
|
168
|
-
ran = true
|
169
|
-
err.class.should eq RuntimeError
|
170
|
-
err.message.should eq "example message"
|
171
|
-
}
|
172
|
-
|
173
|
-
ran.should be(true)
|
174
|
-
end
|
175
|
-
|
176
|
-
it "yielded block fails on it's own right" do
|
177
|
-
ran, passed = false, false
|
178
|
-
|
179
|
-
lambda {
|
180
|
-
lambda {
|
181
|
-
raise "example message"
|
182
|
-
}.should raise_error(RuntimeError, "example message") { |err|
|
183
|
-
ran = true
|
184
|
-
5.should eq 4
|
185
|
-
passed = true
|
186
|
-
}
|
187
|
-
}.should fail_with(/expected: 4/m)
|
188
|
-
|
189
|
-
ran.should be_true
|
190
|
-
passed.should be_false
|
191
|
-
end
|
192
|
-
|
193
|
-
it "does NOT yield exception if no error was thrown" do
|
194
|
-
ran = false
|
195
|
-
|
196
|
-
lambda {
|
197
|
-
lambda {}.should raise_error(RuntimeError, "example message") { |err|
|
198
|
-
ran = true
|
199
|
-
}
|
200
|
-
}.should fail_with("expected RuntimeError with \"example message\" but nothing was raised")
|
201
|
-
|
202
|
-
ran.should == false
|
203
|
-
end
|
204
|
-
|
205
|
-
it "does not yield exception if error class is not matched" do
|
206
|
-
ran = false
|
207
|
-
|
208
|
-
lambda {
|
209
|
-
lambda {
|
210
|
-
raise "example message"
|
211
|
-
}.should raise_error(SyntaxError, "example message") { |err|
|
212
|
-
ran = true
|
213
|
-
}
|
214
|
-
}.should fail_with("expected SyntaxError with \"example message\", got #<RuntimeError: example message>")
|
215
|
-
|
216
|
-
ran.should == false
|
217
|
-
end
|
218
|
-
|
219
|
-
it "does NOT yield exception if error message is not matched" do
|
220
|
-
ran = false
|
221
|
-
|
222
|
-
lambda {
|
223
|
-
lambda {
|
224
|
-
raise "example message"
|
225
|
-
}.should raise_error(RuntimeError, "different message") { |err|
|
226
|
-
ran = true
|
227
|
-
}
|
228
|
-
}.should fail_with("expected RuntimeError with \"different message\", got #<RuntimeError: example message>")
|
229
|
-
|
230
|
-
ran.should == false
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
describe "should_not raise_error(NamedError, error_message) { |err| ... }" do
|
235
|
-
it "passes if nothing is raised" do
|
236
|
-
ran = false
|
237
|
-
|
238
|
-
lambda {}.should_not raise_error(RuntimeError, "example message") { |err|
|
239
|
-
ran = true
|
240
|
-
}
|
241
|
-
|
242
|
-
ran.should == false
|
243
|
-
end
|
244
|
-
|
245
|
-
it "passes if a different error is raised" do
|
246
|
-
ran = false
|
247
|
-
|
248
|
-
lambda { raise }.should_not raise_error(NameError, "example message") { |err|
|
249
|
-
ran = true
|
250
|
-
}
|
251
|
-
|
252
|
-
ran.should == false
|
253
|
-
end
|
254
|
-
|
255
|
-
it "passes if same error is raised with different message" do
|
256
|
-
ran = false
|
257
|
-
|
258
|
-
lambda {
|
259
|
-
raise RuntimeError.new("not the example message")
|
260
|
-
}.should_not raise_error(RuntimeError, "example message") { |err|
|
261
|
-
ran = true
|
262
|
-
}
|
263
|
-
|
264
|
-
ran.should == false
|
265
|
-
end
|
266
|
-
|
267
|
-
it "fails if named error is raised with same message" do
|
268
|
-
ran = false
|
269
|
-
|
270
|
-
lambda {
|
271
|
-
lambda {
|
272
|
-
raise "example message"
|
273
|
-
}.should_not raise_error(RuntimeError, "example message") { |err|
|
274
|
-
ran = true
|
275
|
-
}
|
276
|
-
}.should fail_with("expected no RuntimeError with \"example message\", got #<RuntimeError: example message>")
|
277
|
-
|
278
|
-
ran.should == false
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
describe "should_not raise_error(NamedError, error_message) with String" do
|
283
|
-
it "passes if nothing is raised" do
|
284
|
-
lambda {}.should_not raise_error(RuntimeError, "example message")
|
285
|
-
end
|
286
|
-
|
287
|
-
it "passes if a different error is raised" do
|
288
|
-
lambda { raise }.should_not raise_error(NameError, "example message")
|
289
|
-
end
|
290
|
-
|
291
|
-
it "passes if same error is raised with different message" do
|
292
|
-
lambda { raise RuntimeError.new("not the example message") }.should_not raise_error(RuntimeError, "example message")
|
293
|
-
end
|
294
|
-
|
295
|
-
it "fails if named error is raised with same message" do
|
296
|
-
lambda {
|
297
|
-
lambda { raise "example message" }.should_not raise_error(RuntimeError, "example message")
|
298
|
-
}.should fail_with("expected no RuntimeError with \"example message\", got #<RuntimeError: example message>")
|
299
|
-
end
|
300
|
-
end
|
301
|
-
|
302
|
-
describe "should raise_error(NamedError, error_message) with Regexp" do
|
303
|
-
it "passes if named error is raised with matching message" do
|
304
|
-
lambda { raise "example message" }.should raise_error(RuntimeError, /ample mess/)
|
305
|
-
end
|
306
|
-
|
307
|
-
it "fails if nothing is raised" do
|
308
|
-
lambda {
|
309
|
-
lambda {}.should raise_error(RuntimeError, /ample mess/)
|
310
|
-
}.should fail_with("expected RuntimeError with message matching /ample mess/ but nothing was raised")
|
311
|
-
end
|
312
|
-
|
313
|
-
it "fails if incorrect error is raised" do
|
314
|
-
lambda {
|
315
|
-
lambda { raise RuntimeError, "example message" }.should raise_error(NameError, /ample mess/)
|
316
|
-
}.should fail_with("expected NameError with message matching /ample mess/, got #<RuntimeError: example message>")
|
317
|
-
end
|
318
|
-
|
319
|
-
it "fails if correct error is raised with incorrect message" do
|
320
|
-
lambda {
|
321
|
-
lambda { raise RuntimeError.new("not the example message") }.should raise_error(RuntimeError, /less than ample mess/)
|
322
|
-
}.should fail_with("expected RuntimeError with message matching /less than ample mess/, got #<RuntimeError: not the example message>")
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
|
-
describe "should_not raise_error(NamedError, error_message) with Regexp" do
|
327
|
-
it "passes if nothing is raised" do
|
328
|
-
lambda {}.should_not raise_error(RuntimeError, /ample mess/)
|
329
|
-
end
|
330
|
-
|
331
|
-
it "passes if a different error is raised" do
|
332
|
-
lambda { raise }.should_not raise_error(NameError, /ample mess/)
|
333
|
-
end
|
334
|
-
|
335
|
-
it "passes if same error is raised with non-matching message" do
|
336
|
-
lambda { raise RuntimeError.new("non matching message") }.should_not raise_error(RuntimeError, /ample mess/)
|
337
|
-
end
|
338
|
-
|
339
|
-
it "fails if named error is raised with matching message" do
|
340
|
-
lambda {
|
341
|
-
lambda { raise "example message" }.should_not raise_error(RuntimeError, /ample mess/)
|
342
|
-
}.should fail_with("expected no RuntimeError with message matching /ample mess/, got #<RuntimeError: example message>")
|
343
|
-
end
|
344
|
-
end
|
@@ -1,295 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "should respond_to(:sym)" do
|
4
|
-
it_behaves_like "an RSpec matcher", :valid_value => "s", :invalid_value => 5 do
|
5
|
-
let(:matcher) { respond_to(:upcase) }
|
6
|
-
end
|
7
|
-
|
8
|
-
it "passes if target responds to :sym" do
|
9
|
-
Object.new.should respond_to(:methods)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "fails if target does not respond to :sym" do
|
13
|
-
lambda {
|
14
|
-
"this string".should respond_to(:some_method)
|
15
|
-
}.should fail_with(%q|expected "this string" to respond to :some_method|)
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "should respond_to(:sym).with(1).argument" do
|
21
|
-
it "passes if target responds to :sym with 1 arg" do
|
22
|
-
obj = Object.new
|
23
|
-
def obj.foo(arg); end
|
24
|
-
obj.should respond_to(:foo).with(1).argument
|
25
|
-
end
|
26
|
-
|
27
|
-
it "passes if target responds to any number of arguments" do
|
28
|
-
obj = Object.new
|
29
|
-
def obj.foo(*args); end
|
30
|
-
obj.should respond_to(:foo).with(1).argument
|
31
|
-
end
|
32
|
-
|
33
|
-
it "passes if target responds to one or more arguments" do
|
34
|
-
obj = Object.new
|
35
|
-
def obj.foo(a, *args); end
|
36
|
-
obj.should respond_to(:foo).with(1).argument
|
37
|
-
end
|
38
|
-
|
39
|
-
it "fails if target does not respond to :sym" do
|
40
|
-
obj = Object.new
|
41
|
-
lambda {
|
42
|
-
obj.should respond_to(:some_method).with(1).argument
|
43
|
-
}.should fail_with(/expected .* to respond to :some_method/)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "fails if :sym expects 0 args" do
|
47
|
-
obj = Object.new
|
48
|
-
def obj.foo; end
|
49
|
-
lambda {
|
50
|
-
obj.should respond_to(:foo).with(1).argument
|
51
|
-
}.should fail_with(/expected #<Object.*> to respond to :foo with 1 argument/)
|
52
|
-
end
|
53
|
-
|
54
|
-
it "fails if :sym expects 2 args" do
|
55
|
-
obj = Object.new
|
56
|
-
def obj.foo(arg, arg2); end
|
57
|
-
lambda {
|
58
|
-
obj.should respond_to(:foo).with(1).argument
|
59
|
-
}.should fail_with(/expected #<Object.*> to respond to :foo with 1 argument/)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "fails if :sym expects 2 or more args" do
|
63
|
-
obj = Object.new
|
64
|
-
def obj.foo(arg, arg2, *args); end
|
65
|
-
lambda {
|
66
|
-
obj.should respond_to(:foo).with(1).argument
|
67
|
-
}.should fail_with(/expected #<Object.*> to respond to :foo with 1 argument/)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe "should respond_to(message1, message2)" do
|
72
|
-
|
73
|
-
it "passes if target responds to both messages" do
|
74
|
-
Object.new.should respond_to('methods', 'inspect')
|
75
|
-
end
|
76
|
-
|
77
|
-
it "fails if target does not respond to first message" do
|
78
|
-
lambda {
|
79
|
-
Object.new.should respond_to('method_one', 'inspect')
|
80
|
-
}.should fail_with(/expected #<Object:.*> to respond to "method_one"/)
|
81
|
-
end
|
82
|
-
|
83
|
-
it "fails if target does not respond to second message" do
|
84
|
-
lambda {
|
85
|
-
Object.new.should respond_to('inspect', 'method_one')
|
86
|
-
}.should fail_with(/expected #<Object:.*> to respond to "method_one"/)
|
87
|
-
end
|
88
|
-
|
89
|
-
it "fails if target does not respond to either message" do
|
90
|
-
lambda {
|
91
|
-
Object.new.should respond_to('method_one', 'method_two')
|
92
|
-
}.should fail_with(/expected #<Object:.*> to respond to "method_one", "method_two"/)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe "should respond_to(:sym).with(2).arguments" do
|
97
|
-
it "passes if target responds to :sym with 2 args" do
|
98
|
-
obj = Object.new
|
99
|
-
def obj.foo(a1, a2); end
|
100
|
-
obj.should respond_to(:foo).with(2).arguments
|
101
|
-
end
|
102
|
-
|
103
|
-
it "passes if target responds to any number of arguments" do
|
104
|
-
obj = Object.new
|
105
|
-
def obj.foo(*args); end
|
106
|
-
obj.should respond_to(:foo).with(2).arguments
|
107
|
-
end
|
108
|
-
|
109
|
-
it "passes if target responds to one or more arguments" do
|
110
|
-
obj = Object.new
|
111
|
-
def obj.foo(a, *args); end
|
112
|
-
obj.should respond_to(:foo).with(2).arguments
|
113
|
-
end
|
114
|
-
|
115
|
-
it "passes if target responds to two or more arguments" do
|
116
|
-
obj = Object.new
|
117
|
-
def obj.foo(a, b, *args); end
|
118
|
-
obj.should respond_to(:foo).with(2).arguments
|
119
|
-
end
|
120
|
-
|
121
|
-
it "fails if target does not respond to :sym" do
|
122
|
-
obj = Object.new
|
123
|
-
lambda {
|
124
|
-
obj.should respond_to(:some_method).with(2).arguments
|
125
|
-
}.should fail_with(/expected .* to respond to :some_method/)
|
126
|
-
end
|
127
|
-
|
128
|
-
it "fails if :sym expects 0 args" do
|
129
|
-
obj = Object.new
|
130
|
-
def obj.foo; end
|
131
|
-
lambda {
|
132
|
-
obj.should respond_to(:foo).with(2).arguments
|
133
|
-
}.should fail_with(/expected #<Object.*> to respond to :foo with 2 arguments/)
|
134
|
-
end
|
135
|
-
|
136
|
-
it "fails if :sym expects 1 args" do
|
137
|
-
obj = Object.new
|
138
|
-
def obj.foo(arg); end
|
139
|
-
lambda {
|
140
|
-
obj.should respond_to(:foo).with(2).arguments
|
141
|
-
}.should fail_with(/expected #<Object.*> to respond to :foo with 2 arguments/)
|
142
|
-
end
|
143
|
-
|
144
|
-
it "fails if :sym expects 3 or more args" do
|
145
|
-
obj = Object.new
|
146
|
-
def obj.foo(arg, arg2, arg3, *args); end
|
147
|
-
lambda {
|
148
|
-
obj.should respond_to(:foo).with(2).arguments
|
149
|
-
}.should fail_with(/expected #<Object.*> to respond to :foo with 2 arguments/)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
describe "should_not respond_to(:sym)" do
|
154
|
-
|
155
|
-
it "passes if target does not respond to :sym" do
|
156
|
-
Object.new.should_not respond_to(:some_method)
|
157
|
-
end
|
158
|
-
|
159
|
-
it "fails if target responds to :sym" do
|
160
|
-
lambda {
|
161
|
-
Object.new.should_not respond_to(:methods)
|
162
|
-
}.should fail_with(/expected #<Object:.*> not to respond to :methods/)
|
163
|
-
end
|
164
|
-
|
165
|
-
end
|
166
|
-
|
167
|
-
describe "should_not respond_to(:sym).with(1).argument" do
|
168
|
-
it "fails if target responds to :sym with 1 arg" do
|
169
|
-
obj = Object.new
|
170
|
-
def obj.foo(arg); end
|
171
|
-
lambda {
|
172
|
-
obj.should_not respond_to(:foo).with(1).argument
|
173
|
-
}.should fail_with(/expected #<Object:.*> not to respond to :foo with 1 argument/)
|
174
|
-
end
|
175
|
-
|
176
|
-
it "fails if target responds to :sym with any number of args" do
|
177
|
-
obj = Object.new
|
178
|
-
def obj.foo(*args); end
|
179
|
-
lambda {
|
180
|
-
obj.should_not respond_to(:foo).with(1).argument
|
181
|
-
}.should fail_with(/expected #<Object:.*> not to respond to :foo with 1 argument/)
|
182
|
-
end
|
183
|
-
|
184
|
-
it "fails if target responds to :sym with one or more args" do
|
185
|
-
obj = Object.new
|
186
|
-
def obj.foo(a, *args); end
|
187
|
-
lambda {
|
188
|
-
obj.should_not respond_to(:foo).with(1).argument
|
189
|
-
}.should fail_with(/expected #<Object:.*> not to respond to :foo with 1 argument/)
|
190
|
-
end
|
191
|
-
|
192
|
-
it "passes if target does not respond to :sym" do
|
193
|
-
obj = Object.new
|
194
|
-
obj.should_not respond_to(:some_method).with(1).argument
|
195
|
-
end
|
196
|
-
|
197
|
-
it "passes if :sym expects 0 args" do
|
198
|
-
obj = Object.new
|
199
|
-
def obj.foo; end
|
200
|
-
obj.should_not respond_to(:foo).with(1).argument
|
201
|
-
end
|
202
|
-
|
203
|
-
it "passes if :sym expects 2 args" do
|
204
|
-
obj = Object.new
|
205
|
-
def obj.foo(arg, arg2); end
|
206
|
-
obj.should_not respond_to(:foo).with(1).argument
|
207
|
-
end
|
208
|
-
|
209
|
-
it "passes if :sym expects 2 or more args" do
|
210
|
-
obj = Object.new
|
211
|
-
def obj.foo(arg, arg2, *args); end
|
212
|
-
obj.should_not respond_to(:foo).with(1).argument
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
describe "should_not respond_to(message1, message2)" do
|
217
|
-
it "passes if target does not respond to either message1 or message2" do
|
218
|
-
Object.new.should_not respond_to(:some_method, :some_other_method)
|
219
|
-
end
|
220
|
-
|
221
|
-
it "fails if target responds to message1 but not message2" do
|
222
|
-
lambda {
|
223
|
-
Object.new.should_not respond_to(:object_id, :some_method)
|
224
|
-
}.should fail_with(/expected #<Object:.*> not to respond to :object_id/)
|
225
|
-
end
|
226
|
-
|
227
|
-
it "fails if target responds to message2 but not message1" do
|
228
|
-
lambda {
|
229
|
-
Object.new.should_not respond_to(:some_method, :object_id)
|
230
|
-
}.should fail_with(/expected #<Object:.*> not to respond to :object_id/)
|
231
|
-
end
|
232
|
-
|
233
|
-
it "fails if target responds to both message1 and message2" do
|
234
|
-
lambda {
|
235
|
-
Object.new.should_not respond_to(:class, :object_id)
|
236
|
-
}.should fail_with(/expected #<Object:.*> not to respond to :class, :object_id/)
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
describe "should_not respond_to(:sym).with(2).arguments" do
|
241
|
-
it "fails if target responds to :sym with 2 args" do
|
242
|
-
obj = Object.new
|
243
|
-
def obj.foo(a1, a2); end
|
244
|
-
lambda {
|
245
|
-
obj.should_not respond_to(:foo).with(2).arguments
|
246
|
-
}.should fail_with(/expected .* not to respond to :foo with 2 arguments/)
|
247
|
-
end
|
248
|
-
|
249
|
-
it "fails if target responds to :sym with any number args" do
|
250
|
-
obj = Object.new
|
251
|
-
def obj.foo(*args); end
|
252
|
-
lambda {
|
253
|
-
obj.should_not respond_to(:foo).with(2).arguments
|
254
|
-
}.should fail_with(/expected .* not to respond to :foo with 2 arguments/)
|
255
|
-
end
|
256
|
-
|
257
|
-
it "fails if target responds to :sym with one or more args" do
|
258
|
-
obj = Object.new
|
259
|
-
def obj.foo(a, *args); end
|
260
|
-
lambda {
|
261
|
-
obj.should_not respond_to(:foo).with(2).arguments
|
262
|
-
}.should fail_with(/expected .* not to respond to :foo with 2 arguments/)
|
263
|
-
end
|
264
|
-
|
265
|
-
it "fails if target responds to :sym with two or more args" do
|
266
|
-
obj = Object.new
|
267
|
-
def obj.foo(a, b, *args); end
|
268
|
-
lambda {
|
269
|
-
obj.should_not respond_to(:foo).with(2).arguments
|
270
|
-
}.should fail_with(/expected .* not to respond to :foo with 2 arguments/)
|
271
|
-
end
|
272
|
-
|
273
|
-
it "passes if target does not respond to :sym" do
|
274
|
-
obj = Object.new
|
275
|
-
obj.should_not respond_to(:some_method).with(2).arguments
|
276
|
-
end
|
277
|
-
|
278
|
-
it "passes if :sym expects 0 args" do
|
279
|
-
obj = Object.new
|
280
|
-
def obj.foo; end
|
281
|
-
obj.should_not respond_to(:foo).with(2).arguments
|
282
|
-
end
|
283
|
-
|
284
|
-
it "passes if :sym expects 2 args" do
|
285
|
-
obj = Object.new
|
286
|
-
def obj.foo(arg); end
|
287
|
-
obj.should_not respond_to(:foo).with(2).arguments
|
288
|
-
end
|
289
|
-
|
290
|
-
it "passes if :sym expects 3 or more args" do
|
291
|
-
obj = Object.new
|
292
|
-
def obj.foo(a, b, c, *arg); end
|
293
|
-
obj.should_not respond_to(:foo).with(2).arguments
|
294
|
-
end
|
295
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "should satisfy { block }" do
|
4
|
-
it_behaves_like "an RSpec matcher", :valid_value => true, :invalid_value => false do
|
5
|
-
let(:matcher) { satisfy { |v| v } }
|
6
|
-
end
|
7
|
-
|
8
|
-
it "describes itself" do
|
9
|
-
satisfy.description.should eq("satisfy block")
|
10
|
-
end
|
11
|
-
|
12
|
-
it "passes if block returns true" do
|
13
|
-
true.should satisfy { |val| val }
|
14
|
-
true.should satisfy do |val|
|
15
|
-
val
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
it "fails if block returns false" do
|
20
|
-
lambda {
|
21
|
-
false.should satisfy { |val| val }
|
22
|
-
}.should fail_with("expected false to satisfy block")
|
23
|
-
lambda do
|
24
|
-
false.should satisfy do |val|
|
25
|
-
val
|
26
|
-
end
|
27
|
-
end.should fail_with("expected false to satisfy block")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "should_not satisfy { block }" do
|
32
|
-
it "passes if block returns false" do
|
33
|
-
false.should_not satisfy { |val| val }
|
34
|
-
false.should_not satisfy do |val|
|
35
|
-
val
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
it "fails if block returns true" do
|
40
|
-
lambda {
|
41
|
-
true.should_not satisfy { |val| val }
|
42
|
-
}.should fail_with("expected true not to satisfy block")
|
43
|
-
end
|
44
|
-
end
|