scampi 0.1.3 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87c645091946d4a08fb92032e2e72424ab882e3fdea782321a80adb2afc14116
4
- data.tar.gz: 0d39f5c822180e01583b9d2c21cf2659cc0361582274660db691f4b741fa3a73
3
+ metadata.gz: ebaf159a976cdda7cb655ad11defb7db1533a8c9a77c5874c03fea4887fa20ce
4
+ data.tar.gz: fda454180c407b8f5dea77d6c7a954c62705885126b73888409c7ab0e3277610
5
5
  SHA512:
6
- metadata.gz: 7670887328769ef711129c2c63a1056916f2a7e7ae3f40452ee7d295db0212724f2966113f790e5995111cc65efb49b6c165661ca07eb3200df8f4bac472e5a2
7
- data.tar.gz: 82d40f00f67ff6c15f26f9766980f133459bb6d4b5d301e3a51a65169dc815bfedf5d3228df4e63aa07e9e09b39670c5a696a44a3795ac877530047d253f4bfb
6
+ metadata.gz: f0c78a891d43b2a5a6f8f340fcc4febe0bab4845d5c942b26c1c5ff607dc32e4ba14f85964fcb1de46ccfdf711d7730ce93cb1b33a2f8d9da8e6b2c3013870e5
7
+ data.tar.gz: 7f035622b13ebef90ec6ef03616f11f2006102df6f3ebdc47f88777058d181c0529646a18e63ec0fa2866b95ff32cea63dd7948e9d6a3961af4c59e54e2a68a6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- scampi (0.1.3)
4
+ scampi (0.1.5)
5
5
  colorize-extended
6
6
 
7
7
  GEM
@@ -22,7 +22,7 @@ DEPENDENCIES
22
22
  CHECKSUMS
23
23
  colorize (1.1.0) sha256=30b5237f0603f6662ab8d1fc2bd4a96142b806c6415d79e45ef5fdc6a0cfc837
24
24
  colorize-extended (0.1.0) sha256=e8c39986e41ee2e14623c8fa02cf851ef4b83d2fe1392daa2b4d81f0df7bedc9
25
- scampi (0.1.3)
25
+ scampi (0.1.5)
26
26
 
27
27
  BUNDLED WITH
28
28
  4.0.7
data/README.md CHANGED
@@ -11,16 +11,18 @@ Tests can live alongside your code using the `test` block — it only runs when
11
11
  def greet(name) = "hello #{name}"
12
12
 
13
13
  test do
14
+ greeting = proc { |name| greet(name) }
15
+
14
16
  it "equality and matching" do
15
- greet("world").should == "hello world"
16
- greet("world").should.equal "hello world"
17
- greet("world").should =~ /hello/
18
- greet("world").should.match(/hello/)
17
+ greeting.("world").should == "hello world"
18
+ greeting.("world").should.equal "hello world"
19
+ greeting.("world").should =~ /hello/
20
+ greeting.("world").should.match(/hello/)
19
21
  end
20
22
 
21
23
  it "negation" do
22
- greet("world").should.not == "goodbye"
23
- greet("world").should.not.match(/goodbye/)
24
+ greeting.("world").should.not == "goodbye"
25
+ greeting.("world").should.not.match(/goodbye/)
24
26
  end
25
27
 
26
28
  it "predicates" do
@@ -1,38 +1 @@
1
- module Kernel
2
- # Conditionally run a test block.
3
- #
4
- # When placed in a Ruby file, the block is executed only when the file is
5
- # run directly (ruby myfile.rb) or when ENV["TEST"] is set to "true".
6
- # This lets you co-locate tests alongside implementation code.
7
- #
8
- # # mylib.rb
9
- # def greet(name) = "hello #{name}"
10
- #
11
- # test do
12
- # describe "greet" do
13
- # it "says hello" do
14
- # greet("world").should == "hello world"
15
- # end
16
- # end
17
- # end
18
- #
19
- def test(&block)
20
- loc = caller_locations(1, 1).first
21
- caller_file = loc.absolute_path || loc.path
22
-
23
- if ENV["TEST"] == "true"
24
- require_relative 'scampi' unless defined?(Scampi)
25
- Scampi.summary_on_exit
26
- block.call
27
- elsif caller_file && $0
28
- program = File.expand_path($0) rescue $0
29
- caller_expanded = File.expand_path(caller_file) rescue caller_file
30
- if caller_expanded == program
31
- require_relative 'scampi' unless defined?(Scampi)
32
- Scampi.summary_on_exit
33
- block.call
34
- end
35
- end
36
- end
37
- private :test
38
- end
1
+ require 'scampi'
@@ -60,14 +60,9 @@ module Kernel
60
60
  end
61
61
 
62
62
  # Allow `it` at the top level (outside a describe block).
63
- # Wraps the spec in an anonymous context derived from the caller's filename.
63
+ # Stored as a raw spec only `describe` creates subtests.
64
64
  def it(description, &block)
65
- loc = caller_locations(1, 1).first
66
- file = loc.path || loc.absolute_path || "(unknown)"
67
- ctx_name = File.basename(file, File.extname(file))
68
- ctx = Scampi::Context.new(ctx_name) {}
69
- ctx.it(description, &block)
70
- ctx.register
71
- Scampi.queue << ctx
65
+ block ||= proc { should.flunk "not implemented" }
66
+ Scampi.queue << [:spec, description, block]
72
67
  end
73
68
  end
@@ -1,5 +1,3 @@
1
1
  module Scampi
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.5"
3
3
  end
4
-
5
- require_relative '../rubygems_plugin'
@@ -1,5 +1,3 @@
1
1
  module Scampi
2
2
  VERSION = "<%= version %>"
3
3
  end
4
-
5
- require_relative '../rubygems_plugin'
data/lib/scampi.rb CHANGED
@@ -35,20 +35,26 @@ module Scampi
35
35
  @ran = true
36
36
 
37
37
  # Register: evaluate all describe blocks to discover specs
38
- @queue.each(&:register)
38
+ @queue.each { |item| item.register if item.is_a?(Context) }
39
39
 
40
- # TAP version + plan (one entry per top-level describe)
40
+ # TAP version + plan
41
41
  puts "TAP version 14"
42
42
  puts "1..#{@queue.size}"
43
43
 
44
- # Execute all specs as subtests
45
- @queue.each_with_index do |context, i|
46
- passed = context.execute(0)
44
+ # Execute: contexts become subtests, raw specs become flat lines
45
+ @queue.each_with_index do |item, i|
47
46
  n = i + 1
48
- if passed
49
- puts "#{"ok".green} #{n} - #{context.name}"
47
+ if item.is_a?(Context)
48
+ passed = item.execute(0)
49
+ if passed
50
+ puts "#{"ok".green} #{n} - #{item.name}"
51
+ else
52
+ puts "#{"not ok".red} #{n} - #{item.name}"
53
+ end
50
54
  else
51
- puts "#{"not ok".red} #{n} - #{context.name}"
55
+ _, description, block = item
56
+ Counter[:specifications] += 1
57
+ passed = run_bare_spec(description, block, n)
52
58
  end
53
59
  end
54
60
 
@@ -88,10 +94,51 @@ module Scampi
88
94
  false
89
95
  end
90
96
  end
97
+
98
+ def self.run_bare_spec(description, block, n)
99
+ handle_requirement(description, 0, n) do
100
+ begin
101
+ Counter[:depth] += 1
102
+ rescued = false
103
+ begin
104
+ prev_req = Counter[:requirements]
105
+ block.call
106
+ rescue Object => e
107
+ rescued = true
108
+ raise e
109
+ ensure
110
+ if Counter[:requirements] == prev_req and not rescued
111
+ raise Error.new(:missing, "empty specification: #{description}")
112
+ end
113
+ end
114
+ rescue SystemExit, Interrupt
115
+ raise
116
+ rescue Object => e
117
+ ErrorLog << "#{e.class}: #{e.message}\n"
118
+ e.backtrace.find_all { |line| line !~ /bin\/scampi|\/scampi\.rb:\d+/ }.
119
+ each_with_index { |line, i|
120
+ ErrorLog << "\t#{line}#{i==0 ? ": #{description}" : ""}\n"
121
+ }
122
+ ErrorLog << "\n"
123
+
124
+ if e.kind_of? Error
125
+ Counter[e.count_as] += 1
126
+ e.count_as.to_s.upcase
127
+ else
128
+ Counter[:errors] += 1
129
+ "ERROR: #{e.class}"
130
+ end
131
+ else
132
+ ""
133
+ ensure
134
+ Counter[:depth] -= 1
135
+ end
136
+ end
137
+ end
91
138
  end
92
139
 
93
140
  require_relative 'scampi/error'
94
141
  require_relative 'scampi/context'
95
142
  require_relative 'scampi/should'
96
143
  require_relative 'scampi/monkey_patches'
97
- require_relative 'rubygems_plugin'
144
+ require_relative 'scampi/kernel_ext'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scampi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan K