schmurfy-bacon 1.2.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -101
- data/examples/em_spec.rb +51 -0
- data/examples/mocha_spec.rb +24 -0
- data/lib/bacon/ext/em.rb +68 -0
- data/lib/bacon/ext/mocha.rb +35 -0
- data/lib/bacon/version.rb +1 -1
- data/lib/bacon.rb +16 -8
- metadata +10 -6
data/Rakefile
CHANGED
@@ -1,71 +1,10 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
require "bundler/gem_tasks"
|
3
3
|
|
4
4
|
|
5
5
|
desc "Run all the tests"
|
6
6
|
task :default => [:test]
|
7
7
|
|
8
|
-
desc "Do predistribution stuff"
|
9
|
-
task :predist => [:chmod, :changelog, :rdoc]
|
10
|
-
|
11
|
-
|
12
|
-
desc "Make an archive as .tar.gz"
|
13
|
-
task :dist => [:test, :predist] do
|
14
|
-
sh "git archive --format=tar --prefix=#{release}/ HEAD^{tree} >#{release}.tar"
|
15
|
-
sh "pax -waf #{release}.tar -s ':^:#{release}/:' RDOX ChangeLog doc"
|
16
|
-
sh "gzip -f -9 #{release}.tar"
|
17
|
-
end
|
18
|
-
|
19
|
-
# Helper to retrieve the "revision number" of the git tree.
|
20
|
-
def git_tree_version
|
21
|
-
if File.directory?(".git")
|
22
|
-
@tree_version ||= `git describe`.strip.sub('-', '.')
|
23
|
-
@tree_version << ".0" unless @tree_version.count('.') == 2
|
24
|
-
else
|
25
|
-
$: << "lib"
|
26
|
-
require 'bacon'
|
27
|
-
@tree_version = Bacon::VERSION
|
28
|
-
end
|
29
|
-
@tree_version
|
30
|
-
end
|
31
|
-
|
32
|
-
def gem_version
|
33
|
-
git_tree_version.gsub(/-.*/, '')
|
34
|
-
end
|
35
|
-
|
36
|
-
def release
|
37
|
-
"bacon-#{git_tree_version}"
|
38
|
-
end
|
39
|
-
|
40
|
-
def manifest
|
41
|
-
`git ls-files`.split("\n") - [".gitignore"]
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
desc "Make binaries executable"
|
46
|
-
task :chmod do
|
47
|
-
Dir["bin/*"].each { |binary| File.chmod(0775, binary) }
|
48
|
-
end
|
49
|
-
|
50
|
-
desc "Generate a ChangeLog"
|
51
|
-
task :changelog do
|
52
|
-
File.open("ChangeLog", "w") { |out|
|
53
|
-
`git log -z`.split("\0").map { |chunk|
|
54
|
-
author = chunk[/Author: (.*)/, 1].strip
|
55
|
-
date = chunk[/Date: (.*)/, 1].strip
|
56
|
-
desc, detail = $'.strip.split("\n", 2)
|
57
|
-
detail ||= ""
|
58
|
-
detail = detail.gsub(/.*darcs-hash:.*/, '')
|
59
|
-
detail.rstrip!
|
60
|
-
out.puts "#{date} #{author}"
|
61
|
-
out.puts " * #{desc.strip}"
|
62
|
-
out.puts detail unless detail.empty?
|
63
|
-
out.puts
|
64
|
-
}
|
65
|
-
}
|
66
|
-
end
|
67
|
-
|
68
|
-
|
69
8
|
desc "Generate RDox"
|
70
9
|
task "RDOX" do
|
71
10
|
sh "bin/bacon -Ilib --automatic --specdox >RDOX"
|
@@ -77,43 +16,4 @@ task :test do
|
|
77
16
|
end
|
78
17
|
|
79
18
|
|
80
|
-
begin
|
81
|
-
$" << "sources" if defined? FromSrc
|
82
|
-
require 'rubygems'
|
83
|
-
|
84
|
-
require 'rake'
|
85
|
-
require 'rake/clean'
|
86
|
-
require 'rake/packagetask'
|
87
|
-
require 'fileutils'
|
88
|
-
rescue LoadError
|
89
|
-
# Too bad.
|
90
|
-
else
|
91
|
-
spec = Gem::Specification.new do |s|
|
92
|
-
s.name = "bacon"
|
93
|
-
s.version = gem_version
|
94
|
-
s.platform = Gem::Platform::RUBY
|
95
|
-
s.summary = "a small RSpec clone"
|
96
|
-
|
97
|
-
s.description = <<-EOF
|
98
|
-
Bacon is a small RSpec clone weighing less than 350 LoC but
|
99
|
-
nevertheless providing all essential features.
|
100
|
-
|
101
|
-
http://github.com/chneukirchen/bacon
|
102
|
-
EOF
|
103
|
-
|
104
|
-
s.files = manifest + %w(RDOX ChangeLog)
|
105
|
-
s.bindir = 'bin'
|
106
|
-
s.executables << 'bacon'
|
107
|
-
s.require_path = 'lib'
|
108
|
-
s.extra_rdoc_files = ['README', 'RDOX']
|
109
|
-
s.test_files = []
|
110
|
-
|
111
|
-
s.author = 'Christian Neukirchen'
|
112
|
-
s.email = 'chneukirchen@gmail.com'
|
113
|
-
s.homepage = 'http://github.com/chneukirchen/bacon'
|
114
|
-
end
|
115
|
-
|
116
|
-
task :gem => [:chmod, :changelog]
|
117
|
-
end
|
118
|
-
|
119
19
|
|
data/examples/em_spec.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift << File.expand_path('../../lib/', __FILE__)
|
4
|
+
|
5
|
+
require 'bacon/ext/em'
|
6
|
+
require 'bacon'
|
7
|
+
|
8
|
+
Bacon.summary_on_exit
|
9
|
+
|
10
|
+
def run_something_later(&block)
|
11
|
+
EM::add_timer(0.1) do
|
12
|
+
block.call("something")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'AsynchronousSpec' do
|
17
|
+
# tell bacon we want to run inside
|
18
|
+
# the EventMachine reactor
|
19
|
+
with_eventmachine!
|
20
|
+
|
21
|
+
before do
|
22
|
+
# Eventmachine is running, yeah !
|
23
|
+
EM::reactor_running?.should == true
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'ends immediately' do
|
27
|
+
EM::reactor_running?.should == true
|
28
|
+
1.should == 1
|
29
|
+
# without action EM::stop is called after our code
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'requires time (simple)' do
|
33
|
+
# suppose this method do something
|
34
|
+
# 0.1s after the call
|
35
|
+
run_something_later do |s|
|
36
|
+
s.should == "something"
|
37
|
+
end
|
38
|
+
|
39
|
+
wait(0.2)
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
it 'requires time (less simple)' do
|
44
|
+
v = 1
|
45
|
+
EM::add_timer(0.2){ v = 2 }
|
46
|
+
|
47
|
+
# wait 0.2s and then execute the passed block
|
48
|
+
wait(0.2){ v.should == 2 }
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift << File.expand_path('../../lib/', __FILE__)
|
4
|
+
|
5
|
+
require 'bacon'
|
6
|
+
require 'bacon/ext/mocha'
|
7
|
+
|
8
|
+
Bacon.summary_on_exit
|
9
|
+
|
10
|
+
def call_it(target)
|
11
|
+
target.do_something()
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'MochaSpec' do
|
15
|
+
before do
|
16
|
+
@m = mock()
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should call method on mock' do
|
20
|
+
@m.expects(:do_something)
|
21
|
+
call_it(@m)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/lib/bacon/ext/em.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
|
2
|
+
require 'eventmachine'
|
3
|
+
|
4
|
+
#
|
5
|
+
# This module allows you to run your specs inside an eventmachine loop
|
6
|
+
# check examples/em_spec.rb for usage.
|
7
|
+
#
|
8
|
+
# Be aware that it does not work like the em-spec gem, no timeout error will
|
9
|
+
# ever be raised.
|
10
|
+
#
|
11
|
+
module Bacon
|
12
|
+
class Context
|
13
|
+
def with_eventmachine!
|
14
|
+
(class << self; self; end).send(:include, EMSpec)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module EMSpec # :nodoc:
|
19
|
+
|
20
|
+
def wait(timeout = 0.1, &block)
|
21
|
+
@timeout_interval = timeout
|
22
|
+
@end_check = block
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
def done
|
27
|
+
@end_check.call if @end_check
|
28
|
+
EM.cancel_timer(@timeout)
|
29
|
+
EM.stop
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_timeout_timer(delay = 0.1)
|
33
|
+
EM::add_timer(delay){ done }
|
34
|
+
end
|
35
|
+
|
36
|
+
def describe(*, &block)
|
37
|
+
super do
|
38
|
+
with_eventmachine!
|
39
|
+
block.call
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def execute_spec(&block)
|
44
|
+
raise "block required" unless block
|
45
|
+
|
46
|
+
super do
|
47
|
+
@timeout_interval = nil
|
48
|
+
|
49
|
+
EM.run do
|
50
|
+
@timeout = create_timeout_timer()
|
51
|
+
|
52
|
+
instance_eval(&block)
|
53
|
+
|
54
|
+
if @timeout_interval
|
55
|
+
EM::cancel_timer(@timeout)
|
56
|
+
@timeout = create_timeout_timer(@timeout_interval)
|
57
|
+
else
|
58
|
+
done
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
require 'mocha'
|
3
|
+
|
4
|
+
#
|
5
|
+
# This extension ensure that mocha expectations are considered
|
6
|
+
# as bacon tests. Amongst other thing it allows to have a test
|
7
|
+
# containing only mocha expectations.
|
8
|
+
#
|
9
|
+
module Bacon
|
10
|
+
module MochaRequirementsCounter
|
11
|
+
def self.increment
|
12
|
+
Counter[:requirements] += 1
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Context
|
17
|
+
include Mocha::API
|
18
|
+
|
19
|
+
alias_method :it_before_mocha, :it
|
20
|
+
|
21
|
+
def it(description, &block)
|
22
|
+
it_before_mocha(description) do
|
23
|
+
begin
|
24
|
+
mocha_setup
|
25
|
+
block.call
|
26
|
+
mocha_verify(MochaRequirementsCounter)
|
27
|
+
rescue Mocha::ExpectationError => e
|
28
|
+
raise Error.new(:failed, "#{e.message}\n#{e.backtrace[0...10].join("\n")}")
|
29
|
+
ensure
|
30
|
+
mocha_teardown
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/bacon/version.rb
CHANGED
data/lib/bacon.rb
CHANGED
@@ -73,11 +73,8 @@ module Bacon
|
|
73
73
|
end
|
74
74
|
|
75
75
|
module ContextAssertions
|
76
|
-
def
|
77
|
-
|
78
|
-
block ||= lambda { should.flunk "not implemented" }
|
79
|
-
Counter[:specifications] += 1
|
80
|
-
run_requirement description, block
|
76
|
+
def execute_spec(&block)
|
77
|
+
block.call
|
81
78
|
end
|
82
79
|
|
83
80
|
def describe(*args, &block)
|
@@ -124,6 +121,13 @@ module Bacon
|
|
124
121
|
super(*args,&block)
|
125
122
|
end
|
126
123
|
end
|
124
|
+
|
125
|
+
def it(description, &block)
|
126
|
+
return unless description =~ RestrictName
|
127
|
+
block ||= lambda { should.flunk "not implemented" }
|
128
|
+
Counter[:specifications] += 1
|
129
|
+
run_requirement description, block
|
130
|
+
end
|
127
131
|
|
128
132
|
def run_requirement(description, spec)
|
129
133
|
Bacon.handle_requirement description do
|
@@ -131,9 +135,13 @@ module Bacon
|
|
131
135
|
Counter[:depth] += 1
|
132
136
|
rescued = false
|
133
137
|
begin
|
134
|
-
|
135
|
-
|
136
|
-
|
138
|
+
prev_req = nil
|
139
|
+
|
140
|
+
execute_spec do
|
141
|
+
@before.each { |block| instance_eval(&block) }
|
142
|
+
prev_req = Counter[:requirements]
|
143
|
+
instance_eval(&spec)
|
144
|
+
end
|
137
145
|
rescue Object => e
|
138
146
|
rescued = true
|
139
147
|
raise e
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schmurfy-bacon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-04-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: term-ansicolor
|
16
|
-
requirement: &
|
16
|
+
requirement: &70141825879320 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70141825879320
|
25
25
|
description: ! 'Bacon is a small RSpec clone weighing less than 350 LoC but
|
26
26
|
|
27
27
|
nevertheless providing all essential features.
|
@@ -44,10 +44,14 @@ files:
|
|
44
44
|
- Rakefile
|
45
45
|
- bacon.gemspec
|
46
46
|
- bin/bacon
|
47
|
+
- examples/em_spec.rb
|
48
|
+
- examples/mocha_spec.rb
|
47
49
|
- lib/autotest/bacon.rb
|
48
50
|
- lib/autotest/bacon_rspec.rb
|
49
51
|
- lib/autotest/discover.rb
|
50
52
|
- lib/bacon.rb
|
53
|
+
- lib/bacon/ext/em.rb
|
54
|
+
- lib/bacon/ext/mocha.rb
|
51
55
|
- lib/bacon/version.rb
|
52
56
|
- lib/output/better_output.rb
|
53
57
|
- lib/output/knock_output.rb
|
@@ -71,7 +75,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
75
|
version: '0'
|
72
76
|
segments:
|
73
77
|
- 0
|
74
|
-
hash:
|
78
|
+
hash: 3626099875100681830
|
75
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
80
|
none: false
|
77
81
|
requirements:
|
@@ -80,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
84
|
version: '0'
|
81
85
|
segments:
|
82
86
|
- 0
|
83
|
-
hash:
|
87
|
+
hash: 3626099875100681830
|
84
88
|
requirements: []
|
85
89
|
rubyforge_project:
|
86
90
|
rubygems_version: 1.8.11
|