summaryrefslogtreecommitdiff
path: root/spec/mspec/lib/mspec/expectations/should.rb
blob: ca0617484cfec717e4ca1d8dc7589b5e6b970f87 (plain)
1
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
30
31
32
33
34
35
class Object
  NO_MATCHER_GIVEN = Object.new

  def should(matcher = NO_MATCHER_GIVEN)
    MSpec.expectation
    state = MSpec.current.state
    raise "should outside example" unless state
    MSpec.actions :expectation, state

    if NO_MATCHER_GIVEN.equal?(matcher)
      SpecPositiveOperatorMatcher.new(self)
    else
      unless matcher.matches? self
        expected, actual = matcher.failure_message
        SpecExpectation.fail_with(expected, actual)
      end
    end
  end

  def should_not(matcher = NO_MATCHER_GIVEN)
    MSpec.expectation
    state = MSpec.current.state
    raise "should_not outside example" unless state
    MSpec.actions :expectation, state

    if NO_MATCHER_GIVEN.equal?(matcher)
      SpecNegativeOperatorMatcher.new(self)
    else
      if matcher.matches? self
        expected, actual = matcher.negative_failure_message
        SpecExpectation.fail_with(expected, actual)
      end
    end
  end
end