Class: Lookout::Runners::Console

Inherits:
Object
  • Object
show all
Defined in:
lib/lookout/runners/console.rb

Instance Method Summary collapse

Constructor Details

#initialize(results = Lookout::Results.new, expectations = Lookout::Expectations.new(results), ui = Lookout::UI::Console.new(results)) ⇒ Console

Returns a new instance of Console.



4
5
6
7
8
9
10
# File 'lib/lookout/runners/console.rb', line 4

def initialize(results = Lookout::Results.new,
               expectations = Lookout::Expectations.new(results),
               ui = Lookout::UI::Console.new(results))
  @results, @expectations, @ui = results, expectations, ui
  @ui.start
  @failed = Lookout::Runners::Trackers::Failure.new(@results)
end

Instance Method Details

#exitObject



32
33
34
35
36
37
# File 'lib/lookout/runners/console.rb', line 32

def exit
  @expectations.flush
  @ui.flush
  super 1 if @failed.failed?
  self
end

#expectations_eval(&block) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/lookout/runners/console.rb', line 39

def expectations_eval(&block)
  @expectations.instance_eval(&block)
rescue Interrupt, NoMemoryError, SignalException, SystemExit
  raise
rescue Exception => e
  raise unless location = Array(e.backtrace).first
  file, line = Lookout.location(location)
  raise unless file and line
  @results << Lookout::Results::Error.new(file, line, nil, e)
end

#installObject



12
13
14
15
16
17
18
19
# File 'lib/lookout/runners/console.rb', line 12

def install
  Kernel.module_exec(self) do |runner|
    define_method :Expectations do |&block|
      runner.expectations_eval(&block)
    end
  end
  self
end

#load(file) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/lookout/runners/console.rb', line 21

def load(file)
  expectations_eval do
    begin
      load file
    rescue SyntaxError => e
      raise unless matches = %r{\A(.*?:\d+): (.*)}m.match(e.message)
      raise SyntaxError, matches[2], [matches[1]]
    end
  end
end