derickbailey-notamock 0.0.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,181 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'not_a_mock'
3
+
4
+ class BlockTest
5
+ attr_accessor :real_method_called
6
+
7
+ def initialize
8
+ @real_method_called = false
9
+ end
10
+
11
+ def block_method
12
+ @real_method_called = true
13
+ end
14
+
15
+ def method_that_yields_a_value
16
+ yield false if block_given?
17
+ end
18
+ end
19
+
20
+ module YieldingObject
21
+ def self.yield_test
22
+ obj = YieldedObject.new
23
+ yield obj if block_given?
24
+ end
25
+ end
26
+
27
+ class YieldedObject
28
+ def yielding_test(arg)
29
+ puts "#{arg}"
30
+ end
31
+ end
32
+
33
+ class YieldTest
34
+ def do_something
35
+ YieldingObject.yield_test do |obj|
36
+ obj.yielding_test "foo"
37
+ end
38
+ end
39
+ end
40
+
41
+ describe NotAMock::Stubber, "when stubbing a method that is called with a block" do
42
+ before :each do
43
+ @bt = BlockTest.new
44
+
45
+ @bt.stub_method(:block_method)
46
+
47
+ @block_executed = false
48
+ @bt.block_method(){ @block_executed = true }
49
+ end
50
+
51
+ after :each do
52
+ NotAMock::Stubber.instance.reset
53
+ end
54
+
55
+ it "should execute the block" do
56
+ @block_executed.should be_true
57
+ end
58
+
59
+ it "should not call the real method" do
60
+ @bt.real_method_called.should be_false
61
+ end
62
+
63
+ it "should track the method call" do
64
+ @bt.should have_received(:block_method)
65
+ end
66
+ end
67
+
68
+ describe NotAMock::Stubber, "when stubbing a method that yields two values" do
69
+ before :each do
70
+ @bt = BlockTest.new
71
+
72
+ p = proc { yield false if block_given?}
73
+ @output = @bt.stub_method(:method_that_yields_a_value, &p).yields(true, 2)
74
+
75
+ @bt.method_that_yields_a_value(){ |b, i|
76
+ @yielded_bool = b
77
+ @yielded_int = i
78
+ }
79
+ end
80
+
81
+ after :each do
82
+ NotAMock::Stubber.instance.reset
83
+ end
84
+
85
+ it "should yield the first value" do
86
+ @yielded_bool.should be_true
87
+ end
88
+
89
+ it "should yield the second value" do
90
+ @yielded_int.should == 2
91
+ end
92
+
93
+ it "should track the method call" do
94
+ @bt.should have_received(:method_that_yields_a_value)
95
+ end
96
+ end
97
+
98
+ describe NotAMock::Stubber, "when stubbing a method on an object that is yielded to a block" do
99
+ before :each do
100
+ @stubyielded = YieldedObject.new
101
+ @stubyielded.stub_method(:yielding_test)
102
+
103
+ YieldingObject.stub_method(:yield_test).yields(@stubyielded)
104
+
105
+ @yieldtest = YieldTest.new
106
+ @yieldtest.do_something
107
+ end
108
+
109
+ after :each do
110
+ NotAMock::Stubber.instance.reset
111
+ end
112
+
113
+ it "should track the method call on the yielded object" do
114
+ @stubyielded.should have_received(:yielding_test)
115
+ end
116
+
117
+ it "should track the method call on the yielding object" do
118
+ YieldingObject.should have_received(:yield_test)
119
+ end
120
+ end
121
+
122
+ describe NotAMock::Stubber, "when stubbing a method and providing a block in the yields call" do
123
+ before :each do
124
+ @bt = BlockTest.new
125
+
126
+ @block_was_called = false
127
+ @output = @bt.stub_method(:method_that_yields_a_value).yields(true){
128
+ @block_was_called = true
129
+ }
130
+
131
+ @bt.method_that_yields_a_value()
132
+ end
133
+
134
+ after :each do
135
+ NotAMock::Stubber.instance.reset
136
+ end
137
+
138
+ it "should execute the block provided to the yield, as the stub method block" do
139
+ @block_was_called.should be_true
140
+ end
141
+ end
142
+
143
+ describe NotAMock::Stubber, "when stubbing a method that yields nil" do
144
+ before :each do
145
+ @bt = BlockTest.new
146
+ @output = @bt.stub_method(:method_that_yields_a_value).yields(nil)
147
+
148
+ @yielded_value = "not nil"
149
+ @bt.method_that_yields_a_value(){ |v|
150
+ @yielded_value = v
151
+ }
152
+ end
153
+
154
+ after :each do
155
+ NotAMock::Stubber.instance.reset
156
+ end
157
+
158
+ it "should yield nil" do
159
+ @yielded_value.should be_nil
160
+ end
161
+ end
162
+
163
+ describe NotAMock::Stubber, "when stubbing a method and yielding with no values" do
164
+ before :each do
165
+ @bt = BlockTest.new
166
+ @output = @bt.stub_method(:method_that_yields_a_value).yields
167
+
168
+ @yielded = false
169
+ @bt.method_that_yields_a_value(){
170
+ @yielded = true
171
+ }
172
+ end
173
+
174
+ after :each do
175
+ NotAMock::Stubber.instance.reset
176
+ end
177
+
178
+ it "should yield" do
179
+ @yielded.should be_true
180
+ end
181
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: derickbailey-notamock
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Pete Yandell
8
+ - Derick Bailey
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-10-27 00:00:00 -05:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 1.2.9
25
+ version:
26
+ description: A cleaner and DRYer alternative to mocking and stubbing with RSpec, using Arrange-Act-Assert syntax
27
+ email:
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - README.rdoc
34
+ files:
35
+ - MIT-LICENSE
36
+ - README.rdoc
37
+ - Rakefile
38
+ - TODO
39
+ - VERSION
40
+ - lib/not_a_mock.rb
41
+ - lib/not_a_mock/active_record_extensions.rb
42
+ - lib/not_a_mock/argument_constraint_extensions.rb
43
+ - lib/not_a_mock/call_recorder.rb
44
+ - lib/not_a_mock/matchers.rb
45
+ - lib/not_a_mock/matchers/anything_matcher.rb
46
+ - lib/not_a_mock/matchers/args_matcher.rb
47
+ - lib/not_a_mock/matchers/call_matcher.rb
48
+ - lib/not_a_mock/matchers/method_matcher.rb
49
+ - lib/not_a_mock/matchers/result_matcher.rb
50
+ - lib/not_a_mock/matchers/times_matcher.rb
51
+ - lib/not_a_mock/object_extensions.rb
52
+ - lib/not_a_mock/rspec_mock_framework_adapter.rb
53
+ - lib/not_a_mock/stub.rb
54
+ - lib/not_a_mock/stubber.rb
55
+ - lib/not_a_mock/stubmethod.rb
56
+ - spec/call_recording_spec.rb
57
+ - spec/matchers_spec.rb
58
+ - spec/stub_active_record_spec.rb
59
+ - spec/stub_instance_spec.rb
60
+ - spec/stub_method_spec.rb
61
+ - spec/stub_method_with_block_spec.rb
62
+ has_rdoc: true
63
+ homepage: http://github.com/derickbailey/not_a_mock
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options:
68
+ - --charset=UTF-8
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ requirements: []
84
+
85
+ rubyforge_project:
86
+ rubygems_version: 1.3.5
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: A cleaner and DRYer alternative to mocking and stubbing with RSpec
90
+ test_files:
91
+ - spec/call_recording_spec.rb
92
+ - spec/matchers_spec.rb
93
+ - spec/stub_active_record_spec.rb
94
+ - spec/stub_instance_spec.rb
95
+ - spec/stub_method_spec.rb
96
+ - spec/stub_method_with_block_spec.rb