-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathshould.rb
More file actions
39 lines (34 loc) · 1.05 KB
/
should.rb
File metadata and controls
39 lines (34 loc) · 1.05 KB
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
36
37
38
39
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 RaiseErrorMatcher === matcher
MSpec.deprecate('->{}.should_not raise_error', 'a matcher to verify the result')
end
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