Class: Lookout::Expectations

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

Defined Under Namespace

Classes: Behavior, State

Instance Method Summary collapse

Constructor Details

#initialize(results = Lookout::Results::Unsuccessful.new, line = nil) ⇒ Expectations

Returns a new instance of Expectations.



7
8
9
10
11
# File 'lib/lookout/expectations.rb', line 7

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

Instance Method Details

#argObject



17
18
19
# File 'lib/lookout/expectations.rb', line 17

def arg
  Lookout::Mock::Method::Arguments::Anything.new
end

#expect(expected, &block) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/lookout/expectations.rb', line 41

def expect(expected, &block)
  expectation = Lookout::Expectation.on(expected, *Lookout.location(caller.first), &block)
  if @line
    unless @ran_previous
      if @previous and @previous.line <= @line and expectation.line > @line
        @results << @previous.evaluate
        @ran_previous = true
        @previous = nil
      else
        @previous = expectation
      end
    end
  else
    @results << expectation.evaluate
  end
  self
end

#flushObject

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



60
61
62
63
# File 'lib/lookout/expectations.rb', line 60

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

#mockObject



13
14
15
# File 'lib/lookout/expectations.rb', line 13

def mock
  Lookout::Mock::Object.new
end

#output(string) ⇒ Object



29
30
31
# File 'lib/lookout/expectations.rb', line 29

def output(string)
  Lookout::Output.new(string)
end

#stubObject



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

def stub
  Lookout::Stub::Object.new
end

#warning(string) ⇒ Object



33
34
35
# File 'lib/lookout/expectations.rb', line 33

def warning(string)
  Lookout::Warning.new(string)
end

#without_argumentsObject



21
22
23
# File 'lib/lookout/expectations.rb', line 21

def without_arguments
  Lookout::Mock::Method::Arguments::None.new
end

#xml(string) ⇒ Object



37
38
39
# File 'lib/lookout/expectations.rb', line 37

def xml(string)
  Lookout::XML.new(string)
end