rspec-expectations 2.11.3 → 3.11.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.
Files changed (152) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/.document +1 -1
  4. data/.yardopts +1 -1
  5. data/Changelog.md +1026 -21
  6. data/{License.txt → LICENSE.md} +5 -3
  7. data/README.md +174 -78
  8. data/lib/rspec/expectations/block_snippet_extractor.rb +253 -0
  9. data/lib/rspec/expectations/configuration.rb +230 -0
  10. data/lib/rspec/expectations/expectation_target.rb +130 -55
  11. data/lib/rspec/expectations/fail_with.rb +17 -33
  12. data/lib/rspec/expectations/failure_aggregator.rb +212 -0
  13. data/lib/rspec/expectations/handler.rb +163 -29
  14. data/lib/rspec/expectations/minitest_integration.rb +58 -0
  15. data/lib/rspec/expectations/syntax.rb +68 -54
  16. data/lib/rspec/expectations/version.rb +1 -1
  17. data/lib/rspec/expectations.rb +59 -24
  18. data/lib/rspec/matchers/aliased_matcher.rb +116 -0
  19. data/lib/rspec/matchers/built_in/all.rb +86 -0
  20. data/lib/rspec/matchers/built_in/base_matcher.rb +150 -20
  21. data/lib/rspec/matchers/built_in/be.rb +115 -109
  22. data/lib/rspec/matchers/built_in/be_between.rb +77 -0
  23. data/lib/rspec/matchers/built_in/be_instance_of.rb +16 -1
  24. data/lib/rspec/matchers/built_in/be_kind_of.rb +10 -1
  25. data/lib/rspec/matchers/built_in/be_within.rb +43 -17
  26. data/lib/rspec/matchers/built_in/change.rb +392 -75
  27. data/lib/rspec/matchers/built_in/compound.rb +290 -0
  28. data/lib/rspec/matchers/built_in/contain_exactly.rb +302 -0
  29. data/lib/rspec/matchers/built_in/count_expectation.rb +169 -0
  30. data/lib/rspec/matchers/built_in/cover.rb +3 -0
  31. data/lib/rspec/matchers/built_in/eq.rb +26 -8
  32. data/lib/rspec/matchers/built_in/eql.rb +19 -8
  33. data/lib/rspec/matchers/built_in/equal.rb +56 -19
  34. data/lib/rspec/matchers/built_in/exist.rb +74 -10
  35. data/lib/rspec/matchers/built_in/has.rb +141 -22
  36. data/lib/rspec/matchers/built_in/have_attributes.rb +114 -0
  37. data/lib/rspec/matchers/built_in/include.rb +175 -20
  38. data/lib/rspec/matchers/built_in/match.rb +95 -1
  39. data/lib/rspec/matchers/built_in/operators.rb +128 -0
  40. data/lib/rspec/matchers/built_in/output.rb +207 -0
  41. data/lib/rspec/matchers/built_in/raise_error.rb +212 -38
  42. data/lib/rspec/matchers/built_in/respond_to.rb +155 -29
  43. data/lib/rspec/matchers/built_in/satisfy.rb +39 -9
  44. data/lib/rspec/matchers/built_in/start_or_end_with.rb +94 -0
  45. data/lib/rspec/matchers/built_in/throw_symbol.rb +58 -14
  46. data/lib/rspec/matchers/built_in/yield.rb +252 -98
  47. data/lib/rspec/matchers/built_in.rb +47 -33
  48. data/lib/rspec/matchers/composable.rb +171 -0
  49. data/lib/rspec/matchers/dsl.rb +530 -10
  50. data/lib/rspec/matchers/english_phrasing.rb +58 -0
  51. data/lib/rspec/matchers/expecteds_for_multiple_diffs.rb +82 -0
  52. data/lib/rspec/matchers/fail_matchers.rb +42 -0
  53. data/lib/rspec/matchers/generated_descriptions.rb +15 -10
  54. data/lib/rspec/matchers/matcher_delegator.rb +35 -0
  55. data/lib/rspec/matchers/matcher_protocol.rb +105 -0
  56. data/lib/rspec/matchers.rb +604 -252
  57. data.tar.gz.sig +0 -0
  58. metadata +178 -278
  59. metadata.gz.sig +0 -0
  60. data/features/README.md +0 -49
  61. data/features/Upgrade.md +0 -53
  62. data/features/built_in_matchers/README.md +0 -90
  63. data/features/built_in_matchers/be.feature +0 -173
  64. data/features/built_in_matchers/be_within.feature +0 -46
  65. data/features/built_in_matchers/cover.feature +0 -45
  66. data/features/built_in_matchers/end_with.feature +0 -46
  67. data/features/built_in_matchers/equality.feature +0 -145
  68. data/features/built_in_matchers/exist.feature +0 -43
  69. data/features/built_in_matchers/expect_change.feature +0 -59
  70. data/features/built_in_matchers/expect_error.feature +0 -138
  71. data/features/built_in_matchers/have.feature +0 -103
  72. data/features/built_in_matchers/include.feature +0 -121
  73. data/features/built_in_matchers/match.feature +0 -50
  74. data/features/built_in_matchers/operators.feature +0 -221
  75. data/features/built_in_matchers/predicates.feature +0 -128
  76. data/features/built_in_matchers/respond_to.feature +0 -78
  77. data/features/built_in_matchers/satisfy.feature +0 -31
  78. data/features/built_in_matchers/start_with.feature +0 -46
  79. data/features/built_in_matchers/throw_symbol.feature +0 -85
  80. data/features/built_in_matchers/types.feature +0 -114
  81. data/features/built_in_matchers/yield.feature +0 -146
  82. data/features/custom_matchers/access_running_example.feature +0 -53
  83. data/features/custom_matchers/define_diffable_matcher.feature +0 -27
  84. data/features/custom_matchers/define_matcher.feature +0 -340
  85. data/features/custom_matchers/define_matcher_outside_rspec.feature +0 -38
  86. data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
  87. data/features/customized_message.feature +0 -22
  88. data/features/diffing.feature +0 -85
  89. data/features/implicit_docstrings.feature +0 -52
  90. data/features/step_definitions/additional_cli_steps.rb +0 -22
  91. data/features/support/env.rb +0 -5
  92. data/features/syntax_configuration.feature +0 -68
  93. data/features/test_frameworks/test_unit.feature +0 -46
  94. data/lib/rspec/expectations/deprecation.rb +0 -38
  95. data/lib/rspec/expectations/differ.rb +0 -81
  96. data/lib/rspec/expectations/errors.rb +0 -9
  97. data/lib/rspec/expectations/extensions/array.rb +0 -9
  98. data/lib/rspec/expectations/extensions/object.rb +0 -39
  99. data/lib/rspec/expectations/extensions.rb +0 -2
  100. data/lib/rspec/matchers/be_close.rb +0 -9
  101. data/lib/rspec/matchers/built_in/have.rb +0 -108
  102. data/lib/rspec/matchers/built_in/match_array.rb +0 -45
  103. data/lib/rspec/matchers/built_in/start_and_end_with.rb +0 -48
  104. data/lib/rspec/matchers/compatibility.rb +0 -14
  105. data/lib/rspec/matchers/configuration.rb +0 -66
  106. data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
  107. data/lib/rspec/matchers/matcher.rb +0 -299
  108. data/lib/rspec/matchers/method_missing.rb +0 -12
  109. data/lib/rspec/matchers/operator_matcher.rb +0 -84
  110. data/lib/rspec/matchers/pretty.rb +0 -60
  111. data/lib/rspec-expectations.rb +0 -1
  112. data/spec/rspec/expectations/differ_spec.rb +0 -153
  113. data/spec/rspec/expectations/expectation_target_spec.rb +0 -65
  114. data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
  115. data/spec/rspec/expectations/fail_with_spec.rb +0 -70
  116. data/spec/rspec/expectations/handler_spec.rb +0 -206
  117. data/spec/rspec/matchers/base_matcher_spec.rb +0 -60
  118. data/spec/rspec/matchers/be_close_spec.rb +0 -22
  119. data/spec/rspec/matchers/be_instance_of_spec.rb +0 -40
  120. data/spec/rspec/matchers/be_kind_of_spec.rb +0 -37
  121. data/spec/rspec/matchers/be_spec.rb +0 -452
  122. data/spec/rspec/matchers/be_within_spec.rb +0 -80
  123. data/spec/rspec/matchers/change_spec.rb +0 -528
  124. data/spec/rspec/matchers/configuration_spec.rb +0 -202
  125. data/spec/rspec/matchers/cover_spec.rb +0 -69
  126. data/spec/rspec/matchers/description_generation_spec.rb +0 -176
  127. data/spec/rspec/matchers/dsl_spec.rb +0 -57
  128. data/spec/rspec/matchers/eq_spec.rb +0 -54
  129. data/spec/rspec/matchers/eql_spec.rb +0 -41
  130. data/spec/rspec/matchers/equal_spec.rb +0 -60
  131. data/spec/rspec/matchers/exist_spec.rb +0 -110
  132. data/spec/rspec/matchers/has_spec.rb +0 -118
  133. data/spec/rspec/matchers/have_spec.rb +0 -461
  134. data/spec/rspec/matchers/include_spec.rb +0 -367
  135. data/spec/rspec/matchers/match_array_spec.rb +0 -124
  136. data/spec/rspec/matchers/match_spec.rb +0 -61
  137. data/spec/rspec/matchers/matcher_spec.rb +0 -434
  138. data/spec/rspec/matchers/matchers_spec.rb +0 -31
  139. data/spec/rspec/matchers/method_missing_spec.rb +0 -24
  140. data/spec/rspec/matchers/operator_matcher_spec.rb +0 -221
  141. data/spec/rspec/matchers/raise_error_spec.rb +0 -344
  142. data/spec/rspec/matchers/respond_to_spec.rb +0 -295
  143. data/spec/rspec/matchers/satisfy_spec.rb +0 -44
  144. data/spec/rspec/matchers/start_with_end_with_spec.rb +0 -182
  145. data/spec/rspec/matchers/throw_symbol_spec.rb +0 -116
  146. data/spec/rspec/matchers/yield_spec.rb +0 -402
  147. data/spec/spec_helper.rb +0 -27
  148. data/spec/support/classes.rb +0 -56
  149. data/spec/support/in_sub_process.rb +0 -31
  150. data/spec/support/matchers.rb +0 -22
  151. data/spec/support/ruby_version.rb +0 -10
  152. data/spec/support/shared_examples.rb +0 -13
@@ -1,452 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "should be_predicate" do
4
- it "passes when actual returns true for :predicate?" do
5
- actual = stub("actual", :happy? => true)
6
- actual.should be_happy
7
- end
8
-
9
- it "passes when actual returns true for :predicates? (present tense)" do
10
- actual = stub("actual", :exists? => true, :exist? => true)
11
- actual.should be_exist
12
- end
13
-
14
- it "fails when actual returns false for :predicate?" do
15
- actual = stub("actual", :happy? => false)
16
- lambda {
17
- actual.should be_happy
18
- }.should fail_with("expected happy? to return true, got false")
19
- end
20
-
21
- it "fails when actual returns false for :predicate?" do
22
- actual = stub("actual", :happy? => nil)
23
- lambda {
24
- actual.should be_happy
25
- }.should fail_with("expected happy? to return true, got nil")
26
- end
27
-
28
- it "fails when actual does not respond to :predicate?" do
29
- lambda {
30
- Object.new.should be_happy
31
- }.should raise_error(NameError, /happy\?/)
32
- end
33
-
34
- it "fails on error other than NameError" do
35
- actual = stub("actual")
36
- actual.should_receive(:foo?).and_raise("aaaah")
37
- lambda {
38
- actual.should be_foo
39
- }.should raise_error(/aaaah/)
40
- end
41
-
42
- it "fails on error other than NameError (with the present tense predicate)" do
43
- actual = Object.new
44
- actual.should_receive(:foos?).and_raise("aaaah")
45
- lambda {
46
- actual.should be_foo
47
- }.should raise_error(/aaaah/)
48
- end
49
- end
50
-
51
- describe "should_not be_predicate" do
52
- it "passes when actual returns false for :sym?" do
53
- actual = stub("actual", :happy? => false)
54
- actual.should_not be_happy
55
- end
56
-
57
- it "passes when actual returns nil for :sym?" do
58
- actual = stub("actual", :happy? => nil)
59
- actual.should_not be_happy
60
- end
61
-
62
- it "fails when actual returns true for :sym?" do
63
- actual = stub("actual", :happy? => true)
64
- lambda {
65
- actual.should_not be_happy
66
- }.should fail_with("expected happy? to return false, got true")
67
- end
68
-
69
- it "fails when actual does not respond to :sym?" do
70
- lambda {
71
- Object.new.should_not be_happy
72
- }.should raise_error(NameError)
73
- end
74
- end
75
-
76
- describe "should be_predicate(*args)" do
77
- it "passes when actual returns true for :predicate?(*args)" do
78
- actual = mock("actual")
79
- actual.should_receive(:older_than?).with(3).and_return(true)
80
- actual.should be_older_than(3)
81
- end
82
-
83
- it "fails when actual returns false for :predicate?(*args)" do
84
- actual = mock("actual")
85
- actual.should_receive(:older_than?).with(3).and_return(false)
86
- lambda {
87
- actual.should be_older_than(3)
88
- }.should fail_with("expected older_than?(3) to return true, got false")
89
- end
90
-
91
- it "fails when actual does not respond to :predicate?" do
92
- lambda {
93
- Object.new.should be_older_than(3)
94
- }.should raise_error(NameError)
95
- end
96
- end
97
-
98
- describe "should_not be_predicate(*args)" do
99
- it "passes when actual returns false for :predicate?(*args)" do
100
- actual = mock("actual")
101
- actual.should_receive(:older_than?).with(3).and_return(false)
102
- actual.should_not be_older_than(3)
103
- end
104
-
105
- it "fails when actual returns true for :predicate?(*args)" do
106
- actual = mock("actual")
107
- actual.should_receive(:older_than?).with(3).and_return(true)
108
- lambda {
109
- actual.should_not be_older_than(3)
110
- }.should fail_with("expected older_than?(3) to return false, got true")
111
- end
112
-
113
- it "fails when actual does not respond to :predicate?" do
114
- lambda {
115
- Object.new.should_not be_older_than(3)
116
- }.should raise_error(NameError)
117
- end
118
- end
119
-
120
- describe "should be_predicate(&block)" do
121
- it "passes 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 "fails 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 "fails 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 "passes 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 "fails 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 "fails 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 "passes 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 "fails 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 "fails 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 "passes 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 "fails 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 "fails 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
-
228
- describe "should be_true" do
229
- it "passes when actual equal?(true)" do
230
- true.should be_true
231
- end
232
-
233
- it "passes when actual is 1" do
234
- 1.should be_true
235
- end
236
-
237
- it "fails when actual equal?(false)" do
238
- lambda {
239
- false.should be_true
240
- }.should fail_with("expected: true value\n got: false")
241
- end
242
- end
243
-
244
- describe "should be_false" do
245
- it "passes when actual equal?(false)" do
246
- false.should be_false
247
- end
248
-
249
- it "passes when actual equal?(nil)" do
250
- nil.should be_false
251
- end
252
-
253
- it "fails when actual equal?(true)" do
254
- lambda {
255
- true.should be_false
256
- }.should fail_with("expected: false value\n got: true")
257
- end
258
- end
259
-
260
- describe "should be_nil" do
261
- it "passes when actual is nil" do
262
- nil.should be_nil
263
- end
264
-
265
- it "fails when actual is not nil" do
266
- lambda {
267
- :not_nil.should be_nil
268
- }.should fail_with(/^expected: nil/)
269
- end
270
- end
271
-
272
- describe "should_not be_nil" do
273
- it "passes when actual is not nil" do
274
- :not_nil.should_not be_nil
275
- end
276
-
277
- it "fails when actual is nil" do
278
- lambda {
279
- nil.should_not be_nil
280
- }.should fail_with(/^expected: not nil/)
281
- end
282
- end
283
-
284
- describe "should be <" do
285
- it "passes when < operator returns true" do
286
- 3.should be < 4
287
- end
288
-
289
- it "fails when < operator returns false" do
290
- lambda { 3.should be < 3 }.should fail_with("expected: < 3\n got: 3")
291
- end
292
-
293
- it "describes itself" do
294
- be.<(4).description.should == "be < 4"
295
- end
296
- end
297
-
298
- describe "should be <=" do
299
- it "passes when <= operator returns true" do
300
- 3.should be <= 4
301
- 4.should be <= 4
302
- end
303
-
304
- it "fails when <= operator returns false" do
305
- lambda { 3.should be <= 2 }.should fail_with("expected: <= 2\n got: 3")
306
- end
307
- end
308
-
309
- describe "should be >=" do
310
- it "passes when >= operator returns true" do
311
- 4.should be >= 4
312
- 5.should be >= 4
313
- end
314
-
315
- it "fails when >= operator returns false" do
316
- lambda { 3.should be >= 4 }.should fail_with("expected: >= 4\n got: 3")
317
- end
318
- end
319
-
320
- describe "should be >" do
321
- it "passes when > operator returns true" do
322
- 5.should be > 4
323
- end
324
-
325
- it "fails when > operator returns false" do
326
- lambda { 3.should be > 4 }.should fail_with("expected: > 4\n got: 3")
327
- end
328
- end
329
-
330
- describe "should be ==" do
331
- it "passes when == operator returns true" do
332
- 5.should be == 5
333
- end
334
-
335
- it "fails when == operator returns false" do
336
- lambda { 3.should be == 4 }.should fail_with("expected: == 4\n got: 3")
337
- end
338
- end
339
-
340
- describe "should be ===" do
341
- it "passes when === operator returns true" do
342
- Hash.should be === Hash.new
343
- end
344
-
345
- it "fails when === operator returns false" do
346
- lambda { Hash.should be === "not a hash" }.should fail_with(%[expected: === "not a hash"\n got: Hash])
347
- end
348
- end
349
-
350
- describe "should_not with operators" do
351
- it "coaches user to stop using operators with should_not" do
352
- lambda {
353
- 5.should_not be < 6
354
- }.should raise_error(/not only FAILED,\nit is a bit confusing./m)
355
- end
356
- end
357
-
358
- describe "should be" do
359
- it "passes if actual is truthy" do
360
- true.should be
361
- 1.should be
362
- end
363
-
364
- it "fails if actual is false" do
365
- lambda {false.should be}.should fail_with("expected false to evaluate to true")
366
- end
367
-
368
- it "fails if actual is nil" do
369
- lambda {nil.should be}.should fail_with("expected nil to evaluate to true")
370
- end
371
-
372
- it "describes itself" do
373
- be.description.should == "be"
374
- end
375
- end
376
-
377
- describe "should_not be" do
378
- it "passes if actual is falsy" do
379
- false.should_not be
380
- nil.should_not be
381
- end
382
-
383
- it "fails on true" do
384
- lambda {true.should_not be}.should fail_with("expected true to evaluate to false")
385
- end
386
- end
387
-
388
- describe "should be(value)" do
389
- it "delegates to equal" do
390
- self.should_receive(:equal).with(5)
391
- 5.should be(5)
392
- end
393
- end
394
-
395
- describe "should_not be(value)" do
396
- it "delegates to equal" do
397
- self.should_receive(:equal).with(4)
398
- 5.should_not be(4)
399
- end
400
- end
401
-
402
- describe "'should be' with operator" do
403
- it "includes 'be' in the description" do
404
- (be > 6).description.should =~ /be > 6/
405
- (be >= 6).description.should =~ /be >= 6/
406
- (be <= 6).description.should =~ /be <= 6/
407
- (be < 6).description.should =~ /be < 6/
408
- end
409
- end
410
-
411
-
412
- describe "arbitrary predicate with DelegateClass" do
413
- it "accesses methods defined in the delegating class (LH[#48])" do
414
- require 'delegate'
415
- class ArrayDelegate < DelegateClass(Array)
416
- def initialize(array)
417
- @internal_array = array
418
- super(@internal_array)
419
- end
420
-
421
- def large?
422
- @internal_array.size >= 5
423
- end
424
- end
425
-
426
- delegate = ArrayDelegate.new([1,2,3,4,5,6])
427
- delegate.should be_large
428
- end
429
- end
430
-
431
- describe "be_a, be_an" do
432
- it "passes when class matches" do
433
- "foobar".should be_a(String)
434
- [1,2,3].should be_an(Array)
435
- end
436
-
437
- it "fails when class does not match" do
438
- "foobar".should_not be_a(Hash)
439
- [1,2,3].should_not be_an(Integer)
440
- end
441
- end
442
-
443
- describe "be_an_instance_of" do
444
- it "passes when direct class matches" do
445
- 5.should be_an_instance_of(Fixnum)
446
- end
447
-
448
- it "fails when class is higher up hierarchy" do
449
- 5.should_not be_an_instance_of(Numeric)
450
- end
451
- end
452
-
@@ -1,80 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module RSpec
4
- module Matchers
5
- describe "[actual.should] be_within(delta).of(expected)" do
6
- it_behaves_like "an RSpec matcher", :valid_value => 5, :invalid_value => -5 do
7
- let(:matcher) { be_within(2).of(4.0) }
8
- end
9
-
10
- it "matches when actual == expected" do
11
- be_within(0.5).of(5.0).matches?(5.0).should be_true
12
- end
13
-
14
- it "matches when actual < (expected + delta)" do
15
- be_within(0.5).of(5.0).matches?(5.49).should be_true
16
- end
17
-
18
- it "matches when actual > (expected - delta)" do
19
- be_within(0.5).of(5.0).matches?(4.51).should be_true
20
- end
21
-
22
- it "matches when actual == (expected - delta)" do
23
- be_within(0.5).of(5.0).matches?(4.5).should be_true
24
- end
25
-
26
- it "does not match when actual < (expected - delta)" do
27
- be_within(0.5).of(5.0).matches?(4.49).should be_false
28
- end
29
-
30
- it "matches when actual == (expected + delta)" do
31
- be_within(0.5).of(5.0).matches?(5.5).should be_true
32
- end
33
-
34
- it "does not match when actual > (expected + delta)" do
35
- be_within(0.5).of(5.0).matches?(5.51).should be_false
36
- end
37
-
38
- it "provides a failure message for should" do
39
- #given
40
- matcher = be_within(0.5).of(5.0)
41
- #when
42
- matcher.matches?(5.51)
43
- #then
44
- matcher.failure_message_for_should.should == "expected 5.51 to be within 0.5 of 5.0"
45
- end
46
-
47
- it "provides a failure message for should not" do
48
- #given
49
- matcher = be_within(0.5).of(5.0)
50
- #when
51
- matcher.matches?(5.49)
52
- #then
53
- matcher.failure_message_for_should_not.should == "expected 5.49 not to be within 0.5 of 5.0"
54
- end
55
-
56
- it "works with Time" do
57
- Time.now.should be_within(0.1).of(Time.now)
58
- end
59
-
60
- it "provides a description" do
61
- matcher = be_within(0.5).of(5.0)
62
- matcher.matches?(5.1)
63
- matcher.description.should == "be within 0.5 of 5.0"
64
- end
65
-
66
- it "raises an error if no expected value is given" do
67
- matcher = be_within(0.5)
68
- expect { matcher.matches?(5.1) }.to raise_error(
69
- ArgumentError, /must set an expected value using #of/
70
- )
71
- end
72
-
73
- it "raises an error if the actual does not respond to :-" do
74
- expect { be_within(0.1).of(0).matches?(nil) }.to raise_error(
75
- ArgumentError, /The actual value \(nil\) must respond to `-`/
76
- )
77
- end
78
- end
79
- end
80
- end