forked from freerange/mocha
-
Notifications
You must be signed in to change notification settings - Fork 1
/
failure_messages_test.rb
64 lines (51 loc) · 1.81 KB
/
failure_messages_test.rb
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require File.expand_path('../acceptance_test_helper', __FILE__)
require 'mocha'
class FailureMessagesTest < Test::Unit::TestCase
OBJECT_ADDRESS_PATTERN = '0x[0-9A-Fa-f]{1,12}'
include AcceptanceTest
def setup
setup_acceptance_test
end
def teardown
teardown_acceptance_test
end
class Foo; end
def test_should_display_class_name_when_expectation_was_on_class
test_result = run_as_test do
Foo.expects(:bar)
end
assert_match Regexp.new('FailureMessagesTest::Foo'), test_result.failures[0].message
end
def test_should_display_class_name_and_address_when_expectation_was_on_instance
test_result = run_as_test do
Foo.new.expects(:bar)
end
assert_match Regexp.new("#<FailureMessagesTest::Foo:#{OBJECT_ADDRESS_PATTERN}>"), test_result.failures[0].message
end
def test_should_display_class_name_and_any_instance_prefix_when_expectation_was_on_any_instance
test_result = run_as_test do
Foo.any_instance.expects(:bar)
end
assert_match Regexp.new('#<AnyInstance:FailureMessagesTest::Foo>'), test_result.failures[0].message
end
def test_should_display_mock_name_when_expectation_was_on_named_mock
test_result = run_as_test do
foo = mock('foo')
foo.expects(:bar)
end
assert_match Regexp.new('#<Mock:foo>'), test_result.failures[0].message
end
def test_should_display_mock_address_when_expectation_was_on_unnamed_mock
test_result = run_as_test do
foo = mock()
foo.expects(:bar)
end
assert_match Regexp.new("#<Mock:#{OBJECT_ADDRESS_PATTERN}>"), test_result.failures[0].message
end
def test_should_display_string_when_expectation_was_on_string
test_result = run_as_test do
'Foo'.expects(:bar)
end
assert_match Regexp.new("'Foo'"), test_result.failures[0].message
end
end