File tree Expand file tree Collapse file tree 2 files changed +7
-13
lines changed Expand file tree Collapse file tree 2 files changed +7
-13
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ I will use TMF in my projects and discover if such a minimalistic tool can be pr
23
23
# => true
24
24
25
25
assert(1 + 1 , :equals => 3 )
26
- # => TMF::AssertionFailed : Expected 2 to equal 3
26
+ # => TMF::ExpectationNotMet : Expected 2 to equal 3
27
27
28
28
assert(Object .foo, :equals => :bar )
29
29
# => NoMethodError: undefined method `foo' for Object:Class
@@ -108,7 +108,7 @@ And you also have a file `PROJECT_ROOT/test/foo_test.rb` with the following:
108
108
109
109
# failing test
110
110
assert(f.class , :equals => ' Bar' )
111
- # => TMF::AssertionFailed : Expected Foo to equal Bar
111
+ # => TMF::ExpectationNotMet : Expected Foo to equal Bar
112
112
113
113
# stub with passing test
114
114
stub(f, :method => :class , :return => ' Bar' ) do
@@ -120,7 +120,7 @@ And you also have a file `PROJECT_ROOT/test/foo_test.rb` with the following:
120
120
stub(f, :method => :bar , :return => :baz ) do
121
121
assert(f.bar, :equals => :snafu )
122
122
end
123
- # TMF::AssertionFailed : Expected baz to equal snafu
123
+ # TMF::ExpectationNotMet : Expected baz to equal snafu
124
124
125
125
# testing a raised error
126
126
begin
Original file line number Diff line number Diff line change 21
21
# THE SOFTWARE.
22
22
23
23
module TMF
24
- class AssertionFailed < StandardError
25
- def initialize ( a , b )
26
- super ( "Expected #{ a } to equal #{ b } " )
27
- end
28
- end
29
-
30
24
class ExpectationNotMet < StandardError
31
- def initialize ( o , method )
32
- super ( "Expected #{ o } to receive #{ method } " )
25
+ def initialize ( o , method , verb )
26
+ super ( "Expected #{ o } to #{ verb } #{ method } " )
33
27
end
34
28
end
35
29
36
30
def assert ( a , opts )
37
- a == opts [ :equals ] ? true : raise ( AssertionFailed . new ( a , opts [ :equals ] ) )
31
+ a == opts [ :equals ] ? true : raise ( ExpectationNotMet . new ( a , opts [ :equals ] , 'equal' ) )
38
32
end
39
33
40
34
def stub ( o , opts )
@@ -44,7 +38,7 @@ def stub(o, opts)
44
38
o . singleton_class . send ( :define_method , opts [ :method ] ) { called = 1 ; opts [ :return ] }
45
39
result = yield if block_given?
46
40
47
- raise ExpectationNotMet . new ( o , opts [ :method ] ) if opts [ :spy ] && !called
41
+ raise ExpectationNotMet . new ( o , opts [ :method ] , 'receive' ) if opts [ :spy ] && !called
48
42
49
43
result
50
44
ensure
You can’t perform that action at this time.
0 commit comments