Module: Expectations::RecordedExpectation

Defined in:
lib/expectations/recorded_expectation.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/expectations/recorded_expectation.rb', line 2

def execute
  begin
    mocha_setup
    expected.subject!
    warn_for_expects do
      instance_exec(expected.subject, &block) if block
    end
    if expected.subject.is_a?(Mocha::Mock) &&
        !Mocha::Mockery.instance.mocks.include?(expected.subject)
      Mocha::Mockery.instance.__send__(:add_mock, expected.subject)
    end
    if expected.verify! && mocha_verify
      self.extend(Expectations::Results::Fulfilled)
    else
      self.extend(Expectations::Results::StateBasedFailure)
      self.message = expected.failure_message
    end
  rescue Mocha::ExpectationError => ex
    self.extend(Expectations::Results::BehaviorBasedFailure)
    self.message = expected.mocha_error_message(ex)
  rescue Exception => ex
    self.extend(Expectations::Results::Error)
    self.exception = ex
  ensure
    mocha_teardown
  end
  self
end