Class: Expectations::Expectation

Inherits:
Object
  • Object
show all
Includes:
Mocha::API
Defined in:
lib/expectations/expectation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Expectation.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/expectations/expectation.rb', line 5

def initialize(expected, file, line, &block)
  self.expected = expected
  self.block = block
  self.file, self.line = file, line.to_i

  if expected.is_a?(Expectations::Recorder)
    extend(Expectations::RecordedExpectation)
  elsif !block
    extend(Expectations::RecordedExpectation)
    self.expected = Expectations::Recorder.new(self.expected)
    self.expected.extend(Expectations::StateBasedRecorder)
    self.expected.extend(Expectations::StateBasedRecorderForExpectationsWithoutBlock)
    self.expected.file = file
    self.expected.line = line
  else
    extend(Expectations::StateBasedExpectation)
  end
end

Instance Attribute Details

#actualObject

Returns the value of attribute actual.



3
4
5
# File 'lib/expectations/expectation.rb', line 3

def actual
  @actual
end

#blockObject

Returns the value of attribute block.



3
4
5
# File 'lib/expectations/expectation.rb', line 3

def block
  @block
end

#expectedObject

Returns the value of attribute expected.



3
4
5
# File 'lib/expectations/expectation.rb', line 3

def expected
  @expected
end

#fileObject

Returns the value of attribute file.



3
4
5
# File 'lib/expectations/expectation.rb', line 3

def file
  @file
end

#lineObject

Returns the value of attribute line.



3
4
5
# File 'lib/expectations/expectation.rb', line 3

def line
  @line
end

Instance Method Details

#mock(*args) ⇒ Object



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

def mock(*args)
  Expectations::StandardError.print "mock method called from #{caller.first.chomp(":in `__instance_exec0'")}\n"
  super
end

#warn_for_expectsObject



29
30
31
32
33
34
# File 'lib/expectations/expectation.rb', line 29

def warn_for_expects
  Object.__which_expects__ = ExpectationsExpectsMethod
  yield
ensure
  Object.__which_expects__ = MochaExpectsMethod
end