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.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/opal/rspec/runner.rb', line 79

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 << '--enable-source-location' if source_location?
  options << '--enable-file-source-embed' if file_source_embed?
  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.



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

def arity_checking
  @arity_checking
end

#cli_optionsObject

Returns the value of attribute cli_options.



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

def cli_options
  @cli_options
end

#default_pathObject

Returns the value of attribute default_path.



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

def default_path
  @default_path
end

#exclude_patternObject

Returns the value of attribute exclude_pattern.



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

def exclude_pattern
  @exclude_pattern
end

#filesObject

Returns the value of attribute files.



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

def files
  @files
end

#patternObject

Returns the value of attribute pattern.



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

def pattern
  @pattern
end

#requiresObject

Returns the value of attribute requires.



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

def requires
  @requires
end

#runnerObject

Returns the value of attribute runner.



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

def runner
  @runner
end

#spec_optsObject

Returns the value of attribute spec_opts.



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

def spec_opts
  @spec_opts
end

Instance Method Details

#arity_checking?Boolean

Returns:

  • (Boolean)


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

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

#cliObject



135
136
137
# File 'lib/opal/rspec/runner.rb', line 135

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

#commandObject



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

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

#file_source_embed?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/opal/rspec/runner.rb', line 27

def file_source_embed?
  :enabled
end

#get_load_asset_code(server) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/opal/rspec/runner.rb', line 43

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



111
112
113
114
115
116
117
118
119
120
121
# File 'lib/opal/rspec/runner.rb', line 111

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



139
140
141
142
# File 'lib/opal/rspec/runner.rb', line 139

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

#source_location?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/opal/rspec/runner.rb', line 23

def source_location?
  :enabled
end

#timeout=(_) ⇒ Object



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

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