bacon 0.9.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/RDOX CHANGED
@@ -32,4 +32,29 @@ shared/behaves_like
32
32
  - gets called where it is included
33
33
  - can access data
34
34
 
35
- 28 specifications (288 requirements), 0 failures, 0 errors
35
+ describe arguments
36
+ - should work with stringstring
37
+
38
+
39
+ - should work with symbolsbehaviour
40
+
41
+
42
+ - should work with modulesBacon
43
+
44
+
45
+ - should work with namespaced modulesBacon::Context
46
+
47
+
48
+ - should work with multiple argumentsBacon::Context empty
49
+
50
+
51
+
52
+ #should shortcut for #it('should')
53
+ - should be called
54
+ - should save some characters by typing should
55
+ - should save characters even on failure
56
+ - should work nested
57
+ - should add new specifications
58
+ - should have been called
59
+
60
+ 39 specifications (359 requirements), 0 failures, 0 errors
data/README CHANGED
@@ -3,7 +3,7 @@
3
3
  "Truth will sooner come out from error than from confusion."
4
4
  ---Francis Bacon
5
5
 
6
- Bacon is a small RSpec clone weighing less than 300 LoC but
6
+ Bacon is a small RSpec clone weighing less than 350 LoC but
7
7
  nevertheless providing all essential features.
8
8
 
9
9
  == Whirl-wind tour
@@ -196,9 +196,40 @@ demonstrations, quick checks and doctest tests.
196
196
  => false
197
197
 
198
198
 
199
+ == Bacon with autotest
200
+
201
+ Since version 1.0, there is autotest support. You need to tag your
202
+ test directories (test/ or spec/) by creating an .bacon file there.
203
+ Autotest then will find it. bin/bacon needs to be in PATH or RUBYPATH.
204
+
205
+
206
+ == Converting specs
207
+
208
+ spec-converter is a simple tool to convert test-unit or dust style
209
+ tests to test/spec specs.
210
+
211
+ It can be found at http://opensource.thinkrelevance.com/wiki/spec_converter.
212
+
213
+
199
214
  == Thanks to
200
215
 
201
216
  * Michael Fellinger, for fixing Bacon for 1.9 and various improvements.
217
+ * Gabriele Renzi, for implementing Context#should.
218
+ * James Tucker, for the autotest support
219
+ * everyone contributing bug fixes.
220
+
221
+
222
+ == History
223
+
224
+ * January 7, 2008: First public release 0.9.
225
+
226
+ * July 6th, 2008: Second public release 1.0.
227
+ * Add Context#should as a shortcut for Context#it('should ' + _).
228
+ * describe now supports multiple arguments for better organization.
229
+ * Empty specifications are now erroneous.
230
+ * after-blocks run in the case of exceptions too.
231
+ * Autotest support.
232
+ * Bug fixes.
202
233
 
203
234
 
204
235
  == Contact
data/Rakefile CHANGED
@@ -92,7 +92,7 @@ else
92
92
  s.summary = "a small RSpec clone"
93
93
 
94
94
  s.description = <<-EOF
95
- Bacon is a small RSpec clone weighing less than 300 LoC but
95
+ Bacon is a small RSpec clone weighing less than 350 LoC but
96
96
  nevertheless providing all essential features.
97
97
 
98
98
  http://chneukirchen.org/repos/bacon
data/bin/bacon CHANGED
@@ -2,6 +2,7 @@
2
2
  # -*- ruby -*-
3
3
 
4
4
  require 'optparse'
5
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '../lib/')
5
6
  module Bacon; end
6
7
 
7
8
  automatic = false
@@ -89,9 +90,9 @@ opts = OptionParser.new("", 24, ' ') { |opts|
89
90
  files = ARGV
90
91
 
91
92
  if automatic
92
- files.concat Dir["test/test_*.rb"]
93
- files.concat Dir["test/spec_*.rb"]
94
- files.concat Dir["spec/spec_*.rb"]
93
+ files.concat Dir["test/**/test_*.rb"]
94
+ files.concat Dir["test/**/spec_*.rb"]
95
+ files.concat Dir["spec/**/spec_*.rb"]
95
96
  end
96
97
 
97
98
  if files.empty?
@@ -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,9 @@
1
+ Autotest.add_discovery do
2
+ if File.exist?('spec/.bacon') || File.exist?('test/.bacon')
3
+ class Autotest
4
+ @@discoveries.delete_if { |d| d.inspect =~ /rspec/ }
5
+ warn 'Removing rspec from autotest!'
6
+ end
7
+ 'bacon'
8
+ end
9
+ end
@@ -8,7 +8,7 @@
8
8
  # See COPYING or http://www.opensource.org/licenses/mit-license.php.
9
9
 
10
10
  module Bacon
11
- VERSION = "0.9"
11
+ VERSION = "1.0"
12
12
 
13
13
  Counter = Hash.new(0)
14
14
  ErrorLog = ""
@@ -122,17 +122,42 @@ module Bacon
122
122
 
123
123
  def it(description, &block)
124
124
  return unless description =~ RestrictName
125
+ block ||= lambda { should.flunk "not implemented" }
125
126
  Counter[:specifications] += 1
126
127
  run_requirement description, block
127
128
  end
129
+
130
+ def should(*args, &block)
131
+ if Counter[:depth]==0
132
+ it('should '+args.first,&block)
133
+ else
134
+ super(*args,&block)
135
+ end
136
+ end
128
137
 
129
138
  def run_requirement(description, spec)
130
139
  Bacon.handle_requirement description do
131
140
  begin
132
141
  Counter[:depth] += 1
133
- @before.each { |block| instance_eval(&block) }
134
- instance_eval(&spec)
135
- @after.each { |block| instance_eval(&block) }
142
+ rescued = false
143
+ begin
144
+ @before.each { |block| instance_eval(&block) }
145
+ prev_req = Counter[:requirements]
146
+ instance_eval(&spec)
147
+ rescue Object => e
148
+ rescued = true
149
+ raise e
150
+ ensure
151
+ if Counter[:requirements] == prev_req and not rescued
152
+ raise Error.new(:missing,
153
+ "empty specification: #{@name} #{description}")
154
+ end
155
+ begin
156
+ @after.each { |block| instance_eval(&block) }
157
+ rescue Object => e
158
+ raise e unless rescued
159
+ end
160
+ end
136
161
  rescue Object => e
137
162
  ErrorLog << "#{e.class}: #{e.message}\n"
138
163
  e.backtrace.find_all { |line| line !~ /bin\/bacon|\/bacon\.rb:\d+/ }.
@@ -178,7 +203,7 @@ end
178
203
 
179
204
  class Proc
180
205
  def raise?(*exceptions)
181
- exceptions << RuntimeError if exceptions.empty?
206
+ exceptions = [RuntimeError] if exceptions.empty?
182
207
  call
183
208
 
184
209
  # Only to work in 1.9.0, rescue with splat doesn't work there right now
@@ -217,23 +242,20 @@ end
217
242
 
218
243
 
219
244
  class Object
220
- def should(*args, &block) Should.new(self).be(*args, &block) end
245
+ def should(*args, &block) Should.new(self).be(*args, &block) end
221
246
  end
222
247
 
223
248
  module Kernel
224
249
  private
225
-
226
- def describe(name, &block) Bacon::Context.new(name, &block) end
227
- def shared(name, &block) Bacon::Shared[name] = block end
250
+ def describe(*args, &block) Bacon::Context.new(args.join(' '), &block) end
251
+ def shared(name, &block) Bacon::Shared[name] = block end
228
252
  end
229
253
 
230
254
 
231
255
  class Should
232
256
  # Kills ==, ===, =~, eql?, equal?, frozen?, instance_of?, is_a?,
233
257
  # kind_of?, nil?, respond_to?, tainted?
234
- instance_methods.each { |method|
235
- undef_method method if method =~ /\?|^\W+$/
236
- }
258
+ instance_methods.each { |name| undef_method name if name =~ /\?|^\W+$/ }
237
259
 
238
260
  def initialize(object)
239
261
  @object = object
@@ -271,8 +293,8 @@ class Should
271
293
 
272
294
  r = yield(@object, *args)
273
295
  if Bacon::Counter[:depth] > 0
274
- raise Bacon::Error.new(:failed, description) unless @negated ^ r
275
296
  Bacon::Counter[:requirements] += 1
297
+ raise Bacon::Error.new(:failed, description) unless @negated ^ r
276
298
  end
277
299
  @negated ^ r ? r : false
278
300
  end
@@ -1,5 +1,6 @@
1
- $: << File.dirname(__FILE__) + '/../lib/'
2
- require 'bacon'
1
+ $-w,w = nil, $-w
2
+ require File.join(File.dirname(__FILE__), '../lib/bacon')
3
+ $-w = w
3
4
 
4
5
  # Hooray for meta-testing.
5
6
  module MetaTests
@@ -308,3 +309,32 @@ describe "shared/behaves_like" do
308
309
  }
309
310
  behaves_like "another shared context"
310
311
  end
312
+
313
+ describe 'describe arguments' do
314
+
315
+ def check(ctx,name)
316
+ ctx.should.be.an.instance_of Bacon::Context
317
+ ctx.instance_variable_get('@name').should == name
318
+ end
319
+
320
+ it 'should work with string' do
321
+ check(describe('string') {},'string')
322
+ end
323
+
324
+ it 'should work with symbols' do
325
+ check(describe(:behaviour) {},'behaviour')
326
+ end
327
+
328
+ it 'should work with modules' do
329
+ check(describe(Bacon) {},'Bacon')
330
+ end
331
+
332
+ it 'should work with namespaced modules' do
333
+ check(describe(Bacon::Context) {},'Bacon::Context')
334
+ end
335
+
336
+ it 'should work with multiple arguments' do
337
+ check(describe(Bacon::Context, :empty) {},'Bacon::Context empty')
338
+ end
339
+
340
+ end
@@ -0,0 +1,32 @@
1
+ require File.join(File.dirname(__FILE__), '../lib/bacon')
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 Bacon::Error
16
+ end
17
+
18
+ should "work nested" do
19
+ should.satisfy {1==1}
20
+ end
21
+
22
+ count = Bacon::Counter[:specifications]
23
+ should "add new specifications" do
24
+ # XXX this should +=1 but it's +=2
25
+ (count+1).should == Bacon::Counter[:specifications]
26
+ end
27
+
28
+ should "have been called" do
29
+ @called.should.be == true
30
+ end
31
+
32
+ end
metadata CHANGED
@@ -1,53 +1,63 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: bacon
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.9.0
7
- date: 2008-01-07 00:00:00 +01:00
8
- summary: a small RSpec clone
9
- require_paths:
10
- - lib
11
- email: chneukirchen@gmail.com
12
- homepage: http://chneukirchen.org/repos/bacon
13
- rubyforge_project:
14
- description: Bacon is a small RSpec clone weighing less than 300 LoC but nevertheless providing all essential features. http://chneukirchen.org/repos/bacon
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 1.0.0
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Christian Neukirchen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-07-06 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Bacon is a small RSpec clone weighing less than 350 LoC but nevertheless providing all essential features. http://chneukirchen.org/repos/bacon
17
+ email: chneukirchen@gmail.com
18
+ executables:
19
+ - bacon
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ - RDOX
31
25
  files:
32
26
  - bin/bacon
33
27
  - COPYING
28
+ - lib/autotest/bacon.rb
29
+ - lib/autotest/discover.rb
34
30
  - lib/bacon.rb
35
31
  - Rakefile
36
32
  - README
37
33
  - test/spec_bacon.rb
34
+ - test/spec_should.rb
38
35
  - RDOX
39
- test_files: []
40
-
36
+ has_rdoc: true
37
+ homepage: http://chneukirchen.org/repos/bacon
38
+ post_install_message:
41
39
  rdoc_options: []
42
40
 
43
- extra_rdoc_files:
44
- - README
45
- - RDOX
46
- executables:
47
- - bacon
48
- extensions: []
49
-
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
50
55
  requirements: []
51
56
 
52
- dependencies: []
57
+ rubyforge_project:
58
+ rubygems_version: 1.0.1
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: a small RSpec clone
62
+ test_files: []
53
63