eetee 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -11,4 +11,6 @@ group(:test) do
11
11
  gem 'guard'
12
12
  gem 'rb-fsevent'
13
13
  gem 'growl'
14
+
15
+ gem 'eventmachine', '~> 1.0.0'
14
16
  end
data/README.md CHANGED
@@ -77,7 +77,7 @@ The guard is included inside the gem, just look at the Guardfile for the gem for
77
77
  Allow mocha expectations to be considered as E.T. expectations.
78
78
 
79
79
  ## rack
80
- Boilet plate around rack-test to test rack applications.
80
+ abstraction around rack-test to test rack applications.
81
81
 
82
82
  ## time
83
83
  Some time helpers:
@@ -0,0 +1,23 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'eetee'
5
+ require 'eetee/ext/em'
6
+
7
+ describe 'context' do
8
+ before do
9
+ @fib = Fiber.current
10
+ end
11
+
12
+ should 'run in a fiber inside EventMachine' do
13
+ @fib.should == Fiber.current
14
+ EM.reactor_running?.should == true
15
+ end
16
+
17
+ describe 'nested context' do
18
+ should 'run in a fiber inside EventMachine' do
19
+ @fib.should == Fiber.current
20
+ EM.reactor_running?.should == true
21
+ end
22
+ end
23
+ end
@@ -24,8 +24,8 @@ module EEtee
24
24
  end
25
25
 
26
26
  invert_helper(
27
- "expected to raise #{error_class}, got #{err.class}",
28
- "expected not to raise #{error_class}"
27
+ "expected to raise #{error_class}, got #{err.class} (#{err.message})",
28
+ "expected not to raise #{error_class} (#{err.message})"
29
29
  ) do
30
30
  err.class.should == error_class
31
31
  end
@@ -60,7 +60,8 @@ module EEtee
60
60
  end
61
61
 
62
62
  def method_missing(name, *args, &block)
63
- ::EEtee.current_test.reporter.increment_assertions()
63
+ ::EEtee.current_reporter.increment_assertions()
64
+
64
65
  ret = @object.__send__(name, *args, &block)
65
66
 
66
67
  if !!ret == !!@invert
data/lib/eetee/context.rb CHANGED
@@ -2,7 +2,8 @@ module EEtee
2
2
 
3
3
  module SharedContextMethods
4
4
  def before(&block)
5
- instance_eval(&block)
5
+ @before ||= []
6
+ @before << block
6
7
  end
7
8
 
8
9
  def describe(description, &block)
@@ -22,6 +23,7 @@ module EEtee
22
23
 
23
24
  def it(label, opts = {}, &block)
24
25
  if !@_focus_mode || opts[:focus]
26
+ (@before || []).each{|b| instance_eval(&b) }
25
27
  Test.new(label, @_reporter, &block)
26
28
  end
27
29
  end
@@ -51,7 +53,16 @@ module EEtee
51
53
  end
52
54
 
53
55
  def run(&block)
54
- instance_eval(&block)
56
+ run = ->{
57
+ EEtee.current_reporter = @_reporter
58
+ instance_eval(&block)
59
+ }
60
+
61
+ if defined? super
62
+ super(&run)
63
+ else
64
+ run.call()
65
+ end
55
66
  end
56
67
 
57
68
  def run_shared(name, *args)
@@ -0,0 +1,67 @@
1
+
2
+ require 'fiber'
3
+
4
+ gem 'eventmachine'
5
+ require 'eventmachine'
6
+
7
+ module EEtee::EMSpec
8
+ class << self
9
+ attr_accessor :context_fiber
10
+ end
11
+
12
+ def wakeup
13
+ # this should be enough but for some reason the reactor
14
+ # idles for 20 seconds on EM::stop before really exiting
15
+ # @waiting_fiber.resume
16
+
17
+ if @waiting_fiber
18
+ EM::next_tick { @waiting_fiber.resume }
19
+ end
20
+ end
21
+
22
+ def wait(timeout = 0.1, &block)
23
+ @waiting_fiber = Fiber.current
24
+ EM::cancel_timer(@timeout)
25
+ @timeout = EM::add_timer(timeout, &method(:wakeup))
26
+
27
+ Fiber.yield
28
+
29
+ @waiting_fiber = nil
30
+
31
+ block.call if block
32
+ end
33
+
34
+ def done
35
+ EM.cancel_timer(@timeout)
36
+ wakeup
37
+ end
38
+
39
+ def run(&block)
40
+ if EMSpec.context_fiber == Fiber.current
41
+ block.call()
42
+ else
43
+ EM::run do
44
+ EM::error_handler do |err|
45
+ test = EEtee.current_test || EEtee::Test.new("(EM Loop)", @_reporter){}
46
+ @_reporter.add_error( EEtee::Error.new(err, test))
47
+ end
48
+
49
+ EMSpec.context_fiber = Fiber.new do
50
+ begin
51
+ block.call()
52
+ EM::stop_event_loop
53
+ ensure
54
+ EMSpec.context_fiber = nil
55
+ end
56
+ end
57
+
58
+ EMSpec.context_fiber.resume
59
+ end
60
+
61
+ end
62
+ end
63
+
64
+
65
+ end
66
+
67
+ EEtee::Context.__send__(:include, EEtee::EMSpec)
@@ -18,6 +18,16 @@ module EEtee
18
18
  @assertion_count += 1
19
19
  end
20
20
 
21
+ ##
22
+ # Declare an error, only use this
23
+ # when we are "outside" of the current
24
+ # flow like with EventMachine
25
+ #
26
+ # @param [RuntimeError] an error
27
+ def add_error(err)
28
+ @errors << err
29
+ end
30
+
21
31
  def around_context(ctx, &block)
22
32
  @indent += 1
23
33
  block.call()
data/lib/eetee/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module EEtee
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/eetee.rb CHANGED
@@ -30,6 +30,16 @@ module EEtee
30
30
  def enable_focus_mode
31
31
  @enable_focus_mode
32
32
  end
33
+
34
+
35
+
36
+ def current_reporter
37
+ @reporter_instance
38
+ end
39
+
40
+ def current_reporter=(reporter)
41
+ @reporter_instance = reporter
42
+ end
33
43
  end
34
44
 
35
45
 
@@ -22,10 +22,22 @@ describe 'Context' do
22
22
  Thread.new do
23
23
  ctx = EEtee::Context.new("a context", 0, @reporter, :@a => 234){ }
24
24
  ctx.before{ a = @a }
25
+ ctx.should("do nothing"){} # just to run the before block
25
26
  end.join
26
27
  a.should == 234
27
28
  end
28
29
 
30
+ should 'run the before blocks before every test' do
31
+ n = 0
32
+ Thread.new do
33
+ ctx = EEtee::Context.new("a context", 0, @reporter){ }
34
+ ctx.before{ n = 1 }
35
+ ctx.should("test 1"){ n += 2 }
36
+ ctx.should("test 2"){ n += 2 }
37
+ end.join
38
+ n.should == 3
39
+ end
40
+
29
41
  should 'copy instance variables in nested contexts' do
30
42
  a = b = nil
31
43
  Thread.new do
@@ -3,7 +3,9 @@ require File.expand_path('../../spec_helper', __FILE__)
3
3
  describe 'Test' do
4
4
  before do
5
5
  @reporter = stub('Reporter')
6
+ @reporter.stubs(:increment_assertions)
6
7
  @reporter.stubs(:around_test).yields
8
+ EEtee.stubs(:current_reporter).returns(@reporter)
7
9
  end
8
10
 
9
11
  should 'execute given block in context' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eetee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-18 00:00:00.000000000 Z
12
+ date: 2012-12-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: term-ansicolor
@@ -42,6 +42,7 @@ files:
42
42
  - README.md
43
43
  - Rakefile
44
44
  - eetee.gemspec
45
+ - examples/eventmachine/em.rb
45
46
  - examples/extensions/extension.rb
46
47
  - examples/extensions/test.rb
47
48
  - examples/focus/focus.rb
@@ -51,6 +52,7 @@ files:
51
52
  - lib/eetee/assertion_wrapper.rb
52
53
  - lib/eetee/context.rb
53
54
  - lib/eetee/errors.rb
55
+ - lib/eetee/ext/em.rb
54
56
  - lib/eetee/ext/mocha.rb
55
57
  - lib/eetee/ext/rack.rb
56
58
  - lib/eetee/ext/time.rb
@@ -85,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
87
  version: '0'
86
88
  segments:
87
89
  - 0
88
- hash: 496812950380161431
90
+ hash: -1848565578778888050
89
91
  required_rubygems_version: !ruby/object:Gem::Requirement
90
92
  none: false
91
93
  requirements:
@@ -94,10 +96,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
96
  version: '0'
95
97
  segments:
96
98
  - 0
97
- hash: 496812950380161431
99
+ hash: -1848565578778888050
98
100
  requirements: []
99
101
  rubyforge_project:
100
- rubygems_version: 1.8.24
102
+ rubygems_version: 1.8.23
101
103
  signing_key:
102
104
  specification_version: 3
103
105
  summary: Another test framework