undees-bacon 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/COPYING ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2007, 2008 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/README 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 available from http://chneukirchen.org/repos/taptap/)
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
+ == Bacon with autotest
224
+
225
+ Since version 1.0, there is autotest support. You need to tag your
226
+ test directories (test/ or spec/) by creating an .bacon file there.
227
+ Autotest then will find it. bin/bacon needs to be in PATH or RUBYPATH.
228
+
229
+
230
+ == Converting specs
231
+
232
+ spec-converter is a simple tool to convert test-unit or dust style
233
+ tests to test/spec specs.
234
+
235
+ It can be found at http://opensource.thinkrelevance.com/wiki/spec_converter.
236
+
237
+
238
+ == Thanks to
239
+
240
+ * Michael Fellinger, for fixing Bacon for 1.9 and various improvements.
241
+ * Gabriele Renzi, for implementing Context#should.
242
+ * James Tucker, for the autotest support.
243
+ * Yossef Mendelssohn, for nested contexts.
244
+ * everyone contributing bug fixes.
245
+
246
+
247
+ == History
248
+
249
+ * January 7, 2008: First public release 0.9.
250
+
251
+ * July 6th, 2008: Second public release 1.0.
252
+ * Add Context#should as a shortcut for Context#it('should ' + _).
253
+ * describe now supports multiple arguments for better organization.
254
+ * Empty specifications are now erroneous.
255
+ * after-blocks run in the case of exceptions too.
256
+ * Autotest support.
257
+ * Bug fixes.
258
+
259
+ * November 30th, 2008: Third public release 1.1.
260
+ * Nested before/after.
261
+ * Add -Q/--no-backtraces to not show details about failed specifications.
262
+ * Add Knock output.
263
+ * Bug fixes.
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 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,138 @@
1
+ # Rakefile for Bacon. -*-ruby-*-
2
+ require 'rake/rdoctask'
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 'bacon'
28
+ @tree_version = Bacon::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
+ "bacon-#{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["bin/*"].each { |binary| File.chmod(0775, binary) }
49
+ end
50
+
51
+ desc "Generate a ChangeLog"
52
+ task :changelog do
53
+ File.open("ChangeLog", "w") { |out|
54
+ `git log -z`.split("\0").map { |chunk|
55
+ author = chunk[/Author: (.*)/, 1].strip
56
+ date = chunk[/Date: (.*)/, 1].strip
57
+ desc, detail = $'.strip.split("\n", 2)
58
+ detail ||= ""
59
+ detail = detail.gsub(/.*darcs-hash:.*/, '')
60
+ detail.rstrip!
61
+ out.puts "#{date} #{author}"
62
+ out.puts " * #{desc.strip}"
63
+ out.puts detail unless detail.empty?
64
+ out.puts
65
+ }
66
+ }
67
+ end
68
+
69
+
70
+ desc "Generate RDox"
71
+ task "RDOX" do
72
+ sh "bin/bacon -Ilib --automatic --specdox >RDOX"
73
+ end
74
+
75
+ desc "Run all the tests"
76
+ task :test do
77
+ ruby "bin/bacon -Ilib --automatic --quiet"
78
+ end
79
+
80
+
81
+ begin
82
+ $" << "sources" if defined? FromSrc
83
+ require 'rubygems'
84
+
85
+ require 'rake'
86
+ require 'rake/clean'
87
+ require 'rake/packagetask'
88
+ require 'rake/gempackagetask'
89
+ require 'fileutils'
90
+ rescue LoadError
91
+ # Too bad.
92
+ else
93
+ spec = Gem::Specification.new do |s|
94
+ s.name = "bacon"
95
+ s.version = gem_version
96
+ s.platform = Gem::Platform::RUBY
97
+ s.summary = "a small RSpec clone"
98
+
99
+ s.description = <<-EOF
100
+ Bacon is a small RSpec clone weighing less than 350 LoC but
101
+ nevertheless providing all essential features.
102
+
103
+ http://github.com/chneukirchen/bacon
104
+ EOF
105
+
106
+ s.files = manifest + %w(RDOX ChangeLog)
107
+ s.bindir = 'bin'
108
+ s.executables << 'bacon'
109
+ s.require_path = 'lib'
110
+ s.has_rdoc = true
111
+ s.extra_rdoc_files = ['README', 'RDOX']
112
+ s.test_files = []
113
+
114
+ s.author = 'Christian Neukirchen'
115
+ s.email = 'chneukirchen@gmail.com'
116
+ s.homepage = 'http://chneukirchen.org/repos/bacon'
117
+ end
118
+
119
+ Rake::GemPackageTask.new(spec) do |p|
120
+ p.gem_spec = spec
121
+ p.need_tar = false
122
+ p.need_zip = false
123
+ end
124
+ end
125
+
126
+ desc "Generate RDoc documentation"
127
+ Rake::RDocTask.new(:rdoc) do |rdoc|
128
+ rdoc.options << '--line-numbers' << '--inline-source' <<
129
+ '--main' << 'README' <<
130
+ '--title' << 'Bacon Documentation' <<
131
+ '--charset' << 'utf-8'
132
+ rdoc.rdoc_dir = "doc"
133
+ rdoc.rdoc_files.include 'README'
134
+ rdoc.rdoc_files.include 'COPYING'
135
+ rdoc.rdoc_files.include 'RDOX'
136
+ rdoc.rdoc_files.include('lib/bacon.rb')
137
+ end
138
+ task :rdoc => ["RDOX"]
data/bin/bacon ADDED
@@ -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
+