rspec 0.3.2 → 0.4.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.
@@ -0,0 +1,144 @@
1
+ require 'test/unit'
2
+
3
+ require 'collection_owner'
4
+ require 'spec'
5
+
6
+ class ExpectationsForShouldHaveTest < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @owner = CollectionOwner.new
10
+ end
11
+
12
+ def set_length(number)
13
+ (1..number).each do |n|
14
+ @owner.add_to_collection_with_length_method(n.to_s)
15
+ end
16
+ end
17
+
18
+ def set_size(number)
19
+ (1..number).each do |n|
20
+ @owner.add_to_collection_with_size_method(n.to_s)
21
+ end
22
+ end
23
+
24
+ def test_should_have_should_pass_if_responds_to_length_and_has_correct_number
25
+ assert_nothing_raised do
26
+ set_length 3
27
+ @owner.should.have(3).items_in_collection_with_length_method
28
+ end
29
+ end
30
+
31
+ def test_should_have_should_pass_if_responds_to_size_and_has_correct_number
32
+ assert_nothing_raised do
33
+ set_size 7
34
+ @owner.should.have(7).items_in_collection_with_size_method
35
+ end
36
+ end
37
+
38
+ def test_should_have_should_fail_if_responds_to_length_and_has_wrong_number
39
+ assert_raise(Spec::Exceptions::ExpectationNotMetError) do
40
+ set_length 12
41
+ @owner.should.have(17).items_in_collection_with_length_method
42
+ end
43
+ end
44
+
45
+ def test_should_have_should_fail_if_responds_to_size_and_has_wrong_number
46
+ assert_raise(Spec::Exceptions::ExpectationNotMetError) do
47
+ set_size 6
48
+ @owner.should.have(2).items_in_collection_with_size_method
49
+ end
50
+ end
51
+
52
+ # at.least w/ length
53
+
54
+ def test_should_have_at_least_should_pass_if_responds_to_length_and_has_exact_number
55
+ assert_nothing_raised do
56
+ set_length 1
57
+ @owner.should.have.at.least(1).items_in_collection_with_length_method
58
+ end
59
+ end
60
+
61
+ def test_should_have_at_least_should_pass_if_responds_to_length_and_has_higher_number
62
+ assert_nothing_raised do
63
+ set_length 2
64
+ @owner.should.have.at.least(1).items_in_collection_with_length_method
65
+ end
66
+ end
67
+
68
+ def test_should_have_at_least_should_fail_if_responds_to_length_and_has_lower_number
69
+ assert_raise(Spec::Exceptions::ExpectationNotMetError) do
70
+ set_length 1
71
+ @owner.should.have.at.least(2).items_in_collection_with_length_method
72
+ end
73
+ end
74
+
75
+ # at.least w/ size
76
+
77
+ def test_should_have_at_least_should_pass_if_responds_to_size_and_has_exact_number
78
+ assert_nothing_raised do
79
+ set_size 1
80
+ @owner.should.have.at.least(1).items_in_collection_with_size_method
81
+ end
82
+ end
83
+
84
+ def test_should_have_at_least_should_pass_if_responds_to_size_and_has_higher_number
85
+ assert_nothing_raised do
86
+ set_size 2
87
+ @owner.should.have.at.least(1).items_in_collection_with_size_method
88
+ end
89
+ end
90
+
91
+ def test_should_have_at_least_should_fail_if_responds_to_size_and_has_lower_number
92
+ assert_raise(Spec::Exceptions::ExpectationNotMetError) do
93
+ set_size 1
94
+ @owner.should.have.at.least(2).items_in_collection_with_size_method
95
+ end
96
+ end
97
+
98
+ # at.most w/ length
99
+
100
+ def test_should_have_at_most_should_pass_if_responds_to_length_and_has_exact_number
101
+ assert_nothing_raised do
102
+ set_length 1
103
+ @owner.should.have.at.most(1).items_in_collection_with_length_method
104
+ end
105
+ end
106
+
107
+ def test_should_have_at_most_should_pass_if_responds_to_length_and_has_lower_number
108
+ assert_nothing_raised do
109
+ set_length 1
110
+ @owner.should.have.at.most(2).items_in_collection_with_length_method
111
+ end
112
+ end
113
+
114
+ def test_should_have_at_most_should_fail_if_responds_to_length_and_has_higher_number
115
+ assert_raise(Spec::Exceptions::ExpectationNotMetError) do
116
+ set_length 2
117
+ @owner.should.have.at.most(1).items_in_collection_with_length_method
118
+ end
119
+ end
120
+
121
+ # at.most w/ size
122
+
123
+ def test_should_have_at_most_should_pass_if_responds_to_size_and_has_exact_number
124
+ assert_nothing_raised do
125
+ set_size 1
126
+ @owner.should.have.at.most(1).items_in_collection_with_size_method
127
+ end
128
+ end
129
+
130
+ def test_should_have_at_most_should_pass_if_responds_to_size_and_has_lower_number
131
+ assert_nothing_raised do
132
+ set_size 1
133
+ @owner.should.have.at.most(2).items_in_collection_with_size_method
134
+ end
135
+ end
136
+
137
+ def test_should_have_at_most_should_fail_if_responds_to_size_and_has_higher_number
138
+ assert_raise(Spec::Exceptions::ExpectationNotMetError) do
139
+ set_size 2
140
+ @owner.should.have.at.most(1).items_in_collection_with_size_method
141
+ end
142
+ end
143
+
144
+ end
@@ -21,271 +21,300 @@ class ExpectationsTest < Test::Unit::TestCase
21
21
  @nil_var = nil
22
22
  end
23
23
 
24
- # should
24
+ # should.satisfy
25
25
 
26
26
  def test_should_raise_exception_when_block_yields_false
27
27
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
28
- should do
29
- false
30
- end
28
+ 5.should.satisfy { false }
31
29
  end
32
30
  end
33
31
 
34
32
  def test_should_not_raise_exception_when_block_yields_true
35
33
  assert_nothing_raised do
36
- should do
37
- true
38
- end
34
+ 5.should.satisfy { true }
39
35
  end
40
36
  end
41
37
 
42
- # should_equal
38
+ # should.not.satisfy
39
+
40
+ def test_should_raise_exception_when_block_yields_false
41
+ assert_raise(Spec::Exceptions::ExpectationNotMetError) do
42
+ 5.should.not.satisfy { true }
43
+ end
44
+ end
45
+
46
+ def test_should_not_raise_exception_when_block_yields_true
47
+ assert_nothing_raised do
48
+ 5.should.not.satisfy { false }
49
+ end
50
+ end
51
+
52
+ # should.equal
43
53
 
44
54
  def test_should_equal_should_not_raise_when_objects_are_equal
45
55
  assert_nothing_raised do
46
- @dummy.should_equal(@equal_dummy)
56
+ @dummy.should.equal @equal_dummy
47
57
  end
48
58
  end
49
59
 
50
60
  def test_should_equal_should_raise_when_objects_are_not_equal
51
61
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
52
- @dummy.should_equal(@another_dummy)
62
+ @dummy.should.equal @another_dummy
53
63
  end
54
64
  end
55
65
 
56
- # should_not_equal
66
+ # should.not.equal
57
67
 
58
68
  def test_should_not_equal_should_not_raise_when_objects_are_not_equal
59
69
  assert_nothing_raised do
60
- @dummy.should_not_equal(@another_dummy)
70
+ @dummy.should.not.equal @another_dummy
61
71
  end
62
72
  end
63
73
 
64
74
  def test_should_not_equal_should_raise_when_objects_are_not_equal
65
75
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
66
- @dummy.should_not_equal(@equal_dummy)
76
+ @dummy.should.not.equal @equal_dummy
67
77
  end
68
78
  end
69
79
 
70
- # should_be_same_as
80
+ # should.be
71
81
 
72
82
  def test_should_be_same_as_should_not_raise_when_objects_are_same
73
83
  assert_nothing_raised do
74
- @dummy.should_be_same_as(@dummy)
84
+ @dummy.should.be @dummy
75
85
  end
76
86
  end
77
87
 
78
88
  def test_should_be_same_as_should_raise_when_objects_are_not_same
79
89
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
80
- @dummy.should_be_same_as(@equal_dummy)
90
+ @dummy.should.be @equal_dummy
81
91
  end
82
92
  end
83
93
 
84
- # should_not_be_same_as
85
-
86
- def test_should_not_be_same_as_should_not_raise_when_objects_are_not_same
94
+ def test_should_be_nil_should_not_raise_when_object_is_nil
87
95
  assert_nothing_raised do
88
- @dummy.should_not_be_same_as(@equal_dummy)
89
- end
96
+ @nil_var.should.be nil
97
+ end
90
98
  end
91
99
 
92
- def test_should_not_be_same_as_should_raise_when_objects_are_not_same
100
+ def test_should_be_nil_should_raise_when_object_is_not_nil
93
101
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
94
- @dummy.should_not_be_same_as(@dummy)
102
+ @dummy.should.be nil
95
103
  end
96
104
  end
97
105
 
98
- # should_match
106
+ # should.not.be
99
107
 
100
- def test_should_match_should_not_raise_when_objects_match
108
+ def test_should_not_be_same_as_should_not_raise_when_objects_are_not_same
101
109
  assert_nothing_raised do
102
- "hi aslak".should_match /aslak/
110
+ @dummy.should.not.be @equal_dummy
103
111
  end
104
112
  end
105
113
 
106
- def test_should_equal_should_raise_when_objects_do_not_match
114
+ def test_should_not_be_same_as_should_raise_when_objects_are_not_same
107
115
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
108
- "hi aslak".should_match /steve/
116
+ @dummy.should.not.be @dummy
109
117
  end
110
118
  end
111
119
 
112
- # should_not_match
113
-
114
- def test_should_not_match_should_not_raise_when_objects_do_not_match
120
+ def test_should_not_be_nil_should_not_raise_when_object_is_not_nil
115
121
  assert_nothing_raised do
116
- "hi aslak".should_not_match /steve/
117
- end
122
+ @dummy.should.not.be nil
123
+ end
118
124
  end
119
125
 
120
- def test_should_not_match_should_raise_when_objects_match
126
+ def test_should_not_be_nil_should_raise_when_object_is_nil
121
127
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
122
- "hi aslak".should_not_match /aslak/
128
+ @nil_var.should.not.be nil
123
129
  end
124
130
  end
125
131
 
126
- # should_be_nil
132
+ # should.match
127
133
 
128
- def test_should_be_nil_should_not_raise_when_object_is_nil
134
+ def test_should_match_should_not_raise_when_objects_match
129
135
  assert_nothing_raised do
130
- @nil_var.should_be_nil
131
- end
136
+ "hi aslak".should.match /aslak/
137
+ end
132
138
  end
133
139
 
134
- def test_should_be_nil_should_raise_when_object_is_not_nil
140
+ def test_should_equal_should_raise_when_objects_do_not_match
135
141
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
136
- @dummy.should_be_nil
142
+ "hi aslak".should.match /steve/
137
143
  end
138
144
  end
139
-
140
- # should_not_be_nil
141
145
 
142
- def test_should_not_be_nil_should_not_raise_when_object_is_not_nil
146
+ # should.not.match
147
+
148
+ def test_should_not_match_should_not_raise_when_objects_do_not_match
143
149
  assert_nothing_raised do
144
- @dummy.should_not_be_nil
145
- end
150
+ "hi aslak".should.not.match /steve/
151
+ end
146
152
  end
147
153
 
148
- def test_should_not_be_nil_should_raise_when_object_is_nil
154
+ def test_should_not_match_should_raise_when_objects_match
149
155
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
150
- @nil_var.should_not_be_nil
156
+ "hi aslak".should.not.match /aslak/
151
157
  end
152
158
  end
153
159
 
154
- # should_be_empty
160
+ # should.be.xxx
155
161
 
156
- def test_should_be_empty_should_raise_when_object_is_not_a_container
157
- assert_raise(NoMethodError) do
158
- 5.should_be_empty
162
+ def test_should_be_xxx_should_raise_when_target_doesnt_understand_xxx
163
+ assert_raise(NoMethodError) do
164
+ 5.should.be.xxx
159
165
  end
160
- end
166
+ end
161
167
 
162
- def test_should_be_empty_should_raise_when_object_is_a_non_empty_array
163
- assert_raise(Spec::Exceptions::ExpectationNotMetError) do
164
- [1, 2, 3].should_be_empty
168
+ def test_should_be_xxx_should_raise_when_sending_xxx_to_target_returns_false
169
+ mock = Mock.new("xxx? returns false")
170
+ mock.should_receive(:xxx?).once.with_no_args.and_return(false)
171
+ assert_raise(Spec::Exceptions::ExpectationNotMetError) do
172
+ mock.should.be.xxx
165
173
  end
174
+ mock.__verify
166
175
  end
167
176
 
168
- def test_should_be_empty_shouldnt_raise_when_object_is_an_empty_array
169
- assert_nothing_raised do
170
- [].should_be_empty
177
+ def test_should_be_xxx_should_raise_when_sending_xxx_to_target_returns_nil
178
+ mock = Mock.new("xxx? returns nil")
179
+ mock.should_receive(:xxx?).once.with_no_args.and_return(nil)
180
+ assert_raise(Spec::Exceptions::ExpectationNotMetError) do
181
+ mock.should.be.xxx
171
182
  end
183
+ mock.__verify
172
184
  end
173
185
 
174
- def test_should_be_empty_should_raise_when_object_is_a_non_empty_hash
175
- assert_raise(Spec::Exceptions::ExpectationNotMetError) do
176
- {"a" => 1}.should_be_empty
186
+ def test_should_be_xxx_should_not_raise_when_sending_xxx_to_target_returns_true
187
+ mock = Mock.new("xxx? returns true")
188
+ mock.should_receive(:xxx?).once.with_no_args.and_return(true)
189
+ assert_nothing_raised do
190
+ mock.should.be.xxx
177
191
  end
192
+ mock.__verify
178
193
  end
179
194
 
180
- def test_should_be_empty_shouldnt_raise_when_object_is_an_empty_hash
181
- assert_nothing_raised do
182
- {}.should_be_empty
195
+ def test_should_be_xxx_should_not_raise_when_sending_xxx_to_target_returns_something_other_than_true_false_or_nil
196
+ mock = Mock.new("xxx? returns 5")
197
+ mock.should_receive(:xxx?).once.with_no_args.and_return(5)
198
+ assert_nothing_raised do
199
+ mock.should.be.xxx
183
200
  end
201
+ mock.__verify
184
202
  end
185
-
186
- # should_not_be_empty
187
203
 
188
- def test_should_be_empty_should_raise_when_object_is_a_non_empty_string
189
- assert_raise(Spec::Exceptions::ExpectationNotMetError) do
190
- @dummy.should_be_empty
204
+ # should.be.xxx(args)
205
+
206
+ def test_should_be_xxx_with_args_passes_args_properly
207
+ mock = Mock.new("xxx?(1 2 3) returns true")
208
+ mock.should_receive(:xxx?).once.with(1, 2, 3).and_return(true)
209
+ assert_nothing_raised do
210
+ mock.should.be.xxx(1, 2, 3)
191
211
  end
212
+ mock.__verify
192
213
  end
193
214
 
194
- def test_should_be_empty_shouldnt_raise_when_object_is_an_empty_string
195
- assert_nothing_raised do
196
- "".should_be_empty
197
- end
198
- end
215
+ # should.not.be.xxx
199
216
 
200
- def test_should_not_be_empty_should_raise_when_object_is_not_a_container
201
- assert_raise(NoMethodError) do
202
- 5.should_not_be_empty
217
+ def test_should_not_be_xxx_should_raise_when_target_doesnt_understand_xxx
218
+ assert_raise(NoMethodError) do
219
+ 5.should.not.be.xxx
203
220
  end
204
- end
221
+ end
205
222
 
206
- def test_should_not_be_empty_should_raise_when_object_is_an_empty_array
207
- assert_raise(Spec::Exceptions::ExpectationNotMetError) do
208
- [].should_not_be_empty
223
+ def test_should_not_be_xxx_should_raise_when_sending_xxx_to_target_returns_true
224
+ mock = Mock.new("xxx? returns true")
225
+ mock.should_receive(:xxx?).once.with_no_args.and_return(true)
226
+ assert_raise(Spec::Exceptions::ExpectationNotMetError) do
227
+ mock.should.not.be.xxx
209
228
  end
229
+ mock.__verify
210
230
  end
211
231
 
212
- def test_should_not_be_empty_shouldnt_raise_when_object_is_a_non_empty_array
213
- assert_nothing_raised do
214
- [1, 2, 3].should_not_be_empty
232
+ def test_should_not_be_xxx_shouldnt_raise_when_sending_xxx_to_target_returns_nil
233
+ mock = Mock.new("xxx? returns nil")
234
+ mock.should_receive(:xxx?).once.with_no_args.and_return(nil)
235
+ assert_nothing_raised do
236
+ mock.should.not.be.xxx
215
237
  end
238
+ mock.__verify
216
239
  end
217
240
 
218
- def test_should_not_be_empty_should_raise_when_object_is_an_empty_hash
219
- assert_raise(Spec::Exceptions::ExpectationNotMetError) do
220
- {}.should_not_be_empty
241
+ def test_should_not_be_xxx_shouldnt_raise_when_sending_xxx_to_target_returns_false
242
+ mock = Mock.new("xxx? returns false")
243
+ mock.should_receive(:xxx?).once.with_no_args.and_return(false)
244
+ assert_nothing_raised do
245
+ mock.should.not.be.xxx
221
246
  end
247
+ mock.__verify
222
248
  end
223
249
 
224
- def test_should_not_be_empty_shouldnt_raise_when_object_is_a_non_empty_hash
225
- assert_nothing_raised do
226
- {"a"=>1}.should_not_be_empty
250
+ def test_should_not_be_xxx_should_raise_when_sending_xxx_to_target_returns_something_other_than_true_false_or_nil
251
+ mock = Mock.new("xxx? returns 5")
252
+ mock.should_receive(:xxx?).once.with_no_args.and_return(5)
253
+ assert_raise(Spec::Exceptions::ExpectationNotMetError) do
254
+ mock.should.not.be.xxx
227
255
  end
256
+ mock.__verify
228
257
  end
229
-
230
- def test_should_not_be_empty_should_raise_when_object_is_an_empty_string
231
- assert_raise(Spec::Exceptions::ExpectationNotMetError) do
232
- "".should_not_be_empty
258
+
259
+
260
+ # should.be.xxx(args)
261
+
262
+ def test_should_not_be_xxx_with_args_passes_args_properly
263
+ mock = Mock.new("xxx?(1 2 3) returns false")
264
+ mock.should_receive(:xxx?).once.with(1, 2, 3).and_return(false)
265
+ assert_nothing_raised do
266
+ mock.should.not.be.xxx(1, 2, 3)
233
267
  end
268
+ mock.__verify
234
269
  end
235
270
 
236
- def test_should_not_be_empty_shouldnt_raise_when_object_is_a_non_empty_string
237
- assert_nothing_raised do
238
- @dummy.should_not_be_empty
239
- end
240
- end
241
-
242
271
  # should_include
243
272
 
244
273
  def test_should_include_shouldnt_raise_when_string_inclusion_is_present
245
274
  assert_nothing_raised do
246
- @dummy.should_include("mm")
275
+ @dummy.should.include "mm"
247
276
  end
248
277
  end
249
278
 
250
279
  def test_should_include_should_raise_when_string_inclusion_is_missing
251
280
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
252
- @dummy.should_include("abc")
281
+ @dummy.should.include "abc"
253
282
  end
254
283
  end
255
284
 
256
285
  def test_should_include_shouldnt_raise_when_array_inclusion_is_present
257
286
  assert_nothing_raised do
258
- [1, 2, 3].should_include(2)
287
+ [1, 2, 3].should.include 2
259
288
  end
260
289
  end
261
290
 
262
291
  def test_should_include_should_raise_when_array_inclusion_is_missing
263
292
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
264
- [1, 2, 3].should_include(5)
293
+ [1, 2, 3].should.include 5
265
294
  end
266
295
  end
267
296
 
268
297
  def test_should_include_shouldnt_raise_when_hash_inclusion_is_present
269
298
  assert_nothing_raised do
270
- {"a"=>1}.should_include("a")
299
+ {"a"=>1}.should.include "a"
271
300
  end
272
301
  end
273
302
 
274
303
  def test_should_include_should_raise_when_hash_inclusion_is_missing
275
304
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
276
- {"a"=>1}.should_include("b")
305
+ {"a"=>1}.should.include "b"
277
306
  end
278
307
  end
279
308
 
280
309
  def test_should_include_shouldnt_raise_when_enumerable_inclusion_is_present
281
310
  assert_nothing_raised do
282
- IO.constants.should_include("SEEK_SET")
311
+ IO.constants.should.include "SEEK_SET"
283
312
  end
284
313
  end
285
314
 
286
315
  def test_should_include_should_raise_when_enumerable_inclusion_is_missing
287
316
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
288
- IO.constants.should_include("BLAH")
317
+ IO.constants.should.include "BLAH"
289
318
  end
290
319
  end
291
320
 
@@ -293,49 +322,49 @@ class ExpectationsTest < Test::Unit::TestCase
293
322
 
294
323
  def test_should_not_include_shouldnt_raise_when_string_inclusion_is_missing
295
324
  assert_nothing_raised do
296
- @dummy.should_not_include("abc")
325
+ @dummy.should.not.include "abc"
297
326
  end
298
327
  end
299
328
 
300
329
  def test_should_not_include_should_raise_when_string_inclusion_is_present
301
330
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
302
- @dummy.should_not_include("mm")
331
+ @dummy.should.not.include "mm"
303
332
  end
304
333
  end
305
334
 
306
335
  def test_should_not_include_shouldnt_raise_when_array_inclusion_is_missing
307
336
  assert_nothing_raised do
308
- [1, 2, 3].should_not_include(5)
337
+ [1, 2, 3].should.not.include 5
309
338
  end
310
339
  end
311
340
 
312
341
  def test_should_not_include_should_raise_when_array_inclusion_is_present
313
342
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
314
- [1, 2, 3].should_not_include(2)
343
+ [1, 2, 3].should.not.include 2
315
344
  end
316
345
  end
317
346
 
318
347
  def test_should_not_include_shouldnt_raise_when_hash_inclusion_is_missing
319
348
  assert_nothing_raised do
320
- {"a"=>1}.should_not_include("b")
349
+ {"a"=>1}.should.not.include "b"
321
350
  end
322
351
  end
323
352
 
324
353
  def test_should_not_include_should_raise_when_hash_inclusion_is_present
325
354
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
326
- {"a"=>1}.should_not_include("a")
355
+ {"a"=>1}.should.not.include "a"
327
356
  end
328
357
  end
329
358
 
330
359
  def test_should_not_include_shouldnt_raise_when_enumerable_inclusion_is_present
331
360
  assert_nothing_raised do
332
- IO.constants.should_not_include("BLAH")
361
+ IO.constants.should.not.include "BLAH"
333
362
  end
334
363
  end
335
364
 
336
365
  def test_should_not_include_should_raise_when_enumerable_inclusion_is_missing
337
366
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
338
- IO.constants.should_not_include("SEEK_SET")
367
+ IO.constants.should.not.include "SEEK_SET"
339
368
  end
340
369
  end
341
370
 
@@ -348,120 +377,216 @@ class ExpectationsTest < Test::Unit::TestCase
348
377
  end
349
378
  end
350
379
 
351
- # should_be_true
380
+ # should.be true
352
381
 
353
382
  def test_should_be_true_should_raise_when_object_is_nil
354
383
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
355
- nil.should_be_true
384
+ nil.should.be true
356
385
  end
357
386
  end
358
387
 
359
388
  def test_should_be_true_should_raise_when_object_is_false
360
389
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
361
- false.should_be_true
390
+ false.should.be true
362
391
  end
363
392
  end
364
393
 
365
394
  def test_should_be_true_shouldnt_raise_when_object_is_true
366
395
  assert_nothing_raised do
367
- true.should_be_true
396
+ true.should.be true
368
397
  end
369
398
  end
370
399
 
371
400
  def test_should_be_true_shouldnt_raise_when_object_is_a_number
372
401
  assert_nothing_raised do
373
- 5.should_be_true
402
+ 5.should.be true
374
403
  end
375
404
  end
376
405
 
377
406
  def test_should_be_true_shouldnt_raise_when_object_is_a_string
378
407
  assert_nothing_raised do
379
- "hello".should_be_true
408
+ "hello".should.be true
380
409
  end
381
410
  end
382
411
 
383
412
  def test_should_be_true_shouldnt_raise_when_object_is_a_some_random_object
384
413
  assert_nothing_raised do
385
- self.should_be_true
414
+ self.should.be true
386
415
  end
387
416
  end
388
417
 
389
- # should_be_false
418
+ # should.be false
390
419
 
391
- def test_should_be_true_shouldnt_raise_when_object_is_nil
420
+ def test_should_be_false_shouldnt_raise_when_object_is_nil
392
421
  assert_nothing_raised do
393
- nil.should_be_false
422
+ nil.should.be false
394
423
  end
395
424
  end
396
425
 
397
426
  def test_should_be_true_shouldnt_raise_when_object_is_false
398
427
  assert_nothing_raised do
399
- false.should_be_false
428
+ false.should.be false
400
429
  end
401
430
  end
402
431
 
403
432
  def test_should_be_true_should_raise_when_object_is_true
404
433
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
405
- true.should_be_false
434
+ true.should.be false
406
435
  end
407
436
  end
408
437
 
409
438
  def test_should_be_true_shouldnt_raise_when_object_is_a_number
410
439
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
411
- 5.should_be_false
440
+ 5.should.be false
412
441
  end
413
442
  end
414
443
 
415
444
  def test_should_be_true_shouldnt_raise_when_object_is_a_string
416
445
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
417
- "hello".should_be_false
446
+ "hello".should.be false
418
447
  end
419
448
  end
420
449
 
421
450
  def test_should_be_true_shouldnt_raise_when_object_is_a_some_random_object
422
451
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
423
- self.should_be_false
452
+ self.should.be false
424
453
  end
425
454
  end
426
-
427
- # should_raise
455
+
456
+ # should.raise
428
457
 
429
458
  def test_should_raise_should_pass_when_proper_exception_is_raised
430
459
  assert_nothing_raised do
431
- proc { ''.nonexistant_method }.should_raise(NoMethodError)
460
+ proc { ''.nonexistant_method }.should.raise NoMethodError
432
461
  end
433
462
  end
434
463
 
435
- def test_should_raise_should_not_pass_when_wrong_exception_is_raised
464
+ def test_should_raise_should_fail_when_wrong_exception_is_raised
436
465
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
437
- proc { ''.nonexistant_method }.should_raise(SyntaxError)
466
+ proc { ''.nonexistant_method }.should.raise SyntaxError
438
467
  end
439
468
  end
440
469
 
441
- def test_should_raise_should_not_pass_with_no_exception
470
+ def test_should_raise_should_fail_when_no_exception_is_raised
442
471
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
443
- not proc {''.to_s}.should_raise(NoMethodError)
472
+ proc {''.to_s}.should.raise NoMethodError
444
473
  end
445
474
  end
446
475
 
447
- # should_not_raise
476
+ # should.not.raise
448
477
 
449
- def test_should_not_raise_should_pass_when_proper_exception_is_raised
478
+ def test_should_not_raise_should_fail_when_specific_exception_is_raised
450
479
  assert_raise(Spec::Exceptions::ExpectationNotMetError) do
451
- proc { ''.nonexistant_method }.should_not_raise(NoMethodError)
480
+ proc { ''.nonexistant_method }.should.not.raise NoMethodError
452
481
  end
453
482
  end
454
483
 
455
- def test_should_not_raise_should_not_pass_when_wrong_exception_is_raised
484
+ def test_should_not_raise_should_pass_when_other_exception_is_raised
456
485
  assert_nothing_raised do
457
- proc { ''.nonexistant_method }.should_not_raise(SyntaxError)
486
+ proc { ''.nonexistant_method }.should.not.raise SyntaxError
458
487
  end
459
488
  end
460
489
 
461
- def test_should_not_raise_should_not_pass_with_no_exception
462
- assert_nothing_raised do
463
- not proc { ''.to_s }.should_not_raise(NoMethodError)
464
- end
465
- end
490
+ def test_should_not_raise_should_pass_when_no_exception_is_raised
491
+ assert_nothing_raised do
492
+ proc { ''.to_s }.should.not.raise NoMethodError
493
+ end
494
+ end
495
+
496
+ # should.be.an.instance.of <class>
497
+
498
+ def test_should_be_an_instance_of_should_pass_when_target_is_specified_class
499
+ assert_nothing_raised do
500
+ 5.should.be.an.instance.of Fixnum
501
+ end
502
+ end
503
+
504
+ def test_should_be_an_instance_of_should_fail_when_target_is_not_specified_class
505
+ assert_raise(Spec::Exceptions::ExpectationNotMetError) do
506
+ 5.should.be.an.instance.of Integer
507
+ end
508
+ end
509
+
510
+ # should.be.a.kind.of <class>
511
+
512
+ def test_should_be_a_kind_of_should_pass_when_target_is_of_specified_class
513
+ assert_nothing_raised do
514
+ 5.should.be.a.kind.of Fixnum
515
+ end
516
+ end
517
+
518
+ def test_should_be_a_kind_of_should_pass_when_target_is_of_subclass_of_specified_class
519
+ assert_nothing_raised do
520
+ 5.should.be.a.kind.of Integer
521
+ end
522
+ end
523
+
524
+ def test_should_be_an_instance_of_should_fail_when_target_is_not_specified_class
525
+ assert_raise(Spec::Exceptions::ExpectationNotMetError) do
526
+ 5.should.be.a.kind.of String
527
+ end
528
+ end
529
+
530
+ # should.not.be.an.instance_of <class>
531
+
532
+ def test_should_not_be_an_instance_of_should_fail_when_target_is_of_specified_class
533
+ assert_raise(Spec::Exceptions::ExpectationNotMetError) do
534
+ 'hello'.should.not.be.an.instance.of String
535
+ end
536
+ end
537
+
538
+ def test_should_be_an_instance_of_should_pass_when_target_is_not_of_specified_class
539
+ assert_nothing_raised do
540
+ [].should.not.be.an.instance.of String
541
+ end
542
+ end
543
+
544
+ # should.be.a.kind.of <class>
545
+
546
+ def test_should_not_be_a_kind_of_should_fail_when_target_is_of_specified_class
547
+ assert_raise(Spec::Exceptions::ExpectationNotMetError) do
548
+ 5.should.not.be.a.kind.of Fixnum
549
+ end
550
+ end
551
+
552
+ def test_should_not_be_a_kind_of_should_fail_when_target_is_of_subclass_of_specified_class
553
+ assert_raise(Spec::Exceptions::ExpectationNotMetError) do
554
+ 5.should.not.be.a.kind.of Integer
555
+ end
556
+ end
557
+
558
+ def test_should_not_be_an_instance_of_should_pass_when_target_is_not_specified_class
559
+ assert_nothing_raised do
560
+ 5.should.not.be.a.kind.of String
561
+ end
562
+ end
563
+
564
+ # should.respond.to <message>
565
+
566
+ def test_should_respond_to_should_pass_when_target_does
567
+ assert_nothing_raised do
568
+ "".should.respond.to :length
569
+ end
570
+ end
571
+
572
+ def test_should_respond_to_should_fail_when_target_doesnt
573
+ assert_raise(Spec::Exceptions::ExpectationNotMetError) do
574
+ "".should.respond.to :connect
575
+ end
576
+ end
577
+
578
+ # should.not.respond.to <message>
579
+
580
+ def test_not_should_respond_to_should_fail_when_target_does
581
+ assert_raise(Spec::Exceptions::ExpectationNotMetError) do
582
+ "".should.not.respond.to :length
583
+ end
584
+ end
585
+
586
+ def test_not_should_respond_to_should_pass_when_target_doesnt
587
+ assert_nothing_raised do
588
+ "".should.not.respond.to :connect
589
+ end
590
+ end
466
591
 
467
592
  end