Class: Lookout::Expectations::Line

Inherits:
Lookout::Expectations show all
Defined in:
lib/lookout/expectations/line.rb

Instance Method Summary collapse

Methods inherited from Lookout::Expectations

#arg, #mock, #output, #stub, #warning, #without_arguments, #xml

Constructor Details

#initialize(line, results = Lookout::Results.new) ⇒ Line

Returns a new instance of Line.



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

def initialize(line, results = Lookout::Results.new)
  super results
  @line = line
  @previous = nil
  @ran_previous = false
end

Instance Method Details

#expect(expected) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/lookout/expectations/line.rb', line 11

def expect(expected)
  return self if @ran_previous
  expectation = Lookout::Expectation.on(expected, *Lookout.location(caller.first), &Proc.new)
  if @previous and @previous.line <= @line and expectation.line > @line
    flush
    @previous = nil
    @ran_previous = true
  else
    @previous = expectation
  end
  self
end

#flushObject

TODO: It would be great if this method wasn’t necessary.



25
26
27
28
# File 'lib/lookout/expectations/line.rb', line 25

def flush
  @results << @previous.evaluate if @previous
  self
end