Class: Opal::RSpec::AsyncExample
- Inherits:
-
RSpec::Core::Example
- Object
- RSpec::Core::Example
- Opal::RSpec::AsyncExample
- Includes:
- AsyncHelpers
- Defined in:
- opal/opal/rspec/async.rb
Overview
An AsyncExample is a subclass of regular example instances which adds support for running an example, and waiting for a non-sync outcome. All async examples in a set of spec files will get registered through AsyncExample.register, and added to the AsyncExample.examples array ready for the runner to run.
You will not need to create new instances of this class directly, and should instead use AsyncHelpers to create async examples.
Class Method Summary collapse
-
.examples ⇒ Array<AsyncExample>
All async examples in specs.
-
.register(*args) ⇒ Object
Register new async example.
Instance Method Summary collapse
- #async_example_finished ⇒ Object
- #continue_async(block) ⇒ Object
- #finished? ⇒ Boolean
- #run(example_group_instance, reporter, &after_run_block) ⇒ Object
Methods included from AsyncHelpers
#async, #delay, included, #run_async, #set_timeout
Class Method Details
.examples ⇒ Array<AsyncExample>
All async examples in specs.
210 211 212 |
# File 'opal/opal/rspec/async.rb', line 210 def self.examples @examples ||= [] end |
.register(*args) ⇒ Object
Register new async example.
203 204 205 |
# File 'opal/opal/rspec/async.rb', line 203 def self.register(*args) examples << new(*args) end |
Instance Method Details
#async_example_finished ⇒ Object
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'opal/opal/rspec/async.rb', line 263 def async_example_finished @finished = true begin run_after_each rescue Exception => e set_exception(e) ensure @example_group_instance.instance_variables.each do |ivar| @example_group_instance.instance_variable_set(ivar, nil) end @example_group_instance = nil begin assign_generated_description rescue Exception => e set_exception(e, "while assigning the example description") end end finish(@reporter) ::RSpec.current_example = nil @after_run_block.call end |
#continue_async(block) ⇒ Object
247 248 249 250 251 252 253 254 255 256 257 |
# File 'opal/opal/rspec/async.rb', line 247 def continue_async(block) return if finished? begin block.call rescue Exception => e set_exception(e) end async_example_finished end |
#finished? ⇒ Boolean
259 260 261 |
# File 'opal/opal/rspec/async.rb', line 259 def finished? @finished end |
#run(example_group_instance, reporter, &after_run_block) ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'opal/opal/rspec/async.rb', line 214 def run(example_group_instance, reporter, &after_run_block) @example_group_instance = example_group_instance @reporter = reporter @after_run_block = after_run_block @finished = false should_wait = true ::RSpec.current_example = self example_group_instance.instance_variable_set :@example, self start(reporter) begin run_before_each @example_group_instance.instance_exec(self, &@example_block) rescue Exception => e set_exception(e) should_wait = false end if should_wait delay [:timeout] || 10 do next if finished? set_exception RuntimeError.new("timeout") async_example_finished end else async_example_finished end end |