Class: Matcha::Runner::SpecRunner

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runner, spec) ⇒ SpecRunner

Returns a new instance of SpecRunner.



30
31
32
33
# File 'lib/matcha/runner.rb', line 30

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

Instance Attribute Details

#runnerObject (readonly)

Returns the value of attribute runner.



28
29
30
# File 'lib/matcha/runner.rb', line 28

def runner
  @runner
end

#specObject (readonly)

Returns the value of attribute spec.



28
29
30
# File 'lib/matcha/runner.rb', line 28

def spec
  @spec
end

Instance Method Details

#dotsObject



81
82
83
# File 'lib/matcha/runner.rb', line 81

def dots
  examples; ""
end

#examplesObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/matcha/runner.rb', line 50

def examples
  @results ||= begin
    session.visit(spec.url)

    previous_results = ""

    session.wait_until(300) do
      dots = session.evaluate_script('Matcha.dots')
      io.print dots.sub(/^#{Regexp.escape(previous_results)}/, '')
      io.flush
      previous_results = dots
      session.evaluate_script('Matcha.done')
    end

    dots = session.evaluate_script('Matcha.dots')
    io.print dots.sub(/^#{Regexp.escape(previous_results)}/, '')

    JSON.parse(session.evaluate_script('Matcha.getResults()')).map do |row|
      Example.new(row)
    end
  end
end

#failed_examplesObject



73
74
75
# File 'lib/matcha/runner.rb', line 73

def failed_examples
  examples.select { |example| not example.passed? }
end

#failure_messagesObject



85
86
87
88
89
# File 'lib/matcha/runner.rb', line 85

def failure_messages
  unless passed?
    examples.map { |example| example.failure_message }.compact.join("\n\n")
  end
end

#ioObject



39
40
41
# File 'lib/matcha/runner.rb', line 39

def io
  runner.io
end

#passed?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/matcha/runner.rb', line 77

def passed?
  examples.all? { |example| example.passed? }
end

#runObject



43
44
45
46
47
48
# File 'lib/matcha/runner.rb', line 43

def run
  io.puts dots
  io.puts failure_messages
  io.puts "\n#{examples.size} examples, #{failed_examples.size} failures"
  passed?
end

#sessionObject



35
36
37
# File 'lib/matcha/runner.rb', line 35

def session
  runner.session
end