opal-rspec 0.3.0.beta2 → 0.3.0.beta3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5bd79540d6e74c4df7d716c4ca5b8f03cde5a6e
4
- data.tar.gz: 723db13931f42a37a78ae3c2aecef9ef6eb17df2
3
+ metadata.gz: 84230cf1d8509f28c633e0e882d33c09f1246b24
4
+ data.tar.gz: aec3b03f1a636f28f306cac7fda0dc96a1315d93
5
5
  SHA512:
6
- metadata.gz: 4072ac6a74fe502ca4c83b828934c5f88216d83ede42a03adf3e7cfad083ead45b8f624cb38671cc82912136746a6f8fbdf2475221aaa75d76276b0169ed3b12
7
- data.tar.gz: 8256bba226056877123b8a50439d8eca2eeed995b4ba9b8eed3f34954a2bee31f544b9c86bd4ec79af1ca0ed76cdad96e41c5d5adc2f15d2c754ff98dbe2bdc9
6
+ metadata.gz: 9cdd2b63ace9e719b2c96af8e81120086c7840d5169b5691732bdd71b56b84731cfeb6d4a07abb4bd4ff6f6d4e984b802b00bdd7b0f66015e617a4041bc0d1ca
7
+ data.tar.gz: fa734e9b5618dc8d10944f253f6028d1e7850223b2919d44b32677bea6f53dbd42de1b04c09623bdd420958b1553148a1250642b36d1f4d099da1fb26ee12ea9
data/CHANGELOG.md CHANGED
@@ -8,4 +8,6 @@
8
8
 
9
9
  * Replaced browser formatter to use html printer from rspec
10
10
 
11
+ * Add timeout support to asynchronous specs
12
+
11
13
  ## 0.2.1 2013-11-24
@@ -1,5 +1,5 @@
1
1
  module Opal
2
2
  module RSpec
3
- VERSION = '0.3.0.beta2'
3
+ VERSION = '0.3.0.beta3'
4
4
  end
5
5
  end
@@ -8,14 +8,18 @@ module Opal
8
8
  end
9
9
 
10
10
  module AsyncHelpers
11
- def run_async(&block)
12
- ::RSpec.current_example.continue_async(block)
11
+ def async(&block)
12
+ @example.continue_async(block)
13
13
  end
14
14
 
15
- def set_timeout(duration, &block)
16
- `setTimeout(block, duration)`
15
+ alias run_async async
16
+
17
+ def delay(duration, &block)
18
+ `setTimeout(block, duration * 1000)`
17
19
  self
18
20
  end
21
+
22
+ alias set_timeout delay
19
23
  end
20
24
 
21
25
  class AsyncRunner
@@ -70,14 +74,18 @@ module Opal
70
74
  @examples ||= []
71
75
  end
72
76
 
77
+ include AsyncHelpers
78
+
73
79
  def run(example_group_instance, reporter, &after_run_block)
74
80
  @example_group_instance = example_group_instance
75
- @reporter = reporter
76
- @after_run_block = after_run_block
81
+ @reporter = reporter
82
+ @after_run_block = after_run_block
83
+ @finished = false
77
84
 
78
85
  should_wait = true
79
86
 
80
87
  ::RSpec.current_example = self
88
+ example_group_instance.instance_variable_set :@example, self
81
89
 
82
90
  start(reporter)
83
91
 
@@ -89,10 +97,21 @@ module Opal
89
97
  should_wait = false
90
98
  end
91
99
 
92
- async_example_finished unless should_wait
100
+ if should_wait
101
+ delay options[:timeout] || 10 do
102
+ next if finished?
103
+
104
+ set_exception RuntimeError.new("timeout")
105
+ async_example_finished
106
+ end
107
+ else
108
+ async_example_finished
109
+ end
93
110
  end
94
111
 
95
112
  def continue_async(block)
113
+ return if finished?
114
+
96
115
  begin
97
116
  block.call
98
117
  rescue Exception => e
@@ -102,7 +121,13 @@ module Opal
102
121
  async_example_finished
103
122
  end
104
123
 
124
+ def finished?
125
+ @finished
126
+ end
127
+
105
128
  def async_example_finished
129
+ @finished = true
130
+
106
131
  begin
107
132
  run_after_each
108
133
  rescue Exception => e
data/spec/async_spec.rb CHANGED
@@ -22,7 +22,7 @@ describe "Asynchronous helpers" do
22
22
  async "can finish running after a long delay" do
23
23
  obj = [1, 2, 3, 4]
24
24
 
25
- set_timeout 100 do
25
+ delay(1) do
26
26
  run_async { obj.should == [1, 2, 3, 4] }
27
27
  end
28
28
  end
@@ -32,7 +32,7 @@ describe "Asynchronous helpers" do
32
32
  expect(:foo).to eq(:baz)
33
33
  }.to raise_error(Exception)
34
34
 
35
- set_timeout(0) do
35
+ delay(0) do
36
36
  run_async { expect(42).to eq(42) }
37
37
  end
38
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0.beta2
4
+ version: 0.3.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Beynon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-17 00:00:00.000000000 Z
11
+ date: 2014-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  version: 1.3.1
101
101
  requirements: []
102
102
  rubyforge_project:
103
- rubygems_version: 2.1.9
103
+ rubygems_version: 2.0.3
104
104
  signing_key:
105
105
  specification_version: 4
106
106
  summary: RSpec for Opal