Class: Opal::RSpec::Runner

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

Defined Under Namespace

Classes: LegacyServerProxy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Runner

Returns a new instance of Runner.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/opal/rspec/runner.rb', line 70

def initialize(&block)
  @legacy_server_proxy = LegacyServerProxy.new
  block.call(@legacy_server_proxy, self) if block_given? # for compatibility

  raise 'Cannot supply both a pattern and files!' if self.files and self.pattern

  locator = ::Opal::RSpec::Locator.new pattern: self.pattern, exclude_pattern: self.exclude_pattern, files: self.files, default_path: self.default_path

  options = []
  options << '--arity-check' if arity_checking?
  options += ['--runner', runner] unless runner.empty?
  options << '-ropal-rspec'
  options << '--missing-require=ignore'
  options += @legacy_server_proxy.to_cli_options

  Opal.paths.each                     { |p| options << "-I#{p}" }
  locator.get_spec_load_paths.each    { |p| options << "-I#{p}" }
  requires.each                       { |p| options << "-r#{p}" }
  locator.get_opal_spec_requires.each { |p| options << "-r#{p}" }
  ::Opal::Config.stubbed_files.each   { |p| options << "-s#{p}" }

  options += @cli_options if @cli_options
  bootstrap_code = [
    ::Opal::RSpec.spec_opts_code(spec_opts),
    '::RSpec::Core::Runner.autorun',
  ].join(';')

  @args = "#{options.map(&:shellescape).join ' '} -e #{bootstrap_code.shellescape}"
end

Instance Attribute Details

#arity_checkingObject

Returns the value of attribute arity_checking.



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

def arity_checking
  @arity_checking
end

#cli_optionsObject

Returns the value of attribute cli_options.



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

def cli_options
  @cli_options
end

#default_pathObject

Returns the value of attribute default_path.



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

def default_path
  @default_path
end

#exclude_patternObject

Returns the value of attribute exclude_pattern.



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

def exclude_pattern
  @exclude_pattern
end

#filesObject

Returns the value of attribute files.



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

def files
  @files
end

#patternObject

Returns the value of attribute pattern.



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

def pattern
  @pattern
end

#requiresObject

Returns the value of attribute requires.



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

def requires
  @requires
end

#runnerObject

Returns the value of attribute runner.



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

def runner
  @runner
end

#spec_optsObject

Returns the value of attribute spec_opts.



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

def spec_opts
  @spec_opts
end

Instance Method Details

#arity_checking?Boolean

Returns:

  • (Boolean)


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

def arity_checking?
  setting = @arity_checking || :enabled
  setting == :enabled
end

#cliObject



124
125
126
# File 'lib/opal/rspec/runner.rb', line 124

def cli
  @cli ||= ::Opal::CLI.new(cli_options)
end

#commandObject



112
113
114
# File 'lib/opal/rspec/runner.rb', line 112

def command
  @command ||= "opal #{@args}"
end

#get_load_asset_code(server) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/opal/rspec/runner.rb', line 34

def get_load_asset_code(server)
  sprockets = server.sprockets
  name = server.main
  asset = sprockets[name]
  raise "Cannot find asset: #{name}" if asset.nil?
  # Opal::Sprockets.load_asset name, sprockets
  ''
end

#optionsObject



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/opal/rspec/runner.rb', line 100

def options
  {
    pattern: pattern,
    exclude_pattern: exclude_pattern,
    files: files,
    default_path: default_path,
    runner: runner,
    arity_checking: arity_checking,
    spec_opts: spec_opts,
  }
end

#runObject



128
129
130
131
# File 'lib/opal/rspec/runner.rb', line 128

def run
  ENV['OPAL_CLI_RUNNERS_SERVER_STATIC_FOLDER'] = default_path
  cli.run
end

#timeout=(_) ⇒ Object



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

def timeout= _
  warn "deprecated: setting timeout has no effect"
end