scampi 0.1.1

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,426 @@
1
+ $-w,w = nil, $-w
2
+ require File.expand_path('../../lib/scampi', __FILE__)
3
+ $-w = w
4
+
5
+ # Hooray for meta-testing.
6
+ module MetaTests
7
+ def succeed
8
+ lambda { |block|
9
+ block.should.not.raise Scampi::Error
10
+ true
11
+ }
12
+ end
13
+
14
+ def fail
15
+ lambda { |block|
16
+ block.should.raise Scampi::Error
17
+ true
18
+ }
19
+ end
20
+
21
+ def equal_string(x)
22
+ lambda { |s|
23
+ x == s.to_s
24
+ }
25
+ end
26
+ end
27
+
28
+ describe "Scampi" do
29
+ extend MetaTests
30
+
31
+ it "should have should.satisfy" do
32
+ lambda { should.satisfy { 1 == 1 } }.should succeed
33
+ lambda { should.satisfy { 1 } }.should succeed
34
+
35
+ lambda { should.satisfy { 1 != 1 } }.should fail
36
+ lambda { should.satisfy { false } }.should fail
37
+ lambda { should.satisfy { false } }.should fail
38
+
39
+ lambda { 1.should.satisfy { |n| n % 2 == 0 } }.should fail
40
+ lambda { 2.should.satisfy { |n| n % 2 == 0 } }.should succeed
41
+ end
42
+
43
+ it "should have should.==" do
44
+ lambda { "string1".should == "string1" }.should succeed
45
+ lambda { "string1".should == "string2" }.should fail
46
+
47
+ lambda { [1,2,3].should == [1,2,3] }.should succeed
48
+ lambda { [1,2,3].should == [1,2,4] }.should fail
49
+ end
50
+
51
+ it "should have should.equal" do
52
+ lambda { "string1".should == "string1" }.should succeed
53
+ lambda { "string1".should == "string2" }.should fail
54
+ lambda { "1".should == 1 }.should fail
55
+
56
+ lambda { "string1".should.equal "string1" }.should succeed
57
+ lambda { "string1".should.equal "string2" }.should fail
58
+ lambda { "1".should.equal 1 }.should fail
59
+ end
60
+
61
+ it "should have should.raise" do
62
+ lambda { lambda { raise "Error" }.should.raise }.should succeed
63
+ lambda { lambda { raise "Error" }.should.raise RuntimeError }.should succeed
64
+ lambda { lambda { raise "Error" }.should.not.raise }.should fail
65
+ lambda { lambda { raise "Error" }.should.not.raise(RuntimeError) }.should fail
66
+
67
+ lambda { lambda { 1 + 1 }.should.raise }.should fail
68
+ lambda {
69
+ lambda { raise "Error" }.should.raise(Interrupt)
70
+ }.should.raise
71
+ end
72
+
73
+ it "should have should.change" do
74
+ lambda { lambda {}.should.change { sleep 0.001; Time.now } }.should succeed
75
+
76
+ lambda {
77
+ i = 1
78
+ lambda { i *= 2 }.should.change { i }
79
+ }.should succeed
80
+
81
+ lambda {
82
+ i = 0
83
+ lambda { i *= 2 }.should.change { i }
84
+ }.should fail
85
+
86
+ lambda { should.change { sleep 0.001; Time.now } }.should succeed
87
+ lambda { should.change { 42 } }.should fail
88
+ end
89
+
90
+ it "should have should.raise with a block" do
91
+ lambda { should.raise { raise "Error" } }.should succeed
92
+ lambda { should.raise(RuntimeError) { raise "Error" } }.should succeed
93
+ lambda { should.not.raise { raise "Error" } }.should fail
94
+ lambda { should.not.raise(RuntimeError) { raise "Error" } }.should fail
95
+
96
+ lambda { should.raise { 1 + 1 } }.should fail
97
+ lambda {
98
+ should.raise(Interrupt) { raise "Error" }
99
+ }.should.raise
100
+ end
101
+
102
+ it "should have a should.raise should return the exception" do
103
+ ex = lambda { raise "foo!" }.should.raise
104
+ ex.should.be.kind_of RuntimeError
105
+ ex.message.should =~ /foo/
106
+ end
107
+
108
+ it "should have should.be.an.instance_of" do
109
+ lambda { "string".should.be.instance_of String }.should succeed
110
+ lambda { "string".should.be.instance_of Hash }.should fail
111
+
112
+ lambda { "string".should.be.an.instance_of String }.should succeed
113
+ lambda { "string".should.be.an.instance_of Hash }.should fail
114
+ end
115
+
116
+ it "should have should.be.nil" do
117
+ lambda { nil.should.be.nil }.should succeed
118
+ lambda { nil.should.not.be.nil }.should fail
119
+ lambda { "foo".should.be.nil }.should fail
120
+ lambda { "foo".should.not.be.nil }.should succeed
121
+ end
122
+
123
+ it "should have should.include" do
124
+ lambda { [1,2,3].should.include 2 }.should succeed
125
+ lambda { [1,2,3].should.include 4 }.should fail
126
+
127
+ lambda { {1=>2, 3=>4}.should.include 1 }.should succeed
128
+ lambda { {1=>2, 3=>4}.should.include 2 }.should fail
129
+ end
130
+
131
+ it "should have should.be.a.kind_of" do
132
+ lambda { Array.should.be.kind_of Module }.should succeed
133
+ lambda { "string".should.be.kind_of Object }.should succeed
134
+ lambda { 1.should.be.kind_of Comparable }.should succeed
135
+
136
+ lambda { Array.should.be.a.kind_of Module }.should succeed
137
+
138
+ lambda { "string".should.be.a.kind_of Class }.should fail
139
+ end
140
+
141
+ it "should have should.match" do
142
+ lambda { "string".should.match(/strin./) }.should succeed
143
+ lambda { "string".should =~ /strin./ }.should succeed
144
+
145
+ lambda { "string".should.match(/slin./) }.should fail
146
+ lambda { "string".should =~ /slin./ }.should fail
147
+ end
148
+
149
+ it "should have should.not.raise" do
150
+ lambda { lambda { 1 + 1 }.should.not.raise }.should succeed
151
+ lambda { lambda { 1 + 1 }.should.not.raise(Interrupt) }.should succeed
152
+
153
+ lambda {
154
+ lambda {
155
+ lambda {
156
+ Kernel.raise ZeroDivisionError.new("ArgumentError")
157
+ }.should.not.raise(RuntimeError, Comparable)
158
+ }.should.raise ZeroDivisionError
159
+ }.should succeed
160
+
161
+ lambda { lambda { raise "Error" }.should.not.raise }.should fail
162
+ end
163
+
164
+ it "should have should.throw" do
165
+ lambda { lambda { throw :foo }.should.throw(:foo) }.should succeed
166
+ lambda { lambda { :foo }.should.throw(:foo) }.should fail
167
+
168
+ should.throw(:foo) { throw :foo }
169
+ end
170
+
171
+ it "should have should.not.satisfy" do
172
+ lambda { should.not.satisfy { 1 == 2 } }.should succeed
173
+ lambda { should.not.satisfy { 1 == 1 } }.should fail
174
+ end
175
+
176
+ it "should have should.not.equal" do
177
+ lambda { "string1".should.not == "string2" }.should succeed
178
+ lambda { "string1".should.not == "string1" }.should fail
179
+ end
180
+
181
+ it "should have should.not.match" do
182
+ lambda { "string".should.not.match(/sling/) }.should succeed
183
+ lambda { "string".should.not.match(/string/) }.should fail
184
+ # lambda { "string".should.not.match("strin") }.should fail
185
+
186
+ lambda { "string".should.not =~ /sling/ }.should succeed
187
+ lambda { "string".should.not =~ /string/ }.should fail
188
+ # lambda { "string".should.not =~ "strin" }.should fail
189
+ end
190
+
191
+ it "should have should.be.identical_to/same_as" do
192
+ lambda { s = "string"; s.should.be.identical_to s }.should succeed
193
+ lambda { "string".should.be.identical_to "string".dup }.should fail
194
+
195
+ lambda { s = "string"; s.should.be.same_as s }.should succeed
196
+ lambda { "string".should.be.same_as "string".dup }.should fail
197
+ end
198
+
199
+ it "should have should.respond_to" do
200
+ lambda { "foo".should.respond_to :to_s }.should succeed
201
+ lambda { 5.should.respond_to :to_str }.should fail
202
+ lambda { :foo.should.respond_to :nx }.should fail
203
+ end
204
+
205
+ it "should have should.be.close" do
206
+ lambda { 1.4.should.be.close 1.4, 0 }.should succeed
207
+ lambda { 0.4.should.be.close 0.5, 0.1 }.should succeed
208
+
209
+ lambda { 0.4.should.be.close 0.5, 0.05 }.should fail
210
+ lambda { 0.4.should.be.close Object.new, 0.1 }.should fail
211
+ lambda { 0.4.should.be.close 0.5, -0.1 }.should fail
212
+ end
213
+
214
+ it "should support multiple negation" do
215
+ lambda { 1.should.equal 1 }.should succeed
216
+ lambda { 1.should.not.equal 1 }.should fail
217
+ lambda { 1.should.not.not.equal 1 }.should succeed
218
+ lambda { 1.should.not.not.not.equal 1 }.should fail
219
+
220
+ lambda { 1.should.equal 2 }.should fail
221
+ lambda { 1.should.not.equal 2 }.should succeed
222
+ lambda { 1.should.not.not.equal 2 }.should fail
223
+ lambda { 1.should.not.not.not.equal 2 }.should succeed
224
+ end
225
+
226
+ it "should have should.<predicate>" do
227
+ lambda { [].should.be.empty }.should succeed
228
+ lambda { [1,2,3].should.not.be.empty }.should succeed
229
+
230
+ lambda { [].should.not.be.empty }.should fail
231
+ lambda { [1,2,3].should.be.empty }.should fail
232
+
233
+ lambda { {1=>2, 3=>4}.should.has_key 1 }.should succeed
234
+ lambda { {1=>2, 3=>4}.should.not.has_key 2 }.should succeed
235
+
236
+ lambda { nil.should.bla }.should.raise(NoMethodError)
237
+ lambda { nil.should.not.bla }.should.raise(NoMethodError)
238
+ end
239
+
240
+ it "should have should <operator> (>, >=, <, <=, ===)" do
241
+ lambda { 2.should.be > 1 }.should succeed
242
+ lambda { 1.should.be > 2 }.should fail
243
+
244
+ lambda { 1.should.be < 2 }.should succeed
245
+ lambda { 2.should.be < 1 }.should fail
246
+
247
+ lambda { 2.should.be >= 1 }.should succeed
248
+ lambda { 2.should.be >= 2 }.should succeed
249
+ lambda { 2.should.be >= 2.1 }.should fail
250
+
251
+ lambda { 2.should.be <= 1 }.should fail
252
+ lambda { 2.should.be <= 2 }.should succeed
253
+ lambda { 2.should.be <= 2.1 }.should succeed
254
+
255
+ lambda { Array.should === [1,2,3] }.should succeed
256
+ lambda { Integer.should === [1,2,3] }.should fail
257
+
258
+ lambda { /foo/.should === "foobar" }.should succeed
259
+ lambda { "foobar".should === /foo/ }.should fail
260
+ end
261
+
262
+ it "should allow for custom shoulds" do
263
+ lambda { (1+1).should equal_string("2") }.should succeed
264
+ lambda { (1+2).should equal_string("2") }.should fail
265
+
266
+ lambda { (1+1).should.be equal_string("2") }.should succeed
267
+ lambda { (1+2).should.be equal_string("2") }.should fail
268
+
269
+ lambda { (1+1).should.not equal_string("2") }.should fail
270
+ lambda { (1+2).should.not equal_string("2") }.should succeed
271
+ lambda { (1+2).should.not.not equal_string("2") }.should fail
272
+
273
+ lambda { (1+1).should.not.be equal_string("2") }.should fail
274
+ lambda { (1+2).should.not.be equal_string("2") }.should succeed
275
+ end
276
+
277
+ it "should have should.flunk" do
278
+ lambda { should.flunk }.should fail
279
+ lambda { should.flunk "yikes" }.should fail
280
+ end
281
+ end
282
+
283
+ describe "before/after" do
284
+ before do
285
+ @a = 1
286
+ @b = 2
287
+ @c = nil
288
+ end
289
+
290
+ before do
291
+ @a = 2
292
+ end
293
+
294
+ after do
295
+ @a.should.equal 2
296
+ @a = 3
297
+ end
298
+
299
+ after do
300
+ @a.should.equal 3
301
+ end
302
+
303
+ it "should run in the right order" do
304
+ @a.should.equal 2
305
+ @b.should.equal 2
306
+ end
307
+
308
+ describe "when nested" do
309
+ before do
310
+ @c = 5
311
+ end
312
+
313
+ it "should run from higher level" do
314
+ @a.should.equal 2
315
+ @b.should.equal 2
316
+ end
317
+
318
+ it "should run at the nested level" do
319
+ @c.should.equal 5
320
+ end
321
+
322
+ before do
323
+ @a = 5
324
+ end
325
+
326
+ it "should run in the right order" do
327
+ @a.should.equal 5
328
+ @a = 2
329
+ end
330
+ end
331
+
332
+ it "should not run from lower level" do
333
+ @c.should.be.nil
334
+ end
335
+
336
+ describe "when nested at a sibling level" do
337
+ it "should not run from sibling level" do
338
+ @c.should.be.nil
339
+ end
340
+ end
341
+ end
342
+
343
+ shared "a shared context" do
344
+ it "gets called where it is included" do
345
+ true.should.be.true
346
+ end
347
+ end
348
+
349
+ shared "another shared context" do
350
+ it "can access data" do
351
+ @magic.should.be.equal 42
352
+ end
353
+ end
354
+
355
+ describe "shared/behaves_like" do
356
+ behaves_like "a shared context"
357
+
358
+ ctx = self
359
+ it "raises NameError when the context is not found" do
360
+ lambda {
361
+ ctx.behaves_like "whoops"
362
+ }.should.raise NameError
363
+ end
364
+
365
+ behaves_like "a shared context"
366
+
367
+ before {
368
+ @magic = 42
369
+ }
370
+ behaves_like "another shared context"
371
+ end
372
+
373
+ describe "Methods" do
374
+ def the_meaning_of_life
375
+ 42
376
+ end
377
+
378
+ def the_towels
379
+ yield "DON'T PANIC"
380
+ end
381
+
382
+ it "should be accessible in a test" do
383
+ the_meaning_of_life.should == 42
384
+ end
385
+
386
+ describe "when in a sibling context" do
387
+ it "should be accessible in a test" do
388
+ the_meaning_of_life.should == 42
389
+ end
390
+
391
+ it "should pass the block" do
392
+ the_towels do |label|
393
+ label.should == "DON'T PANIC"
394
+ end.should == true
395
+ end
396
+ end
397
+ end
398
+
399
+ describe 'describe arguments' do
400
+
401
+ def check(ctx,name)
402
+ ctx.should.be.an.instance_of Scampi::Context
403
+ ctx.instance_variable_get('@name').should == name
404
+ end
405
+
406
+ it 'should work with string' do
407
+ check(describe('string') {},'string')
408
+ end
409
+
410
+ it 'should work with symbols' do
411
+ check(describe(:behaviour) {},'behaviour')
412
+ end
413
+
414
+ it 'should work with modules' do
415
+ check(describe(Scampi) {},'Scampi')
416
+ end
417
+
418
+ it 'should work with namespaced modules' do
419
+ check(describe(Scampi::Context) {},'Scampi::Context')
420
+ end
421
+
422
+ it 'should work with multiple arguments' do
423
+ check(describe(Scampi::Context, :empty) {},'Scampi::Context empty')
424
+ end
425
+
426
+ end
@@ -0,0 +1,14 @@
1
+ $false_is_not_true = false.should.not.be.true
2
+ $nil_is_not_true = nil.should.not.be.true
3
+
4
+ describe 'A non-true value' do
5
+ it 'should pass negated tests inside specs' do
6
+ false.should.not.be.true
7
+ nil.should.not.be.true
8
+ end
9
+
10
+ it 'should pass negated tests outside specs' do
11
+ $false_is_not_true.should.be.true
12
+ $nil_is_not_true.should.be.true
13
+ end
14
+ end
@@ -0,0 +1,31 @@
1
+ require File.expand_path('../../lib/scampi', __FILE__)
2
+
3
+ describe "#should shortcut for #it('should')" do
4
+
5
+ should "be called" do
6
+ @called = true
7
+ @called.should.be == true
8
+ end
9
+
10
+ should "save some characters by typing should" do
11
+ lambda { should.satisfy { 1 == 1 } }.should.not.raise
12
+ end
13
+
14
+ should "save characters even on failure" do
15
+ lambda { should.satisfy { 1 == 2 } }.should.raise Scampi::Error
16
+ end
17
+
18
+ should "work nested" do
19
+ should.satisfy {1==1}
20
+ end
21
+
22
+ should "add new specifications" do
23
+ # verify the counter increments for each spec
24
+ Scampi::Counter[:specifications].should.be > 0
25
+ end
26
+
27
+ should "have been called" do
28
+ @called.should.be == true
29
+ end
30
+
31
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scampi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Nathan K
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-01 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: colorize-extended
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ description: |
27
+ Scampi is a small RSpec clone weighing less than 350 LoC but
28
+ nevertheless providing all essential features. Includes a
29
+ TAP (Test Anything Protocol) harness and assertion library.
30
+
31
+ http://github.com/general-intelligence-systems/scampi
32
+ email: nathankidd@hey.com
33
+ executables:
34
+ - scampi
35
+ extensions: []
36
+ extra_rdoc_files:
37
+ - README.rdoc
38
+ files:
39
+ - ".envrc"
40
+ - COPYING
41
+ - Gemfile
42
+ - Gemfile.lock
43
+ - README.rdoc
44
+ - Rakefile
45
+ - bin/increment-version
46
+ - bin/release-gem
47
+ - bin/test
48
+ - exe/scampi
49
+ - flake.lock
50
+ - flake.nix
51
+ - lib/rubygems_plugin.rb
52
+ - lib/scampi.rb
53
+ - lib/scampi/context.rb
54
+ - lib/scampi/error.rb
55
+ - lib/scampi/monkey_patches.rb
56
+ - lib/scampi/should.rb
57
+ - lib/scampi/version.rb
58
+ - lib/scampi/version.rb.erb
59
+ - scampi.gemspec
60
+ - test/spec_bacon.rb
61
+ - test/spec_nontrue.rb
62
+ - test/spec_should.rb
63
+ homepage: http://github.com/general-intelligence-systems/scampi
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubygems_version: 3.7.2
82
+ specification_version: 4
83
+ summary: a small RSpec clone with built-in TAP support
84
+ test_files: []