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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d87e08f77eb962d0a96b49fae22b76e3a557335b8b3c935dabc94c0359b474e2
4
+ data.tar.gz: 2d5b13dc5de16fe05273dd1863d273509ff00b75a1a0d7e9f72f330a3ff70b8f
5
+ SHA512:
6
+ metadata.gz: c42747d107699bbccbbe14764bda1f910f35cf8b7c11492bb5180268dc33fd92afa052d57afcc5f34c7757796bcc21ed2c759eaa10c579ef39b688f7a44a2abc
7
+ data.tar.gz: bc2e9579188b196604b8560231bf531238ba577158a3e38d085e24ceb78674230b77940ae3c94248233b0b1274591fde5c673be2bbf4d0bde586b3a724467bf7
data/.envrc ADDED
@@ -0,0 +1 @@
1
+ use flake
data/COPYING ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2007, 2008, 2012 Christian Neukirchen <purl.org/net/chneukirchen>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to
5
+ deal in the Software without restriction, including without limitation the
6
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ sell copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "colorize-extended"
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ scampi (0.1.1)
5
+ colorize-extended
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ colorize (1.1.0)
11
+ colorize-extended (0.1.0)
12
+ colorize (~> 1.1)
13
+
14
+ PLATFORMS
15
+ ruby
16
+ x86_64-linux
17
+
18
+ DEPENDENCIES
19
+ colorize-extended
20
+ scampi!
21
+
22
+ CHECKSUMS
23
+ colorize (1.1.0) sha256=30b5237f0603f6662ab8d1fc2bd4a96142b806c6415d79e45ef5fdc6a0cfc837
24
+ colorize-extended (0.1.0) sha256=e8c39986e41ee2e14623c8fa02cf851ef4b83d2fe1392daa2b4d81f0df7bedc9
25
+ scampi (0.1.1)
26
+
27
+ BUNDLED WITH
28
+ 4.0.7
data/README.rdoc ADDED
@@ -0,0 +1,290 @@
1
+ = Bacon -- small RSpec clone.
2
+
3
+ "Truth will sooner come out from error than from confusion."
4
+ ---Francis Bacon
5
+
6
+ Bacon is a small RSpec clone weighing less than 350 LoC but
7
+ nevertheless providing all essential features.
8
+
9
+
10
+ == Whirl-wind tour
11
+
12
+ require 'bacon'
13
+
14
+ describe 'A new array' do
15
+ before do
16
+ @ary = Array.new
17
+ end
18
+
19
+ it 'should be empty' do
20
+ @ary.should.be.empty
21
+ @ary.should.not.include 1
22
+ end
23
+
24
+ it 'should have zero size' do
25
+ @ary.size.should.equal 0
26
+ @ary.size.should.be.close 0.1, 0.5
27
+ end
28
+
29
+ it 'should raise on trying fetch any index' do
30
+ lambda { @ary.fetch 0 }.
31
+ should.raise(IndexError).
32
+ message.should.match(/out of array/)
33
+
34
+ # Alternatively:
35
+ should.raise(IndexError) { @ary.fetch 0 }
36
+ end
37
+
38
+ it 'should have an object identity' do
39
+ @ary.should.not.be.same_as Array.new
40
+ end
41
+
42
+ # Custom assertions are trivial to do, they are lambdas returning a
43
+ # boolean vale:
44
+ palindrome = lambda { |obj| obj == obj.reverse }
45
+ it 'should be a palindrome' do
46
+ @ary.should.be.a palindrome
47
+ end
48
+
49
+ it 'should have super powers' do
50
+ should.flunk "no super powers found"
51
+ end
52
+ end
53
+
54
+ Now run it:
55
+
56
+ $ bacon whirlwind.rb
57
+ A new array
58
+ - should be empty
59
+ - should have zero size
60
+ - should raise on trying fetch any index
61
+ - should have an object identity
62
+ - should be a palindrome
63
+ - should have super powers [FAILED]
64
+
65
+ Bacon::Error: no super powers found
66
+ ./whirlwind.rb:39: A new array - should have super powers
67
+ ./whirlwind.rb:38
68
+ ./whirlwind.rb:3
69
+
70
+ 6 specifications (9 requirements), 1 failures, 0 errors
71
+
72
+ If you want shorter output, use the Test::Unit format:
73
+
74
+ $ bacon -q whirlwind.rb
75
+ .....F
76
+ Bacon::Error: no super powers found
77
+ ./whirlwind.rb:39: A new array - should have super powers
78
+ ./whirlwind.rb:38
79
+ ./whirlwind.rb:3
80
+
81
+ 6 tests, 9 assertions, 1 failures, 0 errors
82
+
83
+ It also supports TAP:
84
+
85
+ $ bacon -p whirlwind.rb
86
+ ok 1 - should be empty
87
+ ok 2 - should have zero size
88
+ ok 3 - should raise on trying fetch any index
89
+ ok 4 - should have an object identity
90
+ ok 5 - should be a palindrome
91
+ not ok 6 - should have super powers: FAILED
92
+ # Bacon::Error: no super powers found
93
+ # ./whirlwind.rb:39: A new array - should have super powers
94
+ # ./whirlwind.rb:38
95
+ # ./whirlwind.rb:3
96
+ 1..6
97
+ # 6 tests, 9 assertions, 1 failures, 0 errors
98
+
99
+ $ bacon -p whirlwind.rb | taptap -q
100
+ Tests took 0.00 seconds.
101
+ FAILED tests 6
102
+ 6) should have super powers: FAILED
103
+
104
+ Failed 1/6 tests, 83.33% okay.
105
+
106
+ (taptap is included with scampi)
107
+
108
+ As of Bacon 1.1, it also supports Knock:
109
+
110
+ $ bacon -k whirlwind.rb
111
+ ok - should be empty
112
+ ok - should have zero size
113
+ ok - should raise on trying fetch any index
114
+ ok - should have an object identity
115
+ ok - should be a palindrome
116
+ not ok - should have super powers: FAILED
117
+ # Bacon::Error: no super powers found
118
+ # ./whirlwind.rb:39: A new array - should have super powers
119
+ # ./whirlwind.rb:38
120
+ # ./whirlwind.rb:3
121
+
122
+ $ bacon -k whirlwind.rb | kn-sum
123
+ 6 tests, 1 failed (83.3333% succeeded)
124
+
125
+ (knock is available from http://github.com/chneukirchen/knock/)
126
+
127
+
128
+ == Implemented assertions
129
+
130
+ * should.<predicate> and should.be.<predicate>
131
+ * should.equal
132
+ * should.match
133
+ * should.be.identical_to / should.be.same_as
134
+ * should.raise(*exceptions) { }
135
+ * should.change { }
136
+ * should.throw(symbol) { }
137
+ * should.satisfy { |object| }
138
+
139
+
140
+ == Added core predicates
141
+
142
+ * Object#true?
143
+ * Object#false?
144
+ * Proc#change?
145
+ * Proc#raise?
146
+ * Proc#throw?
147
+ * Numeric#close?
148
+
149
+
150
+ == before/after
151
+
152
+ before and after need to be defined before the first specification in
153
+ a context and are run before and after each specification.
154
+
155
+ As of Bacon 1.1, before and after do nest in nested contexts.
156
+
157
+
158
+ == Shared contexts
159
+
160
+ You can define shared contexts in Bacon like this:
161
+
162
+ shared "an empty container" do
163
+ it "should have size zero" do
164
+ end
165
+
166
+ it "should be empty" do
167
+ end
168
+ end
169
+
170
+ context "A new array" do
171
+ behaves_like "an empty container"
172
+ end
173
+
174
+ These contexts are not executed on their own, but can be included with
175
+ behaves_like in other contexts. You can use shared contexts to
176
+ structure suites with many recurring specifications.
177
+
178
+
179
+ == Matchers
180
+
181
+ Custom matchers are simply lambdas returning a boolean value, for
182
+ example:
183
+
184
+ def shorter_than(max_size)
185
+ lambda { |obj| obj.size < max_size }
186
+ end
187
+
188
+ [1,2,3].should.be shorter_than(5)
189
+
190
+ You can use modules and extend to group matchers for use in multiple
191
+ contexts.
192
+
193
+
194
+ == bacon standalone runner
195
+
196
+ -s, --specdox do AgileDox-like output (default)
197
+ -q, --quiet do Test::Unit-like non-verbose output
198
+ -p, --tap do TAP (Test Anything Protocol) output
199
+ -k, --knock do Knock output
200
+ -o, --output FORMAT do FORMAT (SpecDox/TestUnit/Tap) output
201
+ -Q, --no-backtrace don't print backtraces
202
+ -a, --automatic gather tests from ./test/, include ./lib/
203
+ -n, --name NAME runs tests matching regexp NAME
204
+ -t, --testcase TESTCASE runs tests in TestCases matching regexp TESTCASE
205
+
206
+ If you don't want to use the standalone runner, run
207
+ Bacon.summary_on_exit to install an exit handler showing the summary.
208
+
209
+
210
+ == Object#should
211
+
212
+ You can use Object#should outside of contexts, where the result of
213
+ assertion will be returned as a boolean. This is nice for
214
+ demonstrations, quick checks and doctest tests.
215
+
216
+ >> require 'bacon'
217
+ >> (1 + 1).should.equal 2
218
+ => true
219
+ >> (6*9).should.equal 42
220
+ => false
221
+
222
+
223
+ == Converting specs
224
+
225
+ spec-converter is a simple tool to convert test-unit or dust style
226
+ tests to test/spec specs.
227
+
228
+ It can be found at https://github.com/relevance/spec_converter.
229
+
230
+
231
+ == Thanks to
232
+
233
+ * Michael Fellinger, for fixing Bacon for 1.9 and various improvements.
234
+ * Gabriele Renzi, for implementing Context#should.
235
+ * Yossef Mendelssohn, for nested contexts.
236
+ * everyone contributing bug fixes.
237
+
238
+
239
+ == History
240
+
241
+ * January 7, 2008: First public release 0.9.
242
+
243
+ * July 6th, 2008: Second public release 1.0.
244
+ * Add Context#should as a shortcut for Context#it('should ' + _).
245
+ * describe now supports multiple arguments for better organization.
246
+ * Empty specifications are now erroneous.
247
+ * after-blocks run in the case of exceptions too.
248
+ * Bug fixes.
249
+
250
+ * November 30th, 2008: Third public release 1.1.
251
+ * Nested before/after.
252
+ * Add -Q/--no-backtraces to not show details about failed specifications.
253
+ * Add Knock output.
254
+ * Bug fixes.
255
+
256
+ * December 21th, 2012: Fourth public release 1.2.0.
257
+ * #satisfy will not pass arguments anymore to the block, use lexical scope.
258
+ * Fixed Context#change?.
259
+ * Add support for finding specs named like spec/**/*_spec.rb.
260
+ * Contexts nest properly.
261
+ * Timer in TestUnitOutput.
262
+ * Nested output for SpecDoxOutput.
263
+ * Small cleanups and more tests.
264
+
265
+
266
+ == Contact
267
+
268
+ Please mail bugs, suggestions and patches to
269
+ <mailto:chneukirchen@gmail.com>.
270
+
271
+ Git repository (patches rebased on HEAD are most welcome):
272
+ http://github.com/chneukirchen/bacon
273
+ git://github.com/chneukirchen/bacon.git
274
+
275
+
276
+ == Copying
277
+
278
+ Copyright (C) 2007, 2008, 2012 Christian Neukirchen <purl.org/net/chneukirchen>
279
+
280
+ Bacon is freely distributable under the terms of an MIT-style license.
281
+ See COPYING or http://www.opensource.org/licenses/mit-license.php.
282
+
283
+
284
+ == Links
285
+
286
+ Behavior-Driven Development:: <http://behaviour-driven.org/>
287
+ RSpec:: <http://rspec.rubyforge.org/>
288
+ test/spec:: <http://test-spec.rubyforge.org/>
289
+
290
+ Christian Neukirchen:: <http://chneukirchen.org/>
data/Rakefile ADDED
@@ -0,0 +1,80 @@
1
+ # Rakefile for Scampi. -*-ruby-*-
2
+ require 'rdoc/task'
3
+ require 'rake/testtask'
4
+
5
+
6
+ desc "Run all the tests"
7
+ task :default => [:test]
8
+
9
+ desc "Do predistribution stuff"
10
+ task :predist => [:chmod, :changelog, :rdoc]
11
+
12
+
13
+ desc "Make an archive as .tar.gz"
14
+ task :dist => [:test, :predist] do
15
+ sh "git archive --format=tar --prefix=#{release}/ HEAD^{tree} >#{release}.tar"
16
+ sh "pax -waf #{release}.tar -s ':^:#{release}/:' RDOX ChangeLog doc"
17
+ sh "gzip -f -9 #{release}.tar"
18
+ end
19
+
20
+ # Helper to retrieve the "revision number" of the git tree.
21
+ def git_tree_version
22
+ if File.directory?(".git")
23
+ @tree_version ||= `git describe`.strip.sub('-', '.')
24
+ @tree_version << ".0" unless @tree_version.count('.') == 2
25
+ else
26
+ $: << "lib"
27
+ require 'scampi'
28
+ @tree_version = Scampi::VERSION
29
+ end
30
+ @tree_version
31
+ end
32
+
33
+ def gem_version
34
+ git_tree_version.gsub(/-.*/, '')
35
+ end
36
+
37
+ def release
38
+ "scampi-#{git_tree_version}"
39
+ end
40
+
41
+ def manifest
42
+ `git ls-files`.split("\n") - [".gitignore"]
43
+ end
44
+
45
+
46
+ desc "Make binaries executable"
47
+ task :chmod do
48
+ Dir["exe/*"].each { |binary| File.chmod(0775, binary) }
49
+ end
50
+
51
+ desc "Generate a ChangeLog"
52
+ task :changelog do
53
+ sh "git log --format='%ad %an <%ae>%n%w(79,2,4)* %s%n%n%w(76,4,4)%b' |grep -v darcs-hash: |cat -s >ChangeLog"
54
+ end
55
+
56
+
57
+ desc "Generate RDox"
58
+ task "RDOX" do
59
+ sh "exe/scampi -Ilib --automatic --specdox >RDOX"
60
+ end
61
+
62
+ desc "Run all the tests"
63
+ task :test do
64
+ ruby "exe/scampi -w -Ilib --automatic --quiet"
65
+ end
66
+
67
+
68
+ desc "Generate RDoc documentation"
69
+ Rake::RDocTask.new(:rdoc) do |rdoc|
70
+ rdoc.options << '--line-numbers' << '--inline-source' <<
71
+ '--main' << 'README.rdoc' <<
72
+ '--title' << 'Scampi Documentation' <<
73
+ '--charset' << 'utf-8'
74
+ rdoc.rdoc_dir = "doc"
75
+ rdoc.rdoc_files.include 'README.rdoc'
76
+ rdoc.rdoc_files.include 'COPYING'
77
+ rdoc.rdoc_files.include 'RDOX'
78
+ rdoc.rdoc_files.include('lib/scampi.rb')
79
+ end
80
+ task :rdoc => ["RDOX"]
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "erb"
5
+ require_relative "../lib/scampi/version"
6
+
7
+ USAGE = <<~TEXT
8
+ Usage: bin/increment-version <major|minor|patch>
9
+ TEXT
10
+
11
+ segment = ARGV[0]
12
+
13
+ unless %w[major minor patch].include?(segment)
14
+ warn USAGE
15
+ exit 1
16
+ end
17
+
18
+ current = Scampi::VERSION
19
+ major, minor, patch = current.split(".").map(&:to_i)
20
+
21
+ case segment
22
+ when "major"
23
+ major += 1
24
+ minor = 0
25
+ patch = 0
26
+ when "minor"
27
+ minor += 1
28
+ patch = 0
29
+ when "patch"
30
+ patch += 1
31
+ end
32
+
33
+ version = "#{major}.#{minor}.#{patch}"
34
+
35
+ template_path = File.expand_path("../lib/scampi/version.rb.erb", __dir__)
36
+ output_path = File.expand_path("../lib/scampi/version.rb", __dir__)
37
+
38
+ template = ERB.new(File.read(template_path))
39
+ result = template.result(binding)
40
+
41
+ File.write(output_path, result)
42
+
43
+ `bundle install`
44
+
45
+ puts "#{current} -> #{version}"
data/bin/release-gem ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../lib/scampi/version"
5
+
6
+ local_version = Scampi::VERSION
7
+ gem_name = "scampi"
8
+ gemspec = "scampi.gemspec"
9
+
10
+ puts "Local version: #{local_version}"
11
+
12
+ remote_output = `gem specification #{gem_name} version --remote 2>&1`
13
+
14
+ if $?.success?
15
+ remote_version = remote_output[/version: (.+)/, 1]&.strip
16
+ puts "Remote version: #{remote_version}"
17
+
18
+ if Gem::Version.new(local_version) <= Gem::Version.new(remote_version)
19
+ abort "ERROR: Local version (#{local_version}) has not been incremented past remote (#{remote_version})"
20
+ end
21
+ else
22
+ puts "Gem not yet published remotely, proceeding with first release"
23
+ end
24
+
25
+ puts "Building #{gemspec}..."
26
+ system("gem build #{gemspec}") || abort("ERROR: gem build failed")
27
+
28
+ gem_file = "#{gem_name}-#{local_version}.gem"
29
+ puts "Pushing #{gem_file}..."
30
+ system("gem push #{gem_file}") || abort("ERROR: gem push failed")
31
+
32
+ puts "Released #{gem_name} #{local_version}"
data/bin/test ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ exec File.expand_path('../exe/scampi', __dir__), *ARGV
data/exe/scampi ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
5
+ require 'scampi'
6
+
7
+ ENV["TEST"] = "true"
8
+
9
+ files = if ARGV.empty?
10
+ Dir.glob("test/**/*.rb")
11
+ else
12
+ ARGV.flat_map { |pattern| Dir.glob(pattern) }
13
+ end
14
+
15
+ if files.empty?
16
+ $stderr.puts "no test files found"
17
+ exit 1
18
+ end
19
+
20
+ files.each { |file|
21
+ old_verbose, $-w = $-w, nil
22
+ load file
23
+ $-w = old_verbose
24
+ }
25
+
26
+ Scampi.run
27
+ exit(Scampi::Counter[:errors] + Scampi::Counter[:failed] > 0 ? 1 : 0)
data/flake.lock ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "nodes": {
3
+ "nixpkgs": {
4
+ "locked": {
5
+ "lastModified": 1776548001,
6
+ "narHash": "sha256-ZSK0NL4a1BwVbbTBoSnWgbJy9HeZFXLYQizjb2DPF24=",
7
+ "owner": "NixOS",
8
+ "repo": "nixpkgs",
9
+ "rev": "b12141ef619e0a9c1c84dc8c684040326f27cdcc",
10
+ "type": "github"
11
+ },
12
+ "original": {
13
+ "owner": "NixOS",
14
+ "ref": "nixos-unstable",
15
+ "repo": "nixpkgs",
16
+ "type": "github"
17
+ }
18
+ },
19
+ "root": {
20
+ "inputs": {
21
+ "nixpkgs": "nixpkgs",
22
+ "utils": "utils"
23
+ }
24
+ },
25
+ "systems": {
26
+ "locked": {
27
+ "lastModified": 1681028828,
28
+ "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
29
+ "owner": "nix-systems",
30
+ "repo": "default",
31
+ "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
32
+ "type": "github"
33
+ },
34
+ "original": {
35
+ "owner": "nix-systems",
36
+ "repo": "default",
37
+ "type": "github"
38
+ }
39
+ },
40
+ "utils": {
41
+ "inputs": {
42
+ "systems": "systems"
43
+ },
44
+ "locked": {
45
+ "lastModified": 1731533236,
46
+ "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
47
+ "owner": "numtide",
48
+ "repo": "flake-utils",
49
+ "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
50
+ "type": "github"
51
+ },
52
+ "original": {
53
+ "owner": "numtide",
54
+ "repo": "flake-utils",
55
+ "type": "github"
56
+ }
57
+ }
58
+ },
59
+ "root": "root",
60
+ "version": 7
61
+ }
data/flake.nix ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ description = "Ruby gem flake";
3
+
4
+ inputs = {
5
+ nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6
+ utils.url = "github:numtide/flake-utils";
7
+ };
8
+ outputs = { self, nixpkgs, utils }:
9
+ utils.lib.eachDefaultSystem (system:
10
+ let
11
+ pkgs = nixpkgs.legacyPackages.${system};
12
+ ruby = pkgs.ruby_3_4; # Specify version
13
+ kubectlWithKubeconfig = pkgs.writeShellScriptBin "kubectl" ''
14
+ #!${pkgs.bash}/bin/bash
15
+ KUBECONFIG="$PWD/kubeconfig.yaml" ${pkgs.kubectl}/bin/kubectl "$@"
16
+ '';
17
+ in
18
+ {
19
+ devShells.default = pkgs.mkShell {
20
+ nativeBuildInputs = [
21
+ pkgs.pkg-config # native extension discovery
22
+ ];
23
+
24
+ buildInputs = [
25
+ ruby
26
+ pkgs.libyaml # psych gem
27
+ pkgs.openssl # openssl gem
28
+ kubectlWithKubeconfig
29
+ ];
30
+
31
+ shellHook = ''
32
+ export GEM_HOME="$PWD/.gem"
33
+ export GEM_PATH="$GEM_HOME"
34
+ export PATH="$GEM_HOME/bin:$PATH"
35
+ export BUNDLE_PATH="$GEM_HOME"
36
+ export BUNDLE_BIN="$GEM_HOME/bin"
37
+ export KUBECONFIG="$PWD/kubeconfig.yaml"
38
+ '';
39
+ };
40
+ }
41
+ );
42
+ }
43
+
@@ -0,0 +1,38 @@
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