mockery 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,163 @@
1
+
2
+ #
3
+ # Name: RecordControlTest (tests/unit/mockery/record_control_test.rb)
4
+ #
5
+ # Description:
6
+ #
7
+ # Unit tests for the Mockery::RecordControl object, which
8
+ # enables recording to be paused during the 'try' block
9
+ #
10
+ #
11
+ # Copyright 2005 Gary Shea
12
+ #
13
+ # Licensed under the Apache License, Version 2.0 (the "License");
14
+ # you may not use this file except in compliance with the License.
15
+ # You may obtain a copy of the License at
16
+ #
17
+ # http://www.apache.org/licenses/LICENSE-2.0
18
+ #
19
+ # Unless required by applicable law or agreed to in writing, software
20
+ # distributed under the License is distributed on an "AS IS" BASIS,
21
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ # See the License for the specific language governing permissions and
23
+ # limitations under the License.
24
+ #
25
+
26
+ require 'test/unit'
27
+
28
+ require 'mockery/record_control'
29
+
30
+ class RecordControlTest < Test::Unit::TestCase
31
+
32
+ def test_initialize
33
+
34
+ mocks = [Object.new, Object.new]
35
+ rec_class = Class.new(Mockery::RecordControl)
36
+ rec_class.class_eval {
37
+ attr_reader :mocks
38
+ }
39
+
40
+ rec = rec_class.new(mocks)
41
+
42
+ assert_equal(Array, rec.mocks.class)
43
+ assert_equal(2, rec.mocks.size)
44
+ assert_equal(mocks[0], rec.mocks[0])
45
+ assert_equal(mocks[1], rec.mocks[1])
46
+
47
+ end
48
+
49
+ def test_pause
50
+
51
+ # the #pause method runs a block with
52
+ # record turned off. it first turns
53
+ # off recording in all objects, then
54
+ # runs the block, then turns recording
55
+ # back on in all objects. the mocks
56
+ # are assumed to have a __record_state(bool)
57
+ # method which is used to turn recording
58
+ # on and off
59
+
60
+ ctl_class = Class.new(Mockery::RecordControl)
61
+ ctl_class.class_eval {
62
+ attr_accessor :mocks,
63
+ :off,
64
+ :on
65
+ def stop
66
+ @off = true
67
+ end
68
+ def start
69
+ @on = true
70
+ end
71
+ }
72
+
73
+ # this 'mock' represents a mocked class in
74
+ # use inside a 'try' block.
75
+ mock_class = Class.new(Mockery::RecordControl)
76
+ mock_class.class_eval {
77
+ attr_accessor :state
78
+ def initialize
79
+ @state = []
80
+ end
81
+ def __record_state(state)
82
+ @state.unshift(state)
83
+ end
84
+ }
85
+
86
+ m1 = mock_class.new
87
+ m2 = mock_class.new
88
+ ctl = ctl_class.new([m1, m2])
89
+
90
+ ctl.pause {
91
+ assert_equal(true, ctl.off)
92
+ assert_equal(nil, ctl.on)
93
+ }
94
+ assert_equal(true, ctl.on)
95
+ end
96
+
97
+ def test_stop
98
+
99
+ # the #stop method turns
100
+ # off recording in all objects
101
+
102
+ ctl_class = Class.new(Mockery::RecordControl)
103
+ ctl_class.class_eval {
104
+ attr_accessor :mocks
105
+ }
106
+
107
+ # this 'mock' represents a mocked class in
108
+ # use inside a 'try' block.
109
+ mock_class = Class.new
110
+ mock_class.class_eval {
111
+ attr_accessor :state
112
+ def __record_state=(state)
113
+ @state = state
114
+ end
115
+ }
116
+
117
+ m1 = mock_class.new
118
+ m1.state = true
119
+ m2 = mock_class.new
120
+ m2.state = true
121
+
122
+ ctl = ctl_class.new([m1, m2])
123
+
124
+ ctl.stop
125
+
126
+ assert_equal(false, m1.state)
127
+ assert_equal(false, m2.state)
128
+ end
129
+
130
+ def test_start
131
+
132
+ # the #start method turns
133
+ # on recording in all objects
134
+
135
+ ctl_class = Class.new(Mockery::RecordControl)
136
+ ctl_class.class_eval {
137
+ attr_accessor :mocks
138
+ }
139
+
140
+ # this 'mock' represents a mocked class in
141
+ # use inside a 'try' block.
142
+ mock_class = Class.new
143
+ mock_class.class_eval {
144
+ attr_accessor :state
145
+ def __record_state=(state)
146
+ @state = state
147
+ end
148
+ }
149
+
150
+ m1 = mock_class.new
151
+ m1.state = false
152
+ m2 = mock_class.new
153
+ m2.state = false
154
+
155
+ ctl = ctl_class.new([m1, m2])
156
+
157
+ ctl.start
158
+
159
+ assert_equal(true, m1.state)
160
+ assert_equal(true, m2.state)
161
+ end
162
+
163
+ end
@@ -0,0 +1,67 @@
1
+
2
+ #
3
+ # Name: RecorderTest (tests/unit/mockery/recorder_test.rb)
4
+ #
5
+ # Description:
6
+ #
7
+ # Unit tests for the Mockery::Recorder object
8
+ #
9
+ #
10
+ # Copyright 2005 Gary Shea
11
+ #
12
+ # Licensed under the Apache License, Version 2.0 (the "License");
13
+ # you may not use this file except in compliance with the License.
14
+ # You may obtain a copy of the License at
15
+ #
16
+ # http://www.apache.org/licenses/LICENSE-2.0
17
+ #
18
+ # Unless required by applicable law or agreed to in writing, software
19
+ # distributed under the License is distributed on an "AS IS" BASIS,
20
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ # See the License for the specific language governing permissions and
22
+ # limitations under the License.
23
+ #
24
+
25
+ require 'test/unit'
26
+
27
+ require 'mockery/recorder'
28
+
29
+ class RecorderTest < Test::Unit::TestCase
30
+
31
+ def test_initialize
32
+
33
+ klass = Class.new
34
+ rec_class = Class.new(Mockery::Recorder)
35
+ rec_class.class_eval {
36
+ attr_reader :history,
37
+ :klass
38
+ }
39
+
40
+ rec = rec_class.new(klass)
41
+
42
+ assert_equal(Array, rec.history.class)
43
+ assert_equal(0, rec.history.size)
44
+
45
+ assert_equal(klass, rec.klass)
46
+ end
47
+
48
+ def test_record
49
+ rec_class = Class.new(Mockery::Recorder)
50
+ rec_class.class_eval {
51
+ attr_reader :history
52
+ }
53
+
54
+ rec = rec_class.new(Class.new)
55
+
56
+ call = rec.glorfl(*['a', 'b', 3])
57
+
58
+ assert_equal(1, rec.history.size)
59
+ assert_equal(Mockery::Call, rec.history[0].class)
60
+ assert_equal(:glorfl, rec.history[0].method_name)
61
+ assert_equal(['a', 'b', 3], rec.history[0].args)
62
+ assert_equal(rec, rec.history[0].caller)
63
+
64
+ assert_equal(rec.history[0], call)
65
+ end
66
+
67
+ end
@@ -0,0 +1,29 @@
1
+
2
+ $:.unshift('lib')
3
+ $: << 'tests/unit'
4
+
5
+ require 'test/unit'
6
+ require 'test/unit/ui/console/testrunner'
7
+
8
+ require 'mockery/call_test'
9
+ require 'mockery/controller_test'
10
+ require 'mockery/mock_test'
11
+ require 'mockery/mock_class_factory_test'
12
+ require 'mockery/record_control_test'
13
+ require 'mockery/recorder_test'
14
+
15
+ class Tests
16
+
17
+ def self.suite
18
+ suite = Test::Unit::TestSuite.new
19
+ suite << CallTest.suite
20
+ suite << ControllerTest.suite
21
+ suite << MockTest.suite
22
+ suite << MockClassFactoryTest.suite
23
+ suite << RecordControTest.suite
24
+ suite << RecorderTest.suite
25
+ return suite
26
+ end
27
+
28
+ end
29
+
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.10
3
+ specification_version: 1
4
+ name: mockery
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.4.1
7
+ date: 2005-08-17
8
+ summary: Dynamic mock objects
9
+ require_paths:
10
+ - lib
11
+ email: shea@gtsdesign.com
12
+ homepage: http://mockery.rubyforge.org
13
+ rubyforge_project: mockery
14
+ description: Mockery dynamically generates mock objects and verifies that they are used as expected.
15
+ autorequire: mockery/controller
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ -
22
+ - ">"
23
+ - !ruby/object:Gem::Version
24
+ version: 0.0.0
25
+ version:
26
+ platform: ruby
27
+ authors: []
28
+ files:
29
+ - lib/mockery
30
+ - lib/mockery/mock.rb
31
+ - lib/mockery/call.rb
32
+ - lib/mockery/controller.rb
33
+ - lib/mockery/recorder.rb
34
+ - lib/mockery/mock_class_factory.rb
35
+ - lib/mockery/record_control.rb
36
+ - tests/unit
37
+ - tests/acc
38
+ - tests/unit/mockery
39
+ - tests/unit/unit_tests.rb
40
+ - tests/unit/mockery/recorder_test.rb
41
+ - tests/unit/mockery/call_test.rb
42
+ - tests/unit/mockery/controller_test.rb
43
+ - tests/unit/mockery/mock_test.rb
44
+ - tests/unit/mockery/mock_class_factory_test.rb
45
+ - tests/unit/mockery/record_control_test.rb
46
+ - tests/acc/acc_tests.rb
47
+ - tests/acc/mockery
48
+ - tests/acc/mockery/mockery_test.rb
49
+ - Rakefile
50
+ test_files: []
51
+ rdoc_options: []
52
+ extra_rdoc_files: []
53
+ executables: []
54
+ extensions: []
55
+ requirements:
56
+ - none
57
+ dependencies: []