must_be 1.0.3 → 1.1.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.
- checksums.yaml +7 -0
- data/ChangeLog.md +5 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +22 -0
- data/README.md +14 -14
- data/Rakefile +0 -1
- data/VERSION +1 -1
- data/doc/readme/examples.rb +13 -13
- data/lib/must_be.rb +2 -2
- data/lib/must_be/attr_typed.rb +1 -1
- data/lib/must_be/core.rb +1 -0
- data/must_be.gemspec +46 -57
- data/spec/must_be/attr_typed_spec.rb +14 -14
- data/spec/must_be/basic_spec.rb +22 -22
- data/spec/must_be/containers_spec.rb +10 -10
- data/spec/must_be/core_spec.rb +32 -22
- data/spec/must_be/nonstandard_control_flow_spec.rb +73 -71
- data/spec/must_be/proxy_spec.rb +13 -13
- data/spec/notify_matcher_spec.rb +1 -1
- data/spec/spec_helper.rb +11 -3
- data/spec/typical_usage_spec.rb +5 -5
- metadata +52 -81
- data/.gitignore +0 -2
data/spec/must_be/basic_spec.rb
CHANGED
@@ -34,7 +34,7 @@ describe MustBe do
|
|
34
34
|
context "when called with Float" do
|
35
35
|
it "should notify" do
|
36
36
|
51.must_be(Float).should == 51
|
37
|
-
should notify("51.must_be(Float), but matches
|
37
|
+
should notify("51.must_be(Float), but matches Integer")
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -48,7 +48,7 @@ describe MustBe do
|
|
48
48
|
context "when called with Enumerable" do
|
49
49
|
it "should notify" do
|
50
50
|
51.must_be(Enumerable).should == 51
|
51
|
-
should notify("51.must_be(Enumerable), but matches
|
51
|
+
should notify("51.must_be(Enumerable), but matches Integer")
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
@@ -62,14 +62,14 @@ describe MustBe do
|
|
62
62
|
context "when called with String, Time, Array" do
|
63
63
|
it "should notify" do
|
64
64
|
51.must_be(String, Time, Array).should == 51
|
65
|
-
should notify("51.must_be(String, Time, Array), but matches
|
65
|
+
should notify("51.must_be(String, Time, Array), but matches Integer")
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
69
|
context "when called with [1, 51]" do
|
70
70
|
it "should notify" do
|
71
71
|
51.must_be([1, 51]).should == 51
|
72
|
-
should notify("51.must_be([1, 51]), but matches
|
72
|
+
should notify("51.must_be([1, 51]), but matches Integer")
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -118,14 +118,14 @@ describe MustBe do
|
|
118
118
|
context "when called with no arguments" do
|
119
119
|
it "should notify" do
|
120
120
|
51.must_not_be.should == 51
|
121
|
-
should notify("51.must_not_be, but matches
|
121
|
+
should notify("51.must_not_be, but matches Integer")
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
125
|
context "when called with Numeric" do
|
126
126
|
it "should notify" do
|
127
127
|
51.must_not_be(Numeric)
|
128
|
-
should notify("51.must_not_be(Numeric), but matches
|
128
|
+
should notify("51.must_not_be(Numeric), but matches Integer")
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
@@ -139,7 +139,7 @@ describe MustBe do
|
|
139
139
|
context "when called with Comparable" do
|
140
140
|
it "should notify" do
|
141
141
|
51.must_not_be(Comparable)
|
142
|
-
should notify("51.must_not_be(Comparable), but matches
|
142
|
+
should notify("51.must_not_be(Comparable), but matches Integer")
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
@@ -154,7 +154,7 @@ describe MustBe do
|
|
154
154
|
it "should notify" do
|
155
155
|
51.must_not_be(Hash, Kernel, Object).should == 51
|
156
156
|
should notify("51.must_not_be(Hash, Kernel, Object),"\
|
157
|
-
" but matches
|
157
|
+
" but matches Integer")
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
@@ -205,7 +205,7 @@ describe MustBe do
|
|
205
205
|
it "should raise ArgumentError" do
|
206
206
|
expect do
|
207
207
|
51.send(the_method_name)
|
208
|
-
end.
|
208
|
+
end.to raise_error(ArgumentError,
|
209
209
|
"wrong number of arguments (0 for 1)")
|
210
210
|
end
|
211
211
|
end
|
@@ -214,7 +214,7 @@ describe MustBe do
|
|
214
214
|
it "should raise TypeError" do
|
215
215
|
expect do
|
216
216
|
51.send(the_method_name, Object, :extra_message, :usual_message)
|
217
|
-
end.
|
217
|
+
end.to raise_error(TypeError, "class or module required")
|
218
218
|
end
|
219
219
|
end
|
220
220
|
|
@@ -223,7 +223,7 @@ describe MustBe do
|
|
223
223
|
it "should raise TypeError" do
|
224
224
|
expect do
|
225
225
|
51.send(the_method_name, Object, :not_a_module, Kernel)
|
226
|
-
end.
|
226
|
+
end.to raise_error(TypeError, "class or module required")
|
227
227
|
end
|
228
228
|
end
|
229
229
|
|
@@ -231,7 +231,7 @@ describe MustBe do
|
|
231
231
|
it "should raise TypeError" do
|
232
232
|
expect do
|
233
233
|
51.send(the_method_name, :not_a_module)
|
234
|
-
end.
|
234
|
+
end.to raise_error(TypeError, "class or module required")
|
235
235
|
end
|
236
236
|
end
|
237
237
|
end
|
@@ -244,7 +244,7 @@ describe MustBe do
|
|
244
244
|
context "when called with Float" do
|
245
245
|
it "should notify" do
|
246
246
|
51.must_be_a(Float)
|
247
|
-
should notify("51.must_be_a(Float), but is a
|
247
|
+
should notify("51.must_be_a(Float), but is a Integer")
|
248
248
|
end
|
249
249
|
end
|
250
250
|
|
@@ -276,7 +276,7 @@ describe MustBe do
|
|
276
276
|
context "when called with Float, :message" do
|
277
277
|
it "should notify" do
|
278
278
|
51.must_be_a(Float, :message)
|
279
|
-
should notify("51.must_be_a(Float, :message), but is a
|
279
|
+
should notify("51.must_be_a(Float, :message), but is a Integer")
|
280
280
|
end
|
281
281
|
end
|
282
282
|
end
|
@@ -298,7 +298,7 @@ describe MustBe do
|
|
298
298
|
it "should notify" do
|
299
299
|
51.must_not_be_a(Kernel, Comparable)
|
300
300
|
should notify("51.must_not_be_a(Kernel, Comparable),"\
|
301
|
-
" but is a
|
301
|
+
" but is a Integer")
|
302
302
|
end
|
303
303
|
end
|
304
304
|
|
@@ -306,7 +306,7 @@ describe MustBe do
|
|
306
306
|
it "should notify" do
|
307
307
|
51.must_not_be_a(Float, Integer)
|
308
308
|
should notify("51.must_not_be_a(Float, Integer),"\
|
309
|
-
" but is a
|
309
|
+
" but is a Integer")
|
310
310
|
end
|
311
311
|
end
|
312
312
|
|
@@ -314,7 +314,7 @@ describe MustBe do
|
|
314
314
|
it "should notify" do
|
315
315
|
51.must_not_be_a(Numeric, :message)
|
316
316
|
should notify("51.must_not_be_a(Numeric, :message),"\
|
317
|
-
" but is a
|
317
|
+
" but is a Integer")
|
318
318
|
end
|
319
319
|
end
|
320
320
|
end
|
@@ -325,7 +325,7 @@ describe MustBe do
|
|
325
325
|
it "should raise NoMethodError" do
|
326
326
|
expect do
|
327
327
|
"hi".send(the_method_name, :does_not_respond_to_include?)
|
328
|
-
end.
|
328
|
+
end.to raise_error(NoMethodError)
|
329
329
|
end
|
330
330
|
end
|
331
331
|
end
|
@@ -470,27 +470,27 @@ describe MustBe do
|
|
470
470
|
it "should raise ArgumentError if delta cannot be compared" do
|
471
471
|
expect do
|
472
472
|
200.0.send(the_method_name, 2.0, :a_little)
|
473
|
-
end.
|
473
|
+
end.to raise_error(ArgumentError)
|
474
474
|
end
|
475
475
|
|
476
476
|
it "should raise TypeError if expected cannot be subtracted from"\
|
477
477
|
" receiver" do
|
478
478
|
expect do
|
479
479
|
200.0.send(the_method_name, :some)
|
480
|
-
end.
|
480
|
+
end.to raise_error(TypeError)
|
481
481
|
end
|
482
482
|
|
483
483
|
it "should raise NoMethodError if receiver does not respond to :-" do
|
484
484
|
expect do
|
485
485
|
:lots.send(the_method_name, 2.0)
|
486
|
-
end.
|
486
|
+
end.to raise_error(NoMethodError)
|
487
487
|
end
|
488
488
|
|
489
489
|
it "should rasie NoMethodError if (receiver - expected) does not"\
|
490
490
|
" respond to :abs" do
|
491
491
|
expect do
|
492
492
|
Time.new.send(the_method_name, 2.0, :five)
|
493
|
-
end.
|
493
|
+
end.to raise_error(NoMethodError)
|
494
494
|
end
|
495
495
|
end
|
496
496
|
|
@@ -154,7 +154,7 @@ describe MustBe do
|
|
154
154
|
it "should notify if any member matches one of the cases" do
|
155
155
|
subject.must_not_contain(Range, Numeric).should == subject
|
156
156
|
should notify("must_not_contain: 11.must_not_be(Range, Numeric),"\
|
157
|
-
" but matches
|
157
|
+
" but matches Integer in container [11, :sin, \"cos\"]")
|
158
158
|
end
|
159
159
|
|
160
160
|
context "when there are no cases" do
|
@@ -310,7 +310,7 @@ describe MustBe do
|
|
310
310
|
|
311
311
|
context "after disabling" do
|
312
312
|
before do
|
313
|
-
@enabled_array = [].must_only_ever_contain(
|
313
|
+
@enabled_array = [].must_only_ever_contain(Integer)
|
314
314
|
end
|
315
315
|
|
316
316
|
before_disable_after_enable
|
@@ -340,7 +340,7 @@ describe MustBe do
|
|
340
340
|
|
341
341
|
context "when #must_only_ever_contain is called" do
|
342
342
|
before do
|
343
|
-
@disabled_array = [].must_only_ever_contain(
|
343
|
+
@disabled_array = [].must_only_ever_contain(Integer)
|
344
344
|
end
|
345
345
|
|
346
346
|
it "should not notify" do
|
@@ -734,7 +734,7 @@ describe MustBe do
|
|
734
734
|
it "should raise TypeError" do
|
735
735
|
expect do
|
736
736
|
subject.must_only_ever_contain(Symbol)
|
737
|
-
end.
|
737
|
+
end.to raise_error(TypeError,
|
738
738
|
/No MustOnlyEverContain.registered_class for .*Box/)
|
739
739
|
end
|
740
740
|
end
|
@@ -751,7 +751,7 @@ describe MustBe do
|
|
751
751
|
end
|
752
752
|
end
|
753
753
|
subject.must_only_ever_contain(Symbol)
|
754
|
-
end.
|
754
|
+
end.to raise_error(ArgumentError,
|
755
755
|
/must_only_ever_contain adds singleton methods but receiver .*/)
|
756
756
|
end
|
757
757
|
end
|
@@ -784,13 +784,13 @@ describe MustBe do
|
|
784
784
|
it "should raise when trying to register a non-class" do
|
785
785
|
expect do
|
786
786
|
MustOnlyEverContain.register(:not_a_class)
|
787
|
-
end.
|
787
|
+
end.to raise_error(ArgumentError)
|
788
788
|
end
|
789
789
|
|
790
790
|
it "should raise when trying to register a class more than once" do
|
791
791
|
expect do
|
792
792
|
MustOnlyEverContain.register(Box)
|
793
|
-
end.
|
793
|
+
end.to raise_error(ArgumentError)
|
794
794
|
end
|
795
795
|
end
|
796
796
|
end
|
@@ -821,7 +821,7 @@ describe MustBe do
|
|
821
821
|
it "should notify if obj is non-nil" do
|
822
822
|
subject << 5
|
823
823
|
should notify("must_never_ever_contain: Array#<<(5):"\
|
824
|
-
" 5.must_not_be, but matches
|
824
|
+
" 5.must_not_be, but matches Integer in container"\
|
825
825
|
" [nil, 5]")
|
826
826
|
end
|
827
827
|
end
|
@@ -893,7 +893,7 @@ describe MustBe do
|
|
893
893
|
it "should raise TypeError" do
|
894
894
|
expect do
|
895
895
|
subject.must_never_ever_contain(String)
|
896
|
-
end.
|
896
|
+
end.to raise_error(TypeError,
|
897
897
|
/No MustOnlyEverContain.registered_class for .*Box/)
|
898
898
|
end
|
899
899
|
end
|
@@ -910,7 +910,7 @@ describe MustBe do
|
|
910
910
|
end
|
911
911
|
end
|
912
912
|
subject.must_never_ever_contain(Symbol)
|
913
|
-
end.
|
913
|
+
end.to raise_error(ArgumentError,
|
914
914
|
/must_never_ever_contain adds singleton methods but .*/)
|
915
915
|
end
|
916
916
|
end
|
data/spec/must_be/core_spec.rb
CHANGED
@@ -26,6 +26,16 @@ describe MustBe do
|
|
26
26
|
si.length.should == MustBe::SHORT_INSPECT_CUTOFF_LENGTH
|
27
27
|
end
|
28
28
|
|
29
|
+
it "should not mutate #inspect strings" do
|
30
|
+
o = Object.new
|
31
|
+
class <<o
|
32
|
+
def inspect
|
33
|
+
("x" * (MustBe::SHORT_INSPECT_CUTOFF_LENGTH + 10)).freeze
|
34
|
+
end
|
35
|
+
end
|
36
|
+
MustBe.short_inspect(o)
|
37
|
+
end
|
38
|
+
|
29
39
|
it "should break at word boundries if possible" do
|
30
40
|
side_length = MustBe::SHORT_INSPECT_CUTOFF_LENGTH / 2
|
31
41
|
padding = "x" * (side_length - 7)
|
@@ -63,7 +73,7 @@ describe MustBe do
|
|
63
73
|
example "#must_check should not yield to its block" do
|
64
74
|
yielded = false
|
65
75
|
must_check { yielded = true }
|
66
|
-
yielded.should
|
76
|
+
yielded.should be false
|
67
77
|
end
|
68
78
|
|
69
79
|
example "#must should return receiver (not a proxy)" do
|
@@ -90,7 +100,7 @@ describe MustBe do
|
|
90
100
|
|
91
101
|
example "#must_be should notify" do
|
92
102
|
5799.must_be(:lolly).should == 5799
|
93
|
-
should notify("5799.must_be(:lolly), but matches
|
103
|
+
should notify("5799.must_be(:lolly), but matches Integer")
|
94
104
|
end
|
95
105
|
|
96
106
|
example "#must_notify should return a note" do
|
@@ -101,7 +111,7 @@ describe MustBe do
|
|
101
111
|
example "#must_check should yield to its block" do
|
102
112
|
yielded = false
|
103
113
|
must_check { yielded = true }
|
104
|
-
yielded.should
|
114
|
+
yielded.should be true
|
105
115
|
end
|
106
116
|
|
107
117
|
example "#must should return a proxy" do
|
@@ -180,7 +190,7 @@ describe MustBe do
|
|
180
190
|
before_disable_after_enable
|
181
191
|
|
182
192
|
example "handler should be called" do
|
183
|
-
@handler_called.should
|
193
|
+
@handler_called.should be false
|
184
194
|
end
|
185
195
|
end
|
186
196
|
end
|
@@ -193,7 +203,7 @@ describe MustBe do
|
|
193
203
|
end
|
194
204
|
|
195
205
|
example "handler should be called immediately" do
|
196
|
-
@handler_called.should
|
206
|
+
@handler_called.should be false
|
197
207
|
end
|
198
208
|
|
199
209
|
context "when enabled" do
|
@@ -202,7 +212,7 @@ describe MustBe do
|
|
202
212
|
end
|
203
213
|
|
204
214
|
example "handler should be called" do
|
205
|
-
@handler_called.should
|
215
|
+
@handler_called.should be true
|
206
216
|
end
|
207
217
|
end
|
208
218
|
end
|
@@ -219,7 +229,7 @@ describe MustBe do
|
|
219
229
|
it "should yield" do
|
220
230
|
did_yield = false
|
221
231
|
must_just_yield { did_yield = true }
|
222
|
-
did_yield.should
|
232
|
+
did_yield.should be true
|
223
233
|
should_not notify
|
224
234
|
end
|
225
235
|
end
|
@@ -253,7 +263,7 @@ describe MustBe do
|
|
253
263
|
3.must_be(4)
|
254
264
|
|
255
265
|
$stdout.string.should match(
|
256
|
-
/3.must_be\(4\), but matches
|
266
|
+
/3.must_be\(4\), but matches Integer\n\t.*core_spec.rb:\d+.*\n\t/)
|
257
267
|
end
|
258
268
|
end
|
259
269
|
|
@@ -279,10 +289,10 @@ describe MustBe do
|
|
279
289
|
" and call the debugger" do
|
280
290
|
3.must_be(4)
|
281
291
|
|
282
|
-
$stdout.string.should == "3.must_be(4), but matches
|
292
|
+
$stdout.string.should == "3.must_be(4), but matches Integer\n"\
|
283
293
|
"Starting debugger ($must_be__note stores the note)...\n"
|
284
|
-
$must_be__note.message.should == "3.must_be(4), but matches
|
285
|
-
$must_be__did_call_debugger.should
|
294
|
+
$must_be__note.message.should == "3.must_be(4), but matches Integer"
|
295
|
+
$must_be__did_call_debugger.should be true
|
286
296
|
end
|
287
297
|
end
|
288
298
|
end
|
@@ -310,13 +320,13 @@ describe MustBe do
|
|
310
320
|
it "should raise NoMethodError when argument does not respond to :to_sym" do
|
311
321
|
expect do
|
312
322
|
MustBe.set_notifier_from_env(nil)
|
313
|
-
end.
|
323
|
+
end.to raise_error(NoMethodError)
|
314
324
|
end
|
315
325
|
|
316
326
|
it "should raise ArgumentError when unknown notifier name provided" do
|
317
327
|
expect do
|
318
328
|
MustBe.set_notifier_from_env(:unknown)
|
319
|
-
end.
|
329
|
+
end.to raise_error(ArgumentError)
|
320
330
|
end
|
321
331
|
|
322
332
|
it "should treat 'disable' as a special case" do
|
@@ -373,7 +383,7 @@ describe MustBe do
|
|
373
383
|
it "should raise Note" do
|
374
384
|
expect do
|
375
385
|
must_notify("funny bunny")
|
376
|
-
end.
|
386
|
+
end.to(raise_error(Note, "funny bunny") do |note|
|
377
387
|
note.backtrace[0].should_not match(/`must_notify'/)
|
378
388
|
end)
|
379
389
|
end
|
@@ -493,15 +503,15 @@ describe MustBe do
|
|
493
503
|
|
494
504
|
context "when called with #additional_message" do
|
495
505
|
subject do
|
496
|
-
must_notify(5, :must_be, [String], nil, ", but matches
|
506
|
+
must_notify(5, :must_be, [String], nil, ", but matches Integer")
|
497
507
|
end
|
498
508
|
|
499
|
-
it_should_notify("5.must_be(String), but matches
|
509
|
+
it_should_notify("5.must_be(String), but matches Integer")
|
500
510
|
its(:receiver) { should == 5 }
|
501
511
|
its(:assertion) { should == :must_be }
|
502
512
|
its(:args) { should == [String] }
|
503
513
|
its(:block) { should be_nil }
|
504
|
-
its(:additional_message) { should == ", but matches
|
514
|
+
its(:additional_message) { should == ", but matches Integer"}
|
505
515
|
end
|
506
516
|
end
|
507
517
|
|
@@ -523,7 +533,7 @@ describe MustBe do
|
|
523
533
|
it "should return nil" do
|
524
534
|
did_yield = false
|
525
535
|
note = must_check { did_yield = true }
|
526
|
-
did_yield.should
|
536
|
+
did_yield.should be true
|
527
537
|
should_not notify
|
528
538
|
note.should == nil
|
529
539
|
end
|
@@ -535,7 +545,7 @@ describe MustBe do
|
|
535
545
|
must_check(lambda {}) do
|
536
546
|
did_call_block = true
|
537
547
|
end
|
538
|
-
did_call_block.should
|
548
|
+
did_call_block.should be false
|
539
549
|
end
|
540
550
|
|
541
551
|
it "should call its block and notify if the proc notifies" do
|
@@ -545,7 +555,7 @@ describe MustBe do
|
|
545
555
|
note.message.should == "check"
|
546
556
|
Note.new("mate")
|
547
557
|
end
|
548
|
-
did_call_block.should
|
558
|
+
did_call_block.should be true
|
549
559
|
should notify("mate")
|
550
560
|
end
|
551
561
|
|
@@ -556,7 +566,7 @@ describe MustBe do
|
|
556
566
|
note.message.should == "check"
|
557
567
|
"mate"
|
558
568
|
end
|
559
|
-
did_call_block.should
|
569
|
+
did_call_block.should be true
|
560
570
|
should notify("mate")
|
561
571
|
end
|
562
572
|
end
|
@@ -608,7 +618,7 @@ describe MustBe do
|
|
608
618
|
must_check do
|
609
619
|
raise
|
610
620
|
end
|
611
|
-
end.
|
621
|
+
end.to raise_error(RuntimeError)
|
612
622
|
|
613
623
|
must_notify
|
614
624
|
should notify
|