Class: Matcha::Runner

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

Defined Under Namespace

Classes: Example, SpecRunner

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Runner

Returns a new instance of Runner.



94
95
96
# File 'lib/matcha/runner.rb', line 94

def initialize(options = {})
  @io = options[:output] || STDOUT
end

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io.



92
93
94
# File 'lib/matcha/runner.rb', line 92

def io
  @io
end

#suiteObject (readonly)

Returns the value of attribute suite.



92
93
94
# File 'lib/matcha/runner.rb', line 92

def suite
  @suite
end

Class Method Details

.startObject



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

def self.start
  new.run
end

Instance Method Details

#dotsObject



131
132
133
# File 'lib/matcha/runner.rb', line 131

def dots
  spec_runners.map { |spec_runner| spec_runner.dots }.join
end

#examplesObject



119
120
121
# File 'lib/matcha/runner.rb', line 119

def examples
  spec_runners.map { |spec_runner| spec_runner.examples }.flatten
end

#failed_examplesObject



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

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

#failure_messagesObject



135
136
137
138
139
# File 'lib/matcha/runner.rb', line 135

def failure_messages
  unless passed?
    spec_runners.map { |spec_runner| spec_runner.failure_messages }.compact.join("\n\n")
  end
end

#passed?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/matcha/runner.rb', line 127

def passed?
  spec_runners.all? { |spec_runner| spec_runner.passed? }
end

#runObject



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/matcha/runner.rb', line 102

def run
  before = Time.now

  io.puts ""
  io.puts dots.to_s
  io.puts ""
  if failure_messages
    io.puts failure_messages
    io.puts ""
  end

  seconds = "%.2f" % (Time.now - before)
  io.puts "Finished in #{seconds} seconds"
  io.puts "#{examples.size} examples, #{failed_examples.size} failures"
  passed?
end

#sessionObject



141
142
143
# File 'lib/matcha/runner.rb', line 141

def session
  @session ||= Capybara::Session.new(Matcha.driver, Matcha.application)
end

#spec_runner(spec) ⇒ Object



98
99
100
# File 'lib/matcha/runner.rb', line 98

def spec_runner(spec)
  SpecRunner.new(self, spec)
end