schmurfy-bacon 1.3.1 → 1.3.2

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.
@@ -8,7 +8,7 @@ require 'bacon/ext/mocha'
8
8
  Bacon.summary_on_exit
9
9
 
10
10
  def call_it(target)
11
- target.do_something()
11
+ target.do_something(42)
12
12
  end
13
13
 
14
14
  describe 'MochaSpec' do
@@ -17,7 +17,7 @@ describe 'MochaSpec' do
17
17
  end
18
18
 
19
19
  it 'should call method on mock' do
20
- @m.expects(:do_something)
20
+ @m.expects(:do_something).with(anything())
21
21
  call_it(@m)
22
22
  end
23
23
 
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+
3
+ $LOAD_PATH.unshift << File.expand_path('../../lib/', __FILE__)
4
+
5
+ require 'bacon'
6
+ require 'bacon/ext/em'
7
+
8
+ Bacon.summary_on_exit
9
+
10
+
11
+ describe 'Main context' do
12
+ with_eventmachine!
13
+
14
+ before do
15
+ # EM::reactor_running?.should == true
16
+ @var = 1
17
+ end
18
+
19
+ should 'pass' do
20
+ 2.should == 2
21
+ end
22
+
23
+ describe 'sub context 1' do
24
+ before do
25
+ @var += 2
26
+ end
27
+
28
+ should 'pass' do
29
+ 2.should == 2
30
+ @var.should == 3
31
+ end
32
+ end
33
+ end
data/lib/bacon.rb CHANGED
@@ -86,6 +86,60 @@ module Bacon
86
86
  block.call
87
87
  end
88
88
 
89
+ def run_requirement(description, spec)
90
+ Bacon.handle_requirement description do
91
+ begin
92
+ Counter[:depth] += 1
93
+ rescued = false
94
+ begin
95
+ prev_req = nil
96
+
97
+ execute_spec do
98
+ @before.each { |block| instance_eval(&block) }
99
+ prev_req = Counter[:requirements]
100
+ instance_eval(&spec)
101
+ end
102
+ rescue Object => e
103
+ rescued = true
104
+ raise e
105
+ ensure
106
+ if Counter[:requirements] == prev_req and not rescued
107
+ raise Error.new(:missing, "empty specification: #{@name} #{description}")
108
+ end
109
+ begin
110
+ @after.each { |block| instance_eval(&block) }
111
+ rescue Object => e
112
+ raise e unless rescued
113
+ end
114
+ end
115
+ rescue Object => e
116
+ ErrorLog << "#{e.class}: #{e.message}\n"
117
+
118
+ backtrace = e.backtrace.find_all { |line| line !~ /bin\/bacon|\/bacon\.rb:\d+/ && line !~ /guard|fsevent|thor/ }
119
+ backtrace = backtrace[0, Bacon.backtrace_size] if Bacon.backtrace_size
120
+
121
+ backtrace.each_with_index do |line, i|
122
+ ErrorLog << " #{line}#{i==0 ? ": #@name - #{description}" : ""}\n"
123
+ end
124
+
125
+ ErrorLog << "\n"
126
+
127
+ if e.kind_of? Error
128
+ Counter[e.count_as] += 1
129
+ e.count_as.to_s.upcase
130
+ [:failed]
131
+ else
132
+ Counter[:errors] += 1
133
+ [:error, e]
134
+ end
135
+ else
136
+ ""
137
+ ensure
138
+ Counter[:depth] -= 1
139
+ end
140
+ end
141
+ end
142
+
89
143
  def describe(*args, &block)
90
144
  context = Bacon::Context.new(args.join(' '), &block)
91
145
  (parent_context = self).methods(false).each {|e|
@@ -149,61 +203,6 @@ module Bacon
149
203
  run_requirement description, block
150
204
  end
151
205
 
152
- def run_requirement(description, spec)
153
- Bacon.handle_requirement description do
154
- begin
155
- Counter[:depth] += 1
156
- rescued = false
157
- begin
158
- prev_req = nil
159
-
160
- execute_spec do
161
- @before.each { |block| instance_eval(&block) }
162
- prev_req = Counter[:requirements]
163
- instance_eval(&spec)
164
- end
165
- rescue Object => e
166
- rescued = true
167
- raise e
168
- ensure
169
- if Counter[:requirements] == prev_req and not rescued
170
- raise Error.new(:missing,
171
- "empty specification: #{@name} #{description}")
172
- end
173
- begin
174
- @after.each { |block| instance_eval(&block) }
175
- rescue Object => e
176
- raise e unless rescued
177
- end
178
- end
179
- rescue Object => e
180
- ErrorLog << "#{e.class}: #{e.message}\n"
181
-
182
- backtrace = e.backtrace.find_all { |line| line !~ /bin\/bacon|\/bacon\.rb:\d+/ && line !~ /guard|fsevent|thor/ }
183
- backtrace = backtrace[0, Bacon.backtrace_size] if Bacon.backtrace_size
184
-
185
- backtrace.each_with_index do |line, i|
186
- ErrorLog << " #{line}#{i==0 ? ": #@name - #{description}" : ""}\n"
187
- end
188
-
189
- ErrorLog << "\n"
190
-
191
- if e.kind_of? Error
192
- Counter[e.count_as] += 1
193
- e.count_as.to_s.upcase
194
- [:failed]
195
- else
196
- Counter[:errors] += 1
197
- [:error, e]
198
- end
199
- else
200
- ""
201
- ensure
202
- Counter[:depth] -= 1
203
- end
204
- end
205
- end
206
-
207
206
  def raise?(*args, &block); block.raise?(*args); end
208
207
  def throw?(*args, &block); block.throw?(*args); end
209
208
  def change?(*args, &block); block.change?(*args); end
data/lib/bacon/ext/em.rb CHANGED
@@ -1,4 +1,5 @@
1
1
 
2
+ require 'fiber'
2
3
  require 'eventmachine'
3
4
 
4
5
  #
@@ -18,21 +19,19 @@ module Bacon
18
19
  module EMSpec # :nodoc:
19
20
 
20
21
  def wait(timeout = 0.1, &block)
21
- @timeout_interval = timeout
22
- @end_check = block
22
+ waiting_fiber = Fiber.current
23
+ EM::cancel_timer(@timeout)
24
+ @timeout = EM::add_timer(timeout){ waiting_fiber.resume }
25
+ Fiber.yield
26
+
27
+ block.call if block
23
28
  end
24
29
 
25
-
26
30
  def done
27
- @end_check.call if @end_check
28
31
  EM.cancel_timer(@timeout)
29
32
  EM.stop
30
33
  end
31
34
 
32
- def create_timeout_timer(delay = 0.1)
33
- EM::add_timer(delay){ done }
34
- end
35
-
36
35
  def describe(*, &block)
37
36
  super do
38
37
  with_eventmachine!
@@ -40,25 +39,16 @@ module Bacon
40
39
  end
41
40
  end
42
41
 
43
- def execute_spec(&block)
42
+ def run_requirement(desc, spec)
44
43
  raise "block required" unless block
45
44
 
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
45
+ @timeout_interval = nil
60
46
 
61
- end
47
+ EM.run do
48
+ Fiber.new do
49
+ super
50
+ done
51
+ end.resume
62
52
  end
63
53
  end
64
54
 
data/lib/bacon/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bacon
2
- VERSION = "1.3.1"
2
+ VERSION = "1.3.2"
3
3
  end
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.3.1
4
+ version: 1.3.2
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-04-02 00:00:00.000000000 Z
12
+ date: 2012-04-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: term-ansicolor
16
- requirement: &70177919026240 !ruby/object:Gem::Requirement
16
+ requirement: &70215709703120 !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: *70177919026240
24
+ version_requirements: *70215709703120
25
25
  description: ! 'Bacon is a small RSpec clone weighing less than 350 LoC but
26
26
 
27
27
  nevertheless providing all essential features.
@@ -47,6 +47,7 @@ files:
47
47
  - examples/em_spec.rb
48
48
  - examples/focus_spec.rb
49
49
  - examples/mocha_spec.rb
50
+ - examples/nested_contexts_spec.rb
50
51
  - lib/autotest/bacon.rb
51
52
  - lib/autotest/bacon_rspec.rb
52
53
  - lib/autotest/discover.rb
@@ -76,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
77
  version: '0'
77
78
  segments:
78
79
  - 0
79
- hash: -3207212041725113050
80
+ hash: 414404718689880390
80
81
  required_rubygems_version: !ruby/object:Gem::Requirement
81
82
  none: false
82
83
  requirements:
@@ -85,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
86
  version: '0'
86
87
  segments:
87
88
  - 0
88
- hash: -3207212041725113050
89
+ hash: 414404718689880390
89
90
  requirements: []
90
91
  rubyforge_project:
91
92
  rubygems_version: 1.8.11