em-spec 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  Simple BDD API for testing asynchronous Ruby/EventMachine code
2
2
  (c) 2008 Aman Gupta (tmm1)
3
3
 
4
- em-spec can be used with either bacon or rspec.
4
+ em-spec can be used with either bacon, test unit or rspec.
5
5
 
6
6
  =Rspec
7
7
  There are two ways to use the Rspec extension. To use it as a helper, include EM::SpecHelper in your describe block. You then use the em method to wrap your evented test code. Inside the em block, you must call #done after your expectations. Everything works normally otherwise.
@@ -76,6 +76,36 @@ The API is identical to Bacon, except that you must explicitly call 'done' after
76
76
 
77
77
  end
78
78
 
79
+ =Test::Unit
80
+ There are two ways to use the Test::Unit extension. To use it as a helper, include EM::TestHelper in your test unit class. You then use the em method to wrap your evented test code. Inside the em block, you must call #done after your expectations. Everything works normally otherwise.
81
+
82
+ class EmSpecHelperTest < Test::Unit::TestCase
83
+
84
+ include EventMachine::TestHelper
85
+
86
+ def test_trivial
87
+ em do
88
+ assert_equal 1, 1
89
+ done
90
+ end
91
+ end
92
+ end
93
+
94
+ The other option is to include EM::Test in your test class. This will patch Test::Unit so that all of your examples run inside an em block automatically:
95
+
96
+ class EmSpecTest < Test::Unit::TestCase
97
+
98
+ include EventMachine::Test
99
+
100
+ def test_timer
101
+ start = Time.now
102
+
103
+ EM.add_timer(0.5){
104
+ assert_in_delta 0.5, Time.now-start, 0.1
105
+ done
106
+ }
107
+ end
108
+ end
79
109
 
80
110
  Resources:
81
111
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -69,17 +69,18 @@ module EventMachine
69
69
 
70
70
  def self.included(cls)
71
71
  cls.class_eval(<<-HERE_DOC, __FILE__, __LINE__)
72
- include TestHelper
73
-
74
72
  def self.default_timeout(timeout)
75
73
  self.send(:remove_const, :DefaultTimeout)
76
74
  self.send(:const_set, :DefaultTimeout, timeout)
77
75
  end
78
76
 
79
77
  include TestHelper
78
+
80
79
  alias_method :run_without_em, :run
81
80
  def run(result, &block)
82
81
  em(DefaultTimeout) { run_without_em(result, &block) }
82
+ rescue Exception
83
+ add_error($!)
83
84
  end
84
85
 
85
86
  HERE_DOC
@@ -88,6 +89,4 @@ module EventMachine
88
89
 
89
90
  end
90
91
 
91
- end
92
-
93
-
92
+ end
@@ -90,7 +90,7 @@ class EmSpecWithTimeoutOverrideTest < Test::Unit::TestCase
90
90
  end
91
91
 
92
92
  class AnotherNormalTest < Test::Unit::TestCase
93
- def normal_test
93
+ def test_normal
94
94
  assert_equal 1, 1
95
95
  end
96
- end
96
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aman Gupta
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-19 00:00:00 -08:00
12
+ date: 2010-01-16 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15