Class: Opal::RSpec::Runner

Inherits:
Object
  • Object
show all
Defined in:
opal/opal/rspec/runner.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Runner

Returns a new instance of Runner.



31
32
33
34
35
# File 'opal/opal/rspec/runner.rb', line 31

def initialize(options = {})
  @options = options
  @world = ::RSpec.world
  @configuration = ::RSpec.configuration
end

Class Method Details

.autorunObject



22
23
24
25
26
27
28
# File 'opal/opal/rspec/runner.rb', line 22

def autorun
  if browser?
    `setTimeout(function() { #{Runner.new.run} }, 0)`
  else # phantom
    Runner.new.run
  end
end

.browser?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'opal/opal/rspec/runner.rb', line 6

def browser?
  `typeof(document) !== "undefined"`
end

.default_formatterObject



14
15
16
17
18
19
20
# File 'opal/opal/rspec/runner.rb', line 14

def default_formatter
  if phantom?
    TextFormatter
  else # browser
    BrowserFormatter
  end
end

.phantom?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'opal/opal/rspec/runner.rb', line 10

def phantom?
  `typeof(phantom) !== 'undefined' || typeof(OPAL_SPEC_PHANTOM) !== 'undefined'`
end

Instance Method Details

#finishObject



63
64
65
66
# File 'opal/opal/rspec/runner.rb', line 63

def finish
  @configuration.run_hook(:after, :suite)
  @reporter.finish
end

#run(err = $stdout, out = $stdout) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'opal/opal/rspec/runner.rb', line 37

def run(err=$stdout, out=$stdout)
  @configuration.error_stream = err
  @configuration.output_stream ||= out

  self.start
  run_examples

  run_async_examples do
    self.finish
  end
end

#run_async_examples(&block) ⇒ Object



53
54
55
# File 'opal/opal/rspec/runner.rb', line 53

def run_async_examples(&block)
  AsyncRunner.new(self, @reporter, block).run
end

#run_examplesObject



49
50
51
# File 'opal/opal/rspec/runner.rb', line 49

def run_examples
  @world.example_groups.map { |g| g.run(@reporter) }.all?
end

#startObject



57
58
59
60
61
# File 'opal/opal/rspec/runner.rb', line 57

def start
  @reporter = @configuration.reporter
  @reporter.start(@world.example_count)
  @configuration.run_hook(:before, :suite)
end