Class: RSpec::Core::Runner

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.autorunObject



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

def autorun
  # see NoCarriageReturnIO source for why this is being done (not on Node though)
  err, out = get_opal_closed_tty_io
  # Have to do this in 2 places. This will ensure the default formatter gets the right IO, but need to do this in config for custom formatters
  # that will be constructed BEFORE this runs, see rspec.rb
  run(ARGV, err, out).then do |status|
    exit_with_code status.to_i
  end
end

.browser?Boolean

Returns:

  • (Boolean)


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

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

.exit_with_code(code) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'opal/opal/rspec/runner.rb', line 47

def exit_with_code(code)
  # have to ignore OPAL_SPEC_PHANTOM for this one
  if `typeof(phantom) !== "undefined"`
    `phantom_exit(#{code})`
  elsif node?
    `process.exit(#{code})`
  else
    `Opal.global.OPAL_SPEC_CODE = #{code}`
  end
end

.get_opal_closed_tty_ioObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'opal/opal/rspec/runner.rb', line 22

def get_opal_closed_tty_io
  runner_type = if phantom?
                  :phantom
                elsif node?
                  :node
                else
                  :browser
                end
  std_out = OpalClosedTtyIO.new runner_type,
                                :stdout
  std_err = OpalClosedTtyIO.new runner_type,
                                :stderr
  [std_err, std_out]
end

.node?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'opal/opal/rspec/runner.rb', line 14

def node?
  `typeof(process) !== 'undefined' && typeof(process.versions) !== 'undefined'`
end

.non_browser?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'opal/opal/rspec/runner.rb', line 18

def non_browser?
  phantom? || node?
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

.run(args, err = $stderr, out = $stdout) ⇒ Object



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

def run(args, err=$stderr, out=$stdout)
  options = ConfigurationOptions.new(args)
  new(options).run(err, out)
end

Instance Method Details

#run_groups_async(example_groups, reporter) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'opal/opal/rspec/runner.rb', line 64

def run_groups_async(example_groups, reporter)
  results = []
  last_promise = example_groups.inject(Promise.value(true)) do |previous_promise, group|
    previous_promise.then do |result|
      results << result
      group.run reporter
    end
  end
  last_promise.then do |result|
    results << result
    results.all? ? 0 : @configuration.failure_exit_code
  end
end

#run_specs(example_groups) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
# File 'opal/opal/rspec/runner.rb', line 78

def run_specs(example_groups)
  @configuration.reporter.report_async(@world.example_count(example_groups)) do |reporter|
    hook_context = SuiteHookContext.new
    Promise.value(true).then do
      @configuration.hooks.run(:before, :suite, hook_context)
      run_groups_async example_groups, reporter
    end.ensure do |result|
      @configuration.hooks.run(:after, :suite, hook_context)
      result
    end
  end
end