do_riak 0.10.1.pre
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.
- data/CHANGELOG +2 -0
- data/Gemfile +9 -0
- data/LICENSE +20 -0
- data/README.textile +23 -0
- data/TODO.txt +4 -0
- data/deps.rip +8 -0
- data/do_riak.gemspec +40 -0
- data/do_riak.pre.gemspec +8 -0
- data/gems/cache/bacon-1.1.0.gem +0 -0
- data/gems/cache/code-cleaner-0.8.1.gem +0 -0
- data/gems/cache/nake-0.0.8.gem +0 -0
- data/gems/cache/term-ansicolor-1.0.4.gem +0 -0
- data/gems/environment.rb +107 -0
- data/gems/gems/bacon-1.1.0/COPYING +18 -0
- data/gems/gems/bacon-1.1.0/ChangeLog +220 -0
- data/gems/gems/bacon-1.1.0/RDOX +69 -0
- data/gems/gems/bacon-1.1.0/README +290 -0
- data/gems/gems/bacon-1.1.0/Rakefile +138 -0
- data/gems/gems/bacon-1.1.0/bin/bacon +117 -0
- data/gems/gems/bacon-1.1.0/lib/autotest/bacon.rb +36 -0
- data/gems/gems/bacon-1.1.0/lib/autotest/bacon_rspec.rb +2 -0
- data/gems/gems/bacon-1.1.0/lib/autotest/discover.rb +9 -0
- data/gems/gems/bacon-1.1.0/lib/bacon.rb +354 -0
- data/gems/gems/bacon-1.1.0/test/spec_bacon.rb +374 -0
- data/gems/gems/bacon-1.1.0/test/spec_should.rb +32 -0
- data/gems/gems/code-cleaner-0.8.1/LICENSE +20 -0
- data/gems/gems/code-cleaner-0.8.1/README.textile +87 -0
- data/gems/gems/code-cleaner-0.8.1/TODO.txt +1 -0
- data/gems/gems/code-cleaner-0.8.1/bin/code-cleaner +143 -0
- data/gems/gems/code-cleaner-0.8.1/code-cleaner-0.8.gem +0 -0
- data/gems/gems/code-cleaner-0.8.1/code-cleaner.gemspec +25 -0
- data/gems/gems/code-cleaner-0.8.1/support/pre-commit.erb +70 -0
- data/gems/gems/code-cleaner-0.8.1/tasks.rb +13 -0
- data/gems/gems/code-cleaner-0.8.1/tasks/code-cleaner.nake +49 -0
- data/gems/gems/code-cleaner-0.8.1/tasks/code-cleaner.rake +22 -0
- data/gems/gems/code-cleaner-0.8.1/tasks/code-cleaner.thor +35 -0
- data/gems/gems/nake-0.0.8/CHANGELOG +48 -0
- data/gems/gems/nake-0.0.8/LICENSE +20 -0
- data/gems/gems/nake-0.0.8/README.textile +39 -0
- data/gems/gems/nake-0.0.8/TODO.txt +23 -0
- data/gems/gems/nake-0.0.8/bin/nake +66 -0
- data/gems/gems/nake-0.0.8/bin/nrake +4 -0
- data/gems/gems/nake-0.0.8/bin/rake2nake +1 -0
- data/gems/gems/nake-0.0.8/bin/snake +41 -0
- data/gems/gems/nake-0.0.8/bm/Rakefile +28 -0
- data/gems/gems/nake-0.0.8/bm/bms.rb +56 -0
- data/gems/gems/nake-0.0.8/bm/output.txt +5 -0
- data/gems/gems/nake-0.0.8/bm/tasks.rb +21 -0
- data/gems/gems/nake-0.0.8/bm/tmp/test.c +6 -0
- data/gems/gems/nake-0.0.8/bm/tmp/www/index.html +1 -0
- data/gems/gems/nake-0.0.8/deps.rb +5 -0
- data/gems/gems/nake-0.0.8/deps.rip +5 -0
- data/gems/gems/nake-0.0.8/examples/arguments.rb +38 -0
- data/gems/gems/nake-0.0.8/examples/basic.rb +5 -0
- data/gems/gems/nake-0.0.8/examples/boot.rb +18 -0
- data/gems/gems/nake-0.0.8/examples/complex.rb +9 -0
- data/gems/gems/nake-0.0.8/examples/configuration.rb +15 -0
- data/gems/gems/nake-0.0.8/examples/default.rb +10 -0
- data/gems/gems/nake-0.0.8/examples/default_proc.rb +11 -0
- data/gems/gems/nake-0.0.8/examples/dependencies.rb +10 -0
- data/gems/gems/nake-0.0.8/examples/description.rb +33 -0
- data/gems/gems/nake-0.0.8/examples/file.rb +22 -0
- data/gems/gems/nake-0.0.8/examples/helpers.rb +3 -0
- data/gems/gems/nake-0.0.8/examples/invoking.rb +14 -0
- data/gems/gems/nake-0.0.8/examples/rules.rb +0 -0
- data/gems/gems/nake-0.0.8/examples/script.rb +20 -0
- data/gems/gems/nake-0.0.8/examples/task_arguments.rb +27 -0
- data/gems/gems/nake-0.0.8/features/arguments.feature +22 -0
- data/gems/gems/nake-0.0.8/features/basic.feature +6 -0
- data/gems/gems/nake-0.0.8/features/boot.feature +5 -0
- data/gems/gems/nake-0.0.8/features/builtin_arguments.feature +14 -0
- data/gems/gems/nake-0.0.8/features/complex.feature +6 -0
- data/gems/gems/nake-0.0.8/features/configuration.feature +10 -0
- data/gems/gems/nake-0.0.8/features/default.feature +10 -0
- data/gems/gems/nake-0.0.8/features/default_proc.feature +6 -0
- data/gems/gems/nake-0.0.8/features/dependencies.feature +16 -0
- data/gems/gems/nake-0.0.8/features/description.feature +0 -0
- data/gems/gems/nake-0.0.8/features/env.rb +11 -0
- data/gems/gems/nake-0.0.8/features/executable.feature +29 -0
- data/gems/gems/nake-0.0.8/features/file.feature +23 -0
- data/gems/gems/nake-0.0.8/features/helpers.feature +6 -0
- data/gems/gems/nake-0.0.8/features/invoking.feature +14 -0
- data/gems/gems/nake-0.0.8/features/rules.feature +0 -0
- data/gems/gems/nake-0.0.8/features/script.feature +10 -0
- data/gems/gems/nake-0.0.8/features/steps.rb +39 -0
- data/gems/gems/nake-0.0.8/features/task_arguments.feature +10 -0
- data/gems/gems/nake-0.0.8/lib/nake.rb +103 -0
- data/gems/gems/nake-0.0.8/lib/nake/abstract_task.rb +175 -0
- data/gems/gems/nake-0.0.8/lib/nake/args.rb +65 -0
- data/gems/gems/nake-0.0.8/lib/nake/argv.rb +47 -0
- data/gems/gems/nake-0.0.8/lib/nake/colors.rb +22 -0
- data/gems/gems/nake-0.0.8/lib/nake/dsl.rb +70 -0
- data/gems/gems/nake-0.0.8/lib/nake/file_task.rb +62 -0
- data/gems/gems/nake-0.0.8/lib/nake/helpers.rb +65 -0
- data/gems/gems/nake-0.0.8/lib/nake/rake.rb +38 -0
- data/gems/gems/nake-0.0.8/lib/nake/rule.rb +35 -0
- data/gems/gems/nake-0.0.8/lib/nake/struct_hash.rb +22 -0
- data/gems/gems/nake-0.0.8/lib/nake/task.rb +6 -0
- data/gems/gems/nake-0.0.8/lib/nake/tasks/bundle.rb +30 -0
- data/gems/gems/nake-0.0.8/lib/nake/tasks/clean.rb +12 -0
- data/gems/gems/nake-0.0.8/lib/nake/tasks/gem.rb +29 -0
- data/gems/gems/nake-0.0.8/lib/nake/tasks/release.rb +43 -0
- data/gems/gems/nake-0.0.8/lib/nake/tasks/rip.rb +33 -0
- data/gems/gems/nake-0.0.8/lib/nake/tasks/spec.rb +20 -0
- data/gems/gems/nake-0.0.8/lib/nake/template.rb +51 -0
- data/gems/gems/nake-0.0.8/nake-0.0.8.pre.gem +0 -0
- data/gems/gems/nake-0.0.8/nake.gemspec +42 -0
- data/gems/gems/nake-0.0.8/nake.pre.gemspec +8 -0
- data/gems/gems/nake-0.0.8/spec/nake/abstract_task_spec.rb +0 -0
- data/gems/gems/nake-0.0.8/spec/nake/args_spec.rb +0 -0
- data/gems/gems/nake-0.0.8/spec/nake/argv_spec.rb +51 -0
- data/gems/gems/nake-0.0.8/spec/nake/colors_spec.rb +0 -0
- data/gems/gems/nake-0.0.8/spec/nake/dsl_spec.rb +35 -0
- data/gems/gems/nake-0.0.8/spec/nake/file_task_spec.rb +0 -0
- data/gems/gems/nake-0.0.8/spec/nake/helpers_spec.rb +14 -0
- data/gems/gems/nake-0.0.8/spec/nake/rake_spec.rb +0 -0
- data/gems/gems/nake-0.0.8/spec/nake/rule_spec.rb +72 -0
- data/gems/gems/nake-0.0.8/spec/nake/struct_hash_spec.rb +0 -0
- data/gems/gems/nake-0.0.8/spec/nake/task_spec.rb +72 -0
- data/gems/gems/nake-0.0.8/spec/nake/tasks/bundle_spec.rb +28 -0
- data/gems/gems/nake-0.0.8/spec/nake/tasks/clean_spec.rb +0 -0
- data/gems/gems/nake-0.0.8/spec/nake/tasks/gem_spec.rb +0 -0
- data/gems/gems/nake-0.0.8/spec/nake/tasks/release_spec.rb +0 -0
- data/gems/gems/nake-0.0.8/spec/nake/tasks/rip_spec.rb +0 -0
- data/gems/gems/nake-0.0.8/spec/nake/tasks/spec_spec.rb +0 -0
- data/gems/gems/nake-0.0.8/spec/nake/tasks_spec.rb +48 -0
- data/gems/gems/nake-0.0.8/spec/nake/template_spec.rb +84 -0
- data/gems/gems/nake-0.0.8/spec/nake_spec.rb +9 -0
- data/gems/gems/nake-0.0.8/spec/spec.opts +5 -0
- data/gems/gems/nake-0.0.8/spec/spec_helper.rb +29 -0
- data/gems/gems/nake-0.0.8/spec/stubs/database.yml.erb +9 -0
- data/gems/gems/nake-0.0.8/spec/stubs/database.yml.tt +9 -0
- data/gems/gems/nake-0.0.8/tasks.rb +42 -0
- data/gems/gems/term-ansicolor-1.0.4/CHANGES +22 -0
- data/gems/gems/term-ansicolor-1.0.4/COPYING +340 -0
- data/gems/gems/term-ansicolor-1.0.4/README +31 -0
- data/gems/gems/term-ansicolor-1.0.4/Rakefile +86 -0
- data/gems/gems/term-ansicolor-1.0.4/VERSION +1 -0
- data/gems/gems/term-ansicolor-1.0.4/doc-main.txt +119 -0
- data/gems/gems/term-ansicolor-1.0.4/examples/cdiff.rb +19 -0
- data/gems/gems/term-ansicolor-1.0.4/examples/example.rb +89 -0
- data/gems/gems/term-ansicolor-1.0.4/install.rb +15 -0
- data/gems/gems/term-ansicolor-1.0.4/lib/term/ansicolor.rb +102 -0
- data/gems/gems/term-ansicolor-1.0.4/lib/term/ansicolor/version.rb +10 -0
- data/gems/gems/term-ansicolor-1.0.4/term-ansicolor.gemspec +20 -0
- data/gems/specifications/bacon-1.1.0.gemspec +30 -0
- data/gems/specifications/code-cleaner-0.8.1.gemspec +31 -0
- data/gems/specifications/nake-0.0.8.gemspec +35 -0
- data/gems/specifications/term-ansicolor-1.0.4.gemspec +30 -0
- data/lib/do_riak.rb +10 -0
- data/lib/do_riak/errors.rb +11 -0
- data/lib/do_riak/transaction.rb +24 -0
- data/lib/do_riak/version.rb +7 -0
- data/script/bacon +3 -0
- data/script/code-cleaner +3 -0
- data/script/nake +3 -0
- data/spec/command_spec.rb +8 -0
- data/spec/connection_spec.rb +17 -0
- data/spec/reader_spec.rb +8 -0
- data/spec/result_spec.rb +12 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/typecast/array_spec.rb +8 -0
- data/spec/typecast/bigdecimal_spec.rb +8 -0
- data/spec/typecast/boolean_spec.rb +8 -0
- data/spec/typecast/byte_array_spec.rb +8 -0
- data/spec/typecast/class_spec.rb +8 -0
- data/spec/typecast/date_spec.rb +8 -0
- data/spec/typecast/datetime_spec.rb +8 -0
- data/spec/typecast/float_spec.rb +12 -0
- data/spec/typecast/integer_spec.rb +8 -0
- data/spec/typecast/nil_spec.rb +16 -0
- data/spec/typecast/other_spec.rb +8 -0
- data/spec/typecast/range_spec.rb +8 -0
- data/spec/typecast/string_spec.rb +8 -0
- data/spec/typecast/time_spec.rb +8 -0
- data/tasks.rb +37 -0
- metadata +238 -0
@@ -0,0 +1,117 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'optparse'
|
5
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '../lib/')
|
6
|
+
module Bacon; end
|
7
|
+
|
8
|
+
automatic = false
|
9
|
+
output = 'SpecDoxOutput'
|
10
|
+
|
11
|
+
opts = OptionParser.new("", 24, ' ') { |opts|
|
12
|
+
opts.banner = "Usage: bacon [options] [files | -a] [-- untouched arguments]"
|
13
|
+
|
14
|
+
opts.separator ""
|
15
|
+
opts.separator "Ruby options:"
|
16
|
+
|
17
|
+
lineno = 1
|
18
|
+
opts.on("-e", "--eval LINE", "evaluate a LINE of code") { |line|
|
19
|
+
eval line, TOPLEVEL_BINDING, "-e", lineno
|
20
|
+
lineno += 1
|
21
|
+
}
|
22
|
+
|
23
|
+
opts.on("-d", "--debug", "set debugging flags (set $DEBUG to true)") {
|
24
|
+
$DEBUG = true
|
25
|
+
}
|
26
|
+
opts.on("-w", "--warn", "turn warnings on for your script") {
|
27
|
+
$-w = true
|
28
|
+
}
|
29
|
+
|
30
|
+
opts.on("-I", "--include PATH",
|
31
|
+
"specify $LOAD_PATH (may be used more than once)") { |path|
|
32
|
+
$LOAD_PATH.unshift(*path.split(":"))
|
33
|
+
}
|
34
|
+
|
35
|
+
opts.on("-r", "--require LIBRARY",
|
36
|
+
"require the library, before executing your script") { |library|
|
37
|
+
require library
|
38
|
+
}
|
39
|
+
|
40
|
+
opts.separator ""
|
41
|
+
opts.separator "bacon options:"
|
42
|
+
|
43
|
+
opts.on("-s", "--specdox", "do AgileDox-like output (default)") {
|
44
|
+
output = 'SpecDoxOutput'
|
45
|
+
}
|
46
|
+
opts.on("-q", "--quiet", "do Test::Unit-like non-verbose output") {
|
47
|
+
output = 'TestUnitOutput'
|
48
|
+
}
|
49
|
+
opts.on("-p", "--tap", "do TAP (Test Anything Protocol) output") {
|
50
|
+
output = 'TapOutput'
|
51
|
+
}
|
52
|
+
opts.on("-k", "--knock", "do Knock output") {
|
53
|
+
output = 'KnockOutput'
|
54
|
+
}
|
55
|
+
|
56
|
+
opts.on("-o", "--output FORMAT",
|
57
|
+
"do FORMAT (SpecDox/TestUnit/Tap) output") { |format|
|
58
|
+
output = format + "Output"
|
59
|
+
}
|
60
|
+
opts.on("-Q", "--no-backtrace", "don't print backtraces") {
|
61
|
+
Bacon.const_set :Backtraces, false
|
62
|
+
}
|
63
|
+
|
64
|
+
opts.on("-a", "--automatic", "gather tests from ./test/, include ./lib/") {
|
65
|
+
$LOAD_PATH.unshift "lib" if File.directory? "lib"
|
66
|
+
automatic = true
|
67
|
+
}
|
68
|
+
|
69
|
+
opts.on('-n', '--name NAME', String,
|
70
|
+
"runs tests matching regexp NAME") { |n|
|
71
|
+
Bacon.const_set :RestrictName, Regexp.new(n)
|
72
|
+
}
|
73
|
+
|
74
|
+
opts.on('-t', '--testcase TESTCASE', String,
|
75
|
+
"runs tests in TestCases matching regexp TESTCASE") { |t|
|
76
|
+
Bacon.const_set :RestrictContext, Regexp.new(t)
|
77
|
+
}
|
78
|
+
|
79
|
+
opts.separator ""
|
80
|
+
opts.separator "Common options:"
|
81
|
+
|
82
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
83
|
+
puts opts
|
84
|
+
exit
|
85
|
+
end
|
86
|
+
|
87
|
+
opts.on_tail("--version", "Show version") do
|
88
|
+
require 'bacon'
|
89
|
+
puts "bacon #{Bacon::VERSION}"
|
90
|
+
exit
|
91
|
+
end
|
92
|
+
|
93
|
+
opts.parse! ARGV
|
94
|
+
}
|
95
|
+
|
96
|
+
files = ARGV
|
97
|
+
|
98
|
+
if automatic
|
99
|
+
files.concat Dir["test/**/test_*.rb"]
|
100
|
+
files.concat Dir["test/**/spec_*.rb"]
|
101
|
+
files.concat Dir["spec/**/spec_*.rb"]
|
102
|
+
end
|
103
|
+
|
104
|
+
if files.empty?
|
105
|
+
puts opts.banner
|
106
|
+
exit 1
|
107
|
+
end
|
108
|
+
|
109
|
+
require 'bacon'
|
110
|
+
|
111
|
+
Bacon.extend Bacon.const_get(output) rescue abort "No such formatter: #{output}"
|
112
|
+
Bacon.summary_on_exit
|
113
|
+
|
114
|
+
files.each { |file|
|
115
|
+
load file
|
116
|
+
}
|
117
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
Autotest.add_hook :initialize do |att|
|
2
|
+
att.clear_mappings
|
3
|
+
|
4
|
+
att.add_mapping(%r%^(test|spec)/.*\.rb$%) do |filename, _|
|
5
|
+
filename
|
6
|
+
end
|
7
|
+
|
8
|
+
att.add_mapping(%r%^lib/(.*)\.rb$%) do |filename, m|
|
9
|
+
lib_path = m[1]
|
10
|
+
spec = File.basename(lib_path)
|
11
|
+
path = File.dirname(lib_path)
|
12
|
+
[
|
13
|
+
"test/#{path}/test_#{spec}.rb",
|
14
|
+
"test/#{path}/spec_#{spec}.rb",
|
15
|
+
"spec/#{path}/spec_#{spec}.rb",
|
16
|
+
# TODO : decide if the follow 'rspec style' name should be allowed?
|
17
|
+
# "spec/#{path}/#{spec}_spec.rb"
|
18
|
+
]
|
19
|
+
end
|
20
|
+
|
21
|
+
false
|
22
|
+
end
|
23
|
+
|
24
|
+
class Autotest::Bacon < Autotest
|
25
|
+
def initialize
|
26
|
+
super
|
27
|
+
self.libs = %w[. lib test spec].join(File::PATH_SEPARATOR)
|
28
|
+
end
|
29
|
+
|
30
|
+
def make_test_cmd(files_to_test)
|
31
|
+
args = files_to_test.keys.flatten.join(' ')
|
32
|
+
args = '-a' if args.empty?
|
33
|
+
# TODO : make regex to pass to -n using values
|
34
|
+
"#{ruby} -S bacon -o TestUnit #{args}"
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,354 @@
|
|
1
|
+
# Bacon -- small RSpec clone.
|
2
|
+
#
|
3
|
+
# "Truth will sooner come out from error than from confusion." ---Francis Bacon
|
4
|
+
|
5
|
+
# Copyright (C) 2007, 2008 Christian Neukirchen <purl.org/net/chneukirchen>
|
6
|
+
#
|
7
|
+
# Bacon is freely distributable under the terms of an MIT-style license.
|
8
|
+
# See COPYING or http://www.opensource.org/licenses/mit-license.php.
|
9
|
+
|
10
|
+
module Bacon
|
11
|
+
VERSION = "1.1"
|
12
|
+
|
13
|
+
Counter = Hash.new(0)
|
14
|
+
ErrorLog = ""
|
15
|
+
Shared = Hash.new { |_, name|
|
16
|
+
raise NameError, "no such context: #{name.inspect}"
|
17
|
+
}
|
18
|
+
|
19
|
+
RestrictName = // unless defined? RestrictName
|
20
|
+
RestrictContext = // unless defined? RestrictContext
|
21
|
+
|
22
|
+
Backtraces = true unless defined? Backtraces
|
23
|
+
|
24
|
+
def self.summary_on_exit
|
25
|
+
return if Counter[:installed_summary] > 0
|
26
|
+
at_exit {
|
27
|
+
handle_summary
|
28
|
+
if $!
|
29
|
+
raise $!
|
30
|
+
elsif Counter[:errors] + Counter[:failed] > 0
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
}
|
34
|
+
Counter[:installed_summary] += 1
|
35
|
+
end
|
36
|
+
class <<self; alias summary_at_exit summary_on_exit; end
|
37
|
+
|
38
|
+
module SpecDoxOutput
|
39
|
+
def handle_specification(name)
|
40
|
+
puts name
|
41
|
+
yield
|
42
|
+
puts
|
43
|
+
end
|
44
|
+
|
45
|
+
def handle_requirement(description)
|
46
|
+
print "- #{description}"
|
47
|
+
error = yield
|
48
|
+
puts error.empty? ? "" : " [#{error}]"
|
49
|
+
end
|
50
|
+
|
51
|
+
def handle_summary
|
52
|
+
print ErrorLog if Backtraces
|
53
|
+
puts "%d specifications (%d requirements), %d failures, %d errors" %
|
54
|
+
Counter.values_at(:specifications, :requirements, :failed, :errors)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
module TestUnitOutput
|
59
|
+
def handle_specification(name) yield end
|
60
|
+
|
61
|
+
def handle_requirement(description)
|
62
|
+
error = yield
|
63
|
+
if error.empty?
|
64
|
+
print "."
|
65
|
+
else
|
66
|
+
print error[0..0]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def handle_summary
|
71
|
+
puts
|
72
|
+
puts ErrorLog if Backtraces
|
73
|
+
puts "%d tests, %d assertions, %d failures, %d errors" %
|
74
|
+
Counter.values_at(:specifications, :requirements, :failed, :errors)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
module TapOutput
|
79
|
+
def handle_specification(name) yield end
|
80
|
+
|
81
|
+
def handle_requirement(description)
|
82
|
+
ErrorLog.replace ""
|
83
|
+
error = yield
|
84
|
+
if error.empty?
|
85
|
+
puts "ok %-3d - %s" % [Counter[:specifications], description]
|
86
|
+
else
|
87
|
+
puts "not ok %d - %s: %s" %
|
88
|
+
[Counter[:specifications], description, error]
|
89
|
+
puts ErrorLog.strip.gsub(/^/, '# ') if Backtraces
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def handle_summary
|
94
|
+
puts "1..#{Counter[:specifications]}"
|
95
|
+
puts "# %d tests, %d assertions, %d failures, %d errors" %
|
96
|
+
Counter.values_at(:specifications, :requirements, :failed, :errors)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
module KnockOutput
|
101
|
+
def handle_specification(name) yield end
|
102
|
+
|
103
|
+
def handle_requirement(description)
|
104
|
+
ErrorLog.replace ""
|
105
|
+
error = yield
|
106
|
+
if error.empty?
|
107
|
+
puts "ok - %s" % [description]
|
108
|
+
else
|
109
|
+
puts "not ok - %s: %s" % [description, error]
|
110
|
+
puts ErrorLog.strip.gsub(/^/, '# ') if Backtraces
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def handle_summary; end
|
115
|
+
end
|
116
|
+
|
117
|
+
extend SpecDoxOutput # default
|
118
|
+
|
119
|
+
class Error < RuntimeError
|
120
|
+
attr_accessor :count_as
|
121
|
+
|
122
|
+
def initialize(count_as, message)
|
123
|
+
@count_as = count_as
|
124
|
+
super message
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
class Context
|
129
|
+
attr_reader :name, :block
|
130
|
+
|
131
|
+
def initialize(name, &block)
|
132
|
+
@name = name
|
133
|
+
@before, @after = [], []
|
134
|
+
@block = block
|
135
|
+
end
|
136
|
+
|
137
|
+
def run
|
138
|
+
return unless name =~ RestrictContext
|
139
|
+
Bacon.handle_specification(name) { instance_eval(&block) }
|
140
|
+
self
|
141
|
+
end
|
142
|
+
|
143
|
+
def before(&block); @before << block; end
|
144
|
+
def after(&block); @after << block; end
|
145
|
+
|
146
|
+
def behaves_like(*names)
|
147
|
+
names.each { |name| instance_eval(&Shared[name]) }
|
148
|
+
end
|
149
|
+
|
150
|
+
def it(description, &block)
|
151
|
+
return unless description =~ RestrictName
|
152
|
+
block ||= lambda { should.flunk "not implemented" }
|
153
|
+
Counter[:specifications] += 1
|
154
|
+
run_requirement description, block
|
155
|
+
end
|
156
|
+
|
157
|
+
def should(*args, &block)
|
158
|
+
if Counter[:depth]==0
|
159
|
+
it('should '+args.first,&block)
|
160
|
+
else
|
161
|
+
super(*args,&block)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def run_requirement(description, spec)
|
166
|
+
Bacon.handle_requirement description do
|
167
|
+
begin
|
168
|
+
Counter[:depth] += 1
|
169
|
+
rescued = false
|
170
|
+
begin
|
171
|
+
@before.each { |block| instance_eval(&block) }
|
172
|
+
prev_req = Counter[:requirements]
|
173
|
+
instance_eval(&spec)
|
174
|
+
rescue Object => e
|
175
|
+
rescued = true
|
176
|
+
raise e
|
177
|
+
ensure
|
178
|
+
if Counter[:requirements] == prev_req and not rescued
|
179
|
+
raise Error.new(:missing,
|
180
|
+
"empty specification: #{@name} #{description}")
|
181
|
+
end
|
182
|
+
begin
|
183
|
+
@after.each { |block| instance_eval(&block) }
|
184
|
+
rescue Object => e
|
185
|
+
raise e unless rescued
|
186
|
+
end
|
187
|
+
end
|
188
|
+
rescue Object => e
|
189
|
+
ErrorLog << "#{e.class}: #{e.message}\n"
|
190
|
+
e.backtrace.find_all { |line| line !~ /bin\/bacon|\/bacon\.rb:\d+/ }.
|
191
|
+
each_with_index { |line, i|
|
192
|
+
ErrorLog << "\t#{line}#{i==0 ? ": #@name - #{description}" : ""}\n"
|
193
|
+
}
|
194
|
+
ErrorLog << "\n"
|
195
|
+
|
196
|
+
if e.kind_of? Error
|
197
|
+
Counter[e.count_as] += 1
|
198
|
+
e.count_as.to_s.upcase
|
199
|
+
else
|
200
|
+
Counter[:errors] += 1
|
201
|
+
"ERROR: #{e.class}"
|
202
|
+
end
|
203
|
+
else
|
204
|
+
""
|
205
|
+
ensure
|
206
|
+
Counter[:depth] -= 1
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
def describe(*args, &block)
|
212
|
+
context = Bacon::Context.new(args.join(' '), &block)
|
213
|
+
@before.each { |b| context.before(&b) }
|
214
|
+
@after.each { |b| context.after(&b) }
|
215
|
+
context.run
|
216
|
+
end
|
217
|
+
|
218
|
+
def raise?(*args, &block); block.raise?(*args); end
|
219
|
+
def throw?(*args, &block); block.throw?(*args); end
|
220
|
+
def change?(*args, &block); block.change?(*args); end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
|
225
|
+
class Object
|
226
|
+
def true?; false; end
|
227
|
+
def false?; false; end
|
228
|
+
end
|
229
|
+
|
230
|
+
class TrueClass
|
231
|
+
def true?; true; end
|
232
|
+
end
|
233
|
+
|
234
|
+
class FalseClass
|
235
|
+
def false?; true; end
|
236
|
+
end
|
237
|
+
|
238
|
+
class Proc
|
239
|
+
def raise?(*exceptions)
|
240
|
+
exceptions = [RuntimeError] if exceptions.empty?
|
241
|
+
call
|
242
|
+
|
243
|
+
# Only to work in 1.9.0, rescue with splat doesn't work there right now
|
244
|
+
rescue Object => e
|
245
|
+
case e
|
246
|
+
when *exceptions
|
247
|
+
e
|
248
|
+
else
|
249
|
+
raise e
|
250
|
+
end
|
251
|
+
else
|
252
|
+
false
|
253
|
+
end
|
254
|
+
|
255
|
+
def throw?(sym)
|
256
|
+
catch(sym) {
|
257
|
+
call
|
258
|
+
return false
|
259
|
+
}
|
260
|
+
return true
|
261
|
+
end
|
262
|
+
|
263
|
+
def change?
|
264
|
+
pre_result = yield
|
265
|
+
called = call
|
266
|
+
post_result = yield
|
267
|
+
pre_result != post_result
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
class Numeric
|
272
|
+
def close?(to, delta)
|
273
|
+
(to.to_f - self).abs <= delta.to_f rescue false
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
|
278
|
+
class Object
|
279
|
+
def should(*args, &block) Should.new(self).be(*args, &block) end
|
280
|
+
end
|
281
|
+
|
282
|
+
module Kernel
|
283
|
+
private
|
284
|
+
def describe(*args, &block) Bacon::Context.new(args.join(' '), &block).run end
|
285
|
+
def shared(name, &block) Bacon::Shared[name] = block end
|
286
|
+
end
|
287
|
+
|
288
|
+
|
289
|
+
class Should
|
290
|
+
# Kills ==, ===, =~, eql?, equal?, frozen?, instance_of?, is_a?,
|
291
|
+
# kind_of?, nil?, respond_to?, tainted?
|
292
|
+
instance_methods.each { |name| undef_method name if name =~ /\?|^\W+$/ }
|
293
|
+
|
294
|
+
def initialize(object)
|
295
|
+
@object = object
|
296
|
+
@negated = false
|
297
|
+
end
|
298
|
+
|
299
|
+
def not(*args, &block)
|
300
|
+
@negated = !@negated
|
301
|
+
|
302
|
+
if args.empty?
|
303
|
+
self
|
304
|
+
else
|
305
|
+
be(*args, &block)
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
def be(*args, &block)
|
310
|
+
if args.empty?
|
311
|
+
self
|
312
|
+
else
|
313
|
+
block = args.shift unless block_given?
|
314
|
+
satisfy(*args, &block)
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
alias a be
|
319
|
+
alias an be
|
320
|
+
|
321
|
+
def satisfy(*args, &block)
|
322
|
+
if args.size == 1 && String === args.first
|
323
|
+
description = args.shift
|
324
|
+
else
|
325
|
+
description = ""
|
326
|
+
end
|
327
|
+
|
328
|
+
r = yield(@object, *args)
|
329
|
+
if Bacon::Counter[:depth] > 0
|
330
|
+
Bacon::Counter[:requirements] += 1
|
331
|
+
raise Bacon::Error.new(:failed, description) unless @negated ^ r
|
332
|
+
end
|
333
|
+
@negated ^ r ? r : false
|
334
|
+
end
|
335
|
+
|
336
|
+
def method_missing(name, *args, &block)
|
337
|
+
name = "#{name}?" if name.to_s =~ /\w[^?]\z/
|
338
|
+
|
339
|
+
desc = @negated ? "not " : ""
|
340
|
+
desc << @object.inspect << "." << name.to_s
|
341
|
+
desc << "(" << args.map{|x|x.inspect}.join(", ") << ") failed"
|
342
|
+
|
343
|
+
satisfy(desc) { |x| x.__send__(name, *args, &block) }
|
344
|
+
end
|
345
|
+
|
346
|
+
def equal(value) self == value end
|
347
|
+
def match(value) self =~ value end
|
348
|
+
def identical_to(value) self.equal? value end
|
349
|
+
alias same_as identical_to
|
350
|
+
|
351
|
+
def flunk(reason="Flunked")
|
352
|
+
raise Bacon::Error.new(:failed, reason)
|
353
|
+
end
|
354
|
+
end
|