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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Runner

Returns a new instance of Runner.



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/opal/rspec/runner.rb', line 96

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 \
                                                  && !self.files.empty? \
                                                  && self.pattern

  append_opts_from_config_file

  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

  spec_opts.delete(:opal_rbrequires) { [] }.each do |r|
    require r
  end

  load_paths = [Opal.paths, locator.get_spec_load_paths, self.libs].compact.sum([]).uniq

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

  options += @cli_options if @cli_options
  options += spec_opts.delete(:opal_options) { [] }

  bootstrap_code = ::Opal::RSpec.spec_opts_code(spec_opts)

  @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

#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

Class Method Details

.spec_opts_accessor(*names) ⇒ Object

Delegate property changes to spec_opts



15
16
17
18
19
20
21
22
23
24
# File 'lib/opal/rspec/runner.rb', line 15

def self.spec_opts_accessor(*names)
  names.each do |name|
    define_method name do
      spec_opts[name]
    end
    define_method :"#{name}=" do |value|
      spec_opts[name] = value
    end
  end
end

Instance Method Details

#append_opts_from_config_fileObject



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/opal/rspec/runner.rb', line 139

def append_opts_from_config_file
  self.libs ||= []
  self.requires ||= []

  config_location = nil
  path = self.default_path || "spec-opal"

  # Locate config file
  begin
    loop do
      if File.exist?(File.join(path, ".rspec-opal"))
        path = File.join(path, ".rspec-opal")
        break
      else
        new_path = File.expand_path("..", path)
        return if new_path == path
        path = new_path
      end
    end
  rescue e
    # we've gone too far beyond our permissions without finding a config file
    return
  end

  if path
    config_opts = Opal::RSpec.convert_spec_opts(File.read(path))
  else
    return
  end

  self.spec_opts = config_opts.merge(spec_opts) do |key, oldval, newval|
    [:libs, :requires].include?(key) ? oldval + newval : newval
  end
end

#arity_checking?Boolean

Returns:

  • (Boolean)


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

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

#cliObject



198
199
200
# File 'lib/opal/rspec/runner.rb', line 198

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

#commandObject



186
187
188
# File 'lib/opal/rspec/runner.rb', line 186

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

#file_source_embed?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/opal/rspec/runner.rb', line 44

def file_source_embed?
  :enabled
end

#get_load_asset_code(server) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/opal/rspec/runner.rb', line 60

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



174
175
176
177
178
179
180
181
182
183
184
# File 'lib/opal/rspec/runner.rb', line 174

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

#requiresObject



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

def requires
  spec_opts[:requires] ||= []
end

#runObject



202
203
204
205
# File 'lib/opal/rspec/runner.rb', line 202

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

#source_location?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/opal/rspec/runner.rb', line 40

def source_location?
  :enabled
end

#timeout=(_) ⇒ Object



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

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