Class: Konacha::SpecRunner

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runner, spec) ⇒ SpecRunner

Returns a new instance of SpecRunner.



57
58
59
60
# File 'lib/konacha/runner.rb', line 57

def initialize(runner, spec)
  @runner = runner
  @spec = spec
end

Instance Attribute Details

#examplesObject (readonly)

Returns the value of attribute examples.



55
56
57
# File 'lib/konacha/runner.rb', line 55

def examples
  @examples
end

#runnerObject (readonly)

Returns the value of attribute runner.



55
56
57
# File 'lib/konacha/runner.rb', line 55

def runner
  @runner
end

#specObject (readonly)

Returns the value of attribute spec.



55
56
57
# File 'lib/konacha/runner.rb', line 55

def spec
  @spec
end

Instance Method Details

#ioObject



66
67
68
# File 'lib/konacha/runner.rb', line 66

def io
  runner.io
end

#runObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/konacha/runner.rb', line 70

def run
  session.visit(spec.url)

  dots_printed = 0
  begin
    sleep 0.1
    done, dots = session.evaluate_script('[Konacha.done, Konacha.dots]')
    if dots
      io.write dots[dots_printed..-1]
      io.flush
      dots_printed = dots.length
    end
  end until done

  @examples = JSON.parse(session.evaluate_script('Konacha.getResults()')).map do |row|
    Example.new(row)
  end
rescue => e
  raise Konacha::Error, "Error communicating with browser process: #{e.inspect}"
end

#sessionObject



62
63
64
# File 'lib/konacha/runner.rb', line 62

def session
  runner.session
end