Module: Lookout::Expectation

Included in:
Lookout::Expectations::Behavior, Lookout::Expectations::State
Defined in:
lib/lookout/expectation.rb

Defined Under Namespace

Classes: Method

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



49
50
51
# File 'lib/lookout/expectation.rb', line 49

def file
  @file
end

#lineObject (readonly)

Returns the value of attribute line.



49
50
51
# File 'lib/lookout/expectation.rb', line 49

def line
  @line
end

Class Method Details

.on(expected, file, line, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/lookout/expectation.rb', line 4

def self.on(expected, file, line, &block)
  case expected
  when Lookout::Recorder
    Lookout::Expectations::Behavior
  when Lookout::Warning
    Lookout::Expectations::State::Warning
  else
    Lookout::Expectations::State
  end.new(expected, file, line, &block)
end

Instance Method Details

#evaluateObject



19
20
21
# File 'lib/lookout/expectation.rb', line 19

def evaluate
  Lookout::Stub.methods{ |stubs| @stubs = stubs; evaluate_with_stubs }.tap{ @stubs = nil }
end

#initialize(expected, file, line, &block) ⇒ Object



15
16
17
# File 'lib/lookout/expectation.rb', line 15

def initialize(expected, file, line, &block)
  @expected, @file, @line, @block = expected, file, line, block
end

#stub(*args) ⇒ Object

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/lookout/expectation.rb', line 23

def stub(*args)
  raise ArgumentError,
    'wrong number of arguments (%d for 1)' % args.length unless args.count < 2
  return Lookout::Stub::Object.new if args.length < 1
  case args[0]
  when Hash
    Lookout::Stub::Object.new.tap{ |stub|
      args[0].each do |name, value|
        @stubs.define(stub, name){ value }
      end
    }
  else
    Method.new(@stubs, args[0])
  end
end

#with_verbose(verbose = true) ⇒ Object



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

def with_verbose(verbose = true)
  saved_verbose = $VERBOSE
  $VERBOSE = verbose
  begin
    yield
  ensure
    $VERBOSE = saved_verbose
  end
end