Class: RainforestRubyRuntime::Runner

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Runner

Returns a new instance of Runner.



5
6
7
8
# File 'lib/rainforest_ruby_runtime/runner.rb', line 5

def initialize(options = {})
  @config_options = options.dup.freeze
  @step_variables = options[:step_variables]
end

Instance Attribute Details

#config_optionsObject (readonly)

Returns the value of attribute config_options.



3
4
5
# File 'lib/rainforest_ruby_runtime/runner.rb', line 3

def config_options
  @config_options
end

Instance Method Details

#driverObject



53
54
55
# File 'lib/rainforest_ruby_runtime/runner.rb', line 53

def driver
  ENV.fetch("CAPYBARA_DRIVER") { "selenium" }
end

#extract_results(code, fake_session_id: nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rainforest_ruby_runtime/runner.rb', line 29

def extract_results(code, fake_session_id: nil)
  stdout = stderr = nil
  payload = nil
  begin
    stdout, stderr = capture_output2 do
      run(code)
    end
  rescue RSpec::Expectations::ExpectationNotMetError => e
    payload = exception_to_payload e, status: 'failed'
  rescue StandardError => e
    payload = exception_to_payload e, status: 'error'
  rescue SyntaxError, Exception => e
    payload = exception_to_payload e, status: 'fatal_error'
  end

  payload ||= { status: 'passed' }

  payload.merge({
    stdout: stdout,
    stderr: stderr,
    session_id: fake_session_id || session_id
  })
end

#run(code) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rainforest_ruby_runtime/runner.rb', line 10

def run(code)
  extend RainforestRubyRuntime::DSL
  Capybara.default_driver = :"#{driver}"
  Capybara.default_wait_time = wait_time

  apply_config!
  setup_scope_registery!

  test = eval(code)
  if Test === test
    test.run
  else
    raise WrongReturnValueError, test
  end
  test
ensure
  terminate_session!
end