bourne 1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,163 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+ require 'bourne/mockery'
3
+ require 'mocha/state_machine'
4
+ require 'bourne/invocation'
5
+
6
+ class MockeryTest < Test::Unit::TestCase
7
+
8
+ include Mocha
9
+
10
+ def test_should_build_instance_of_mockery
11
+ mockery = Mockery.instance
12
+ assert_not_nil mockery
13
+ assert_kind_of Mockery, mockery
14
+ end
15
+
16
+ def test_should_cache_instance_of_mockery
17
+ mockery_1 = Mockery.instance
18
+ mockery_2 = Mockery.instance
19
+ assert_same mockery_1, mockery_2
20
+ end
21
+
22
+ def test_should_expire_mockery_instance_cache
23
+ mockery_1 = Mockery.instance
24
+ Mockery.reset_instance
25
+ mockery_2 = Mockery.instance
26
+ assert_not_same mockery_1, mockery_2
27
+ end
28
+
29
+ def test_should_raise_expectation_error_because_not_all_expectations_are_satisfied
30
+ mockery = Mockery.new
31
+ mock_1 = mockery.named_mock('mock-1') { expects(:method_1) }
32
+ mock_2 = mockery.named_mock('mock-2') { expects(:method_2) }
33
+ 1.times { mock_1.method_1 }
34
+ 0.times { mock_2.method_2 }
35
+ assert_raises(ExpectationError) { mockery.verify }
36
+ end
37
+
38
+ def test_should_reset_list_of_mocks_on_teardown
39
+ mockery = Mockery.new
40
+ mock = mockery.unnamed_mock { expects(:my_method) }
41
+ mockery.teardown
42
+ assert_nothing_raised(ExpectationError) { mockery.verify }
43
+ end
44
+
45
+ def test_should_build_instance_of_stubba_on_instantiation
46
+ mockery = Mockery.new
47
+ assert_not_nil mockery.stubba
48
+ assert_kind_of Central, mockery.stubba
49
+ end
50
+
51
+ def test_should_build_new_instance_of_stubba_on_teardown
52
+ mockery = Mockery.new
53
+ stubba_1 = mockery.stubba
54
+ mockery.teardown
55
+ stubba_2 = mockery.stubba
56
+ assert_not_same stubba_1, stubba_2
57
+ end
58
+
59
+ def test_should_build_and_store_new_state_machine
60
+ mockery = Mockery.new
61
+ mockery.new_state_machine('state-machine-name')
62
+ assert_equal 1, mockery.state_machines.length
63
+ assert_kind_of StateMachine, mockery.state_machines[0]
64
+ end
65
+
66
+ def test_should_reset_list_of_state_machines_on_teardown
67
+ mockery = Mockery.new
68
+ mockery.new_state_machine('state-machine-name')
69
+ mockery.teardown
70
+ assert_equal 0, mockery.state_machines.length
71
+ end
72
+
73
+ class FakeMethod
74
+ def stub; end
75
+ def unstub; end
76
+ end
77
+
78
+ def test_should_unstub_all_methods_on_teardown
79
+ mockery = Mockery.new
80
+ stubba = mockery.stubba
81
+ stubba.stub(FakeMethod.new)
82
+ mockery.teardown
83
+ assert stubba.stubba_methods.empty?
84
+ end
85
+
86
+ def test_should_display_object_id_for_mocha_inspect_if_mock_has_no_name
87
+ mockery = Mockery.new
88
+ mock = mockery.unnamed_mock
89
+ assert_match Regexp.new("^#<Mock:0x[0-9A-Fa-f]{1,12}>$"), mock.mocha_inspect
90
+ end
91
+
92
+ def test_should_display_object_id_for_inspect_if_mock_has_no_name
93
+ mockery = Mockery.new
94
+ mock = mockery.unnamed_mock
95
+ assert_match Regexp.new("^#<Mock:0x[0-9A-Fa-f]{1,12}>$"), mock.inspect
96
+ end
97
+
98
+ def test_should_display_name_for_mocha_inspect_if_mock_has_string_name
99
+ mockery = Mockery.new
100
+ mock = mockery.named_mock('named_mock')
101
+ assert_equal "#<Mock:named_mock>", mock.mocha_inspect
102
+ end
103
+
104
+ def test_should_display_name_for_mocha_inspect_if_mock_has_symbol_name
105
+ mockery = Mockery.new
106
+ mock = mockery.named_mock(:named_mock)
107
+ assert_equal "#<Mock:named_mock>", mock.mocha_inspect
108
+ end
109
+
110
+ def test_should_display_name_for_inspect_if_mock_has_string_name
111
+ mockery = Mockery.new
112
+ mock = mockery.named_mock('named_mock')
113
+ assert_equal "#<Mock:named_mock>", mock.inspect
114
+ end
115
+
116
+ def test_should_display_name_for_inspect_if_mock_has_symbol_name
117
+ mockery = Mockery.new
118
+ mock = mockery.named_mock(:named_mock)
119
+ assert_equal "#<Mock:named_mock>", mock.inspect
120
+ end
121
+
122
+ def test_should_display_impersonated_object_for_mocha_inspect
123
+ mockery = Mockery.new
124
+ instance = Object.new
125
+ mock = mockery.mock_impersonating(instance)
126
+ assert_equal "#{instance.mocha_inspect}", mock.mocha_inspect
127
+ end
128
+
129
+ def test_should_display_impersonated_object_for_inspect
130
+ mockery = Mockery.new
131
+ instance = Object.new
132
+ mock = mockery.mock_impersonating(instance)
133
+ assert_equal "#{instance.mocha_inspect}", mock.inspect
134
+ end
135
+
136
+ class FakeClass; end
137
+
138
+ def test_should_display_any_instance_prefix_followed_by_class_whose_instances_are_being_impersonated_for_mocha_inspect
139
+ mockery = Mockery.new
140
+ mock = mockery.mock_impersonating_any_instance_of(FakeClass)
141
+ assert_equal "#<AnyInstance:MockeryTest::FakeClass>", mock.mocha_inspect
142
+ end
143
+
144
+ def test_should_display_any_instance_prefix_followed_by_class_whose_instances_are_being_impersonated_for_inspect
145
+ mockery = Mockery.new
146
+ mock = mockery.mock_impersonating_any_instance_of(FakeClass)
147
+ assert_equal "#<AnyInstance:MockeryTest::FakeClass>", mock.inspect
148
+ end
149
+
150
+ def test_should_record_invocation
151
+ mock = 'a mock'
152
+ method = :call_me
153
+ args = [1, 2]
154
+ mockery = Mockery.new
155
+ mockery.invocation(mock, method, args)
156
+ assert_equal 1, mockery.invocations.size
157
+ invocation = mockery.invocations.first
158
+ assert_equal mock, invocation.mock
159
+ assert_equal method, invocation.method_name
160
+ assert_equal args, invocation.arguments
161
+ end
162
+
163
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bourne
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ version: "1.0"
10
+ platform: ruby
11
+ authors:
12
+ - Joe Ferris
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-06-08 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: mocha
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - "="
27
+ - !ruby/object:Gem::Version
28
+ hash: 43
29
+ segments:
30
+ - 0
31
+ - 9
32
+ - 8
33
+ version: 0.9.8
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :development
49
+ version_requirements: *id002
50
+ description: |-
51
+ Extends mocha to allow detailed tracking and querying of
52
+ stub and mock invocations. Allows test spies using the have_received rspec
53
+ matcher and assert_received for Test::Unit. Extracted from the
54
+ jferris-mocha fork.
55
+ email: jferris@thoughtbot.com
56
+ executables: []
57
+
58
+ extensions: []
59
+
60
+ extra_rdoc_files:
61
+ - README
62
+ - LICENSE
63
+ files:
64
+ - lib/bourne/api.rb
65
+ - lib/bourne/expectation.rb
66
+ - lib/bourne/invocation.rb
67
+ - lib/bourne/mock.rb
68
+ - lib/bourne/mockery.rb
69
+ - lib/bourne.rb
70
+ - test/acceptance/acceptance_test_helper.rb
71
+ - test/acceptance/mocha_example_test.rb
72
+ - test/acceptance/spy_test.rb
73
+ - test/acceptance/stubba_example_test.rb
74
+ - test/execution_point.rb
75
+ - test/matcher_helpers.rb
76
+ - test/method_definer.rb
77
+ - test/simple_counter.rb
78
+ - test/test_helper.rb
79
+ - test/test_runner.rb
80
+ - test/unit/assert_received_test.rb
81
+ - test/unit/expectation_test.rb
82
+ - test/unit/have_received_test.rb
83
+ - test/unit/invocation_test.rb
84
+ - test/unit/mock_test.rb
85
+ - test/unit/mockery_test.rb
86
+ - LICENSE
87
+ - Rakefile
88
+ - README
89
+ has_rdoc: true
90
+ homepage: http://github.com/thoughtbot/bourne
91
+ licenses: []
92
+
93
+ post_install_message:
94
+ rdoc_options:
95
+ - --title
96
+ - Bourne
97
+ - --main
98
+ - README
99
+ - --line-numbers
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 3
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ hash: 3
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ requirements: []
121
+
122
+ rubyforge_project:
123
+ rubygems_version: 1.3.7.pre.1
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: Adds test spies to mocha.
127
+ test_files: []
128
+