much-stub 0.1.1 → 0.1.6

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,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MuchStub
4
+ class Call
5
+ attr_reader :pargs, :kargs, :block
6
+
7
+ def initialize(*pargs, **kargs, &block)
8
+ @pargs = pargs.empty? ? nil : pargs
9
+ @kargs = kargs.empty? ? nil : kargs
10
+ @block = block
11
+ end
12
+
13
+ def args
14
+ @args ||= [*pargs, kargs].compact
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,124 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "much-stub/call"
4
+
5
+ module MuchStub
6
+ class CallSpy < ::BasicObject
7
+ METHOD_NAME_REPLACEMENTS = {
8
+ "!" => "_bang",
9
+ "?" => "_predicate"
10
+ }.freeze
11
+
12
+ def initialize(**return_values)
13
+ @call_spy_return_values = return_values.transform_keys{ |key| key.to_s }
14
+ @call_spy_method_calls = ::Hash.new { |hash, key| hash[key] = [] }
15
+ @call_spy_method_return_values =
16
+ ::Hash.new { |hash, key| hash[key] = call_spy_return_value_proc(key) }
17
+ end
18
+
19
+ def call_spy_tap
20
+ yield self
21
+ self
22
+ end
23
+
24
+ def ==(other)
25
+ self.equal?(other)
26
+ end
27
+
28
+ def ===(other)
29
+ self.equal?(other)
30
+ end
31
+
32
+ def eql?(other)
33
+ self.equal?(other)
34
+ end
35
+
36
+ def equal?(other)
37
+ self.__id__ == other.__id__
38
+ end
39
+
40
+ def hash
41
+ self.__id__
42
+ end
43
+
44
+ def respond_to?(*)
45
+ true
46
+ end
47
+
48
+ def inspect
49
+ "#<MuchStub::CallSpy:#{"0x0%x" % (self.__id__ << 1)}>"
50
+ end
51
+
52
+ private
53
+
54
+ def call_spy_method_return_value(method_name, much_stub_call)
55
+ @call_spy_method_return_values[method_name.to_s].call(much_stub_call)
56
+ end
57
+
58
+ def call_spy_return_value_proc(method_name)
59
+ value = @call_spy_return_values.fetch(method_name, ::Proc.new { self })
60
+ value.respond_to?(:call) ? value : ::Proc.new { value }
61
+ end
62
+
63
+ def call_spy_normalize_method_name(name)
64
+ METHOD_NAME_REPLACEMENTS.reduce(name.to_s) { |acc, (source, replacement)|
65
+ acc.gsub(source, replacement)
66
+ }
67
+ end
68
+
69
+ def call_spy_define_spied_method(name)
70
+ method_name = call_spy_normalize_method_name(name)
71
+ call_spy_define_metaclass_method(name) do |*args, &block|
72
+ call = ::MuchStub::Call.new(*args, &block)
73
+ @call_spy_method_calls[method_name] << call
74
+ call_spy_method_return_value(name, call)
75
+ end
76
+ end
77
+
78
+ def call_spy_define_query_method(query_method_match)
79
+ spied_method_name = query_method_match[1]
80
+ query_method_suffix = query_method_match[2]
81
+ method_name = call_spy_normalize_method_name(spied_method_name)
82
+ call_spy_define_metaclass_method("#{method_name}#{query_method_suffix}") do
83
+ yield(method_name) if ::Kernel.block_given?
84
+ end
85
+ end
86
+
87
+ def call_spy_define_metaclass_method(name, &block)
88
+ metaclass = class << self; self; end
89
+ metaclass.define_method(name, &block)
90
+ end
91
+
92
+ def method_missing(name, *args, &block)
93
+ if (match = name.match(/(\w+)(_calls)\z/))
94
+ call_spy_define_query_method(match) do |method_name|
95
+ @call_spy_method_calls[method_name]
96
+ end
97
+ self.__send__(name, *args, &block)
98
+ elsif (match = name.match(/(\w+)(_last_called_with)\z/))
99
+ call_spy_define_query_method(match) do |method_name|
100
+ self.__send__("#{method_name}_calls").last
101
+ end
102
+ self.__send__(name, *args, &block)
103
+ elsif (match = name.match(/(\w+)(_called_with)\z/))
104
+ call_spy_define_query_method(match) do |method_name|
105
+ self.__send__("#{method_name}_last_called_with")
106
+ end
107
+ self.__send__(name, *args, &block)
108
+ elsif (match = name.match(/(\w+)(_call_count)\z/))
109
+ call_spy_define_query_method(match) do |method_name|
110
+ self.__send__("#{method_name}_calls").size
111
+ end
112
+ self.__send__(name, *args, &block)
113
+ elsif (match = name.match(/(\w+)(_called\?)\z/))
114
+ call_spy_define_query_method(match) do |method_name|
115
+ self.__send__("#{method_name}_call_count") > 0
116
+ end
117
+ self.__send__(name, *args, &block)
118
+ else
119
+ call_spy_define_spied_method(name)
120
+ self.__send__(name, *args, &block)
121
+ end
122
+ end
123
+ end
124
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MuchStub
2
- VERSION = "0.1.1"
4
+ VERSION = "0.1.6"
3
5
  end
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
2
+ lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require "much-stub/version"
5
5
 
@@ -11,13 +11,14 @@ Gem::Specification.new do |gem|
11
11
  gem.summary = "Stubbing API for replacing method calls on objects in test runs."
12
12
  gem.description = "Stubbing API for replacing method calls on objects in test runs."
13
13
  gem.homepage = "https://github.com/redding/much-stub"
14
- gem.license = 'MIT'
14
+ gem.license = "MIT"
15
15
 
16
16
  gem.files = `git ls-files`.split($/)
17
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
20
 
21
- gem.add_development_dependency("assert", ["~> 2.17.0"])
21
+ gem.required_ruby_version = "~> 2.5"
22
22
 
23
+ gem.add_development_dependency("assert", ["~> 2.19.0"])
23
24
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # this file is automatically required when you run `assert`
2
4
  # put any test helpers here
3
5
 
@@ -5,9 +7,9 @@
5
7
  $LOAD_PATH.unshift(File.expand_path("../..", __FILE__))
6
8
 
7
9
  # require pry for debugging (`binding.pry`)
8
- require 'pry'
10
+ require "pry"
9
11
 
10
- require 'test/support/factory'
12
+ require "test/support/factory"
11
13
 
12
14
  # 1.8.7 backfills
13
15
 
@@ -19,7 +21,7 @@ if !(a = Array.new).respond_to?(:sample) && a.respond_to?(:choice)
19
21
  end
20
22
 
21
23
  # unstub all test stubs automatically for Assert test suite
22
- require 'assert'
24
+ require "assert"
23
25
  class Assert::Context
24
26
  teardown{ MuchStub.unstub! }
25
27
  end
@@ -1,6 +1,7 @@
1
- require 'assert/factory'
1
+ # frozen_string_literal: true
2
+
3
+ require "assert/factory"
2
4
 
3
5
  module Factory
4
6
  extend Assert::Factory
5
-
6
7
  end
@@ -1,59 +1,59 @@
1
- require 'assert'
2
- require 'much-stub'
1
+ # frozen_string_literal: true
3
2
 
4
- module MuchStub
3
+ require "assert"
4
+ require "much-stub"
5
5
 
6
+ module MuchStub
6
7
  class SystemTests < Assert::Context
7
8
  desc "MuchStub"
8
-
9
9
  end
10
10
 
11
11
  class InstanceTests < SystemTests
12
12
  desc "for instance methods"
13
13
  setup do
14
14
  @instance = TestClass.new
15
- MuchStub.stub(@instance, :noargs){ 'default' }
16
- MuchStub.stub(@instance, :noargs).with{ 'none' }
15
+ MuchStub.stub(@instance, :noargs){ "default" }
16
+ MuchStub.stub(@instance, :noargs).with{ "none" }
17
17
 
18
- MuchStub.stub(@instance, :withargs){ 'default' }
19
- MuchStub.stub(@instance, :withargs).with(1){ 'one' }
18
+ MuchStub.stub(@instance, :withargs){ "default" }
19
+ MuchStub.stub(@instance, :withargs).with(1){ "one" }
20
20
 
21
- MuchStub.stub(@instance, :anyargs){ 'default' }
22
- MuchStub.stub(@instance, :anyargs).with(1, 2){ 'one-two' }
21
+ MuchStub.stub(@instance, :anyargs){ "default" }
22
+ MuchStub.stub(@instance, :anyargs).with(1, 2){ "one-two" }
23
23
 
24
- MuchStub.stub(@instance, :minargs){ 'default' }
25
- MuchStub.stub(@instance, :minargs).with(1, 2){ 'one-two' }
26
- MuchStub.stub(@instance, :minargs).with(1, 2, 3){ 'one-two-three' }
24
+ MuchStub.stub(@instance, :minargs){ "default" }
25
+ MuchStub.stub(@instance, :minargs).with(1, 2){ "one-two" }
26
+ MuchStub.stub(@instance, :minargs).with(1, 2, 3){ "one-two-three" }
27
27
 
28
- MuchStub.stub(@instance, :withblock){ 'default' }
28
+ MuchStub.stub(@instance, :withblock){ "default" }
29
29
  end
30
30
  subject{ @instance }
31
31
 
32
32
  should "allow stubbing a method that doesn't take args" do
33
- assert_equal 'none', subject.noargs
33
+ assert_equal "none", subject.noargs
34
34
  end
35
35
 
36
36
  should "allow stubbing a method that takes args" do
37
- assert_equal 'one', subject.withargs(1)
38
- assert_equal 'default', subject.withargs(2)
37
+ assert_equal "one", subject.withargs(1)
38
+ assert_equal "default", subject.withargs(2)
39
39
  end
40
40
 
41
41
  should "allow stubbing a method that takes any args" do
42
- assert_equal 'default', subject.anyargs
43
- assert_equal 'default', subject.anyargs(1)
44
- assert_equal 'one-two', subject.anyargs(1, 2)
42
+ assert_equal "default", subject.anyargs
43
+ assert_equal "default", subject.anyargs(1)
44
+ assert_equal "one-two", subject.anyargs(1, 2)
45
45
  end
46
46
 
47
47
  should "allow stubbing a method that takes a minimum number of args" do
48
- assert_equal 'one-two', subject.minargs(1, 2)
49
- assert_equal 'one-two-three', subject.minargs(1, 2, 3)
50
- assert_equal 'default', subject.minargs(1, 2, 4)
51
- assert_equal 'default', subject.minargs(1, 2, 3, 4)
48
+ assert_equal "one-two", subject.minargs(1, 2)
49
+ assert_equal "one-two-three", subject.minargs(1, 2, 3)
50
+ assert_equal "default", subject.minargs(1, 2, 4)
51
+ assert_equal "default", subject.minargs(1, 2, 3, 4)
52
52
  end
53
53
 
54
54
  should "allow stubbing a method that takes a block" do
55
- assert_equal 'default', subject.withblock
56
- assert_equal 'default', subject.withblock{ 'my-block' }
55
+ assert_equal "default", subject.withblock
56
+ assert_equal "default", subject.withblock{ "my-block" }
57
57
  end
58
58
 
59
59
  should "not allow stubbing methods with invalid arity" do
@@ -79,55 +79,54 @@ module MuchStub
79
79
 
80
80
  assert_raises{ subject.withblock(1) }
81
81
  end
82
-
83
82
  end
84
83
 
85
84
  class ClassTests < SystemTests
86
85
  desc "for singleton methods on a class"
87
86
  setup do
88
87
  @class = TestClass
89
- MuchStub.stub(@class, :noargs){ 'default' }
90
- MuchStub.stub(@class, :noargs).with{ 'none' }
88
+ MuchStub.stub(@class, :noargs){ "default" }
89
+ MuchStub.stub(@class, :noargs).with{ "none" }
91
90
 
92
- MuchStub.stub(@class, :withargs){ 'default' }
93
- MuchStub.stub(@class, :withargs).with(1){ 'one' }
91
+ MuchStub.stub(@class, :withargs){ "default" }
92
+ MuchStub.stub(@class, :withargs).with(1){ "one" }
94
93
 
95
- MuchStub.stub(@class, :anyargs){ 'default' }
96
- MuchStub.stub(@class, :anyargs).with(1, 2){ 'one-two' }
94
+ MuchStub.stub(@class, :anyargs){ "default" }
95
+ MuchStub.stub(@class, :anyargs).with(1, 2){ "one-two" }
97
96
 
98
- MuchStub.stub(@class, :minargs){ 'default' }
99
- MuchStub.stub(@class, :minargs).with(1, 2){ 'one-two' }
100
- MuchStub.stub(@class, :minargs).with(1, 2, 3){ 'one-two-three' }
97
+ MuchStub.stub(@class, :minargs){ "default" }
98
+ MuchStub.stub(@class, :minargs).with(1, 2){ "one-two" }
99
+ MuchStub.stub(@class, :minargs).with(1, 2, 3){ "one-two-three" }
101
100
 
102
- MuchStub.stub(@class, :withblock){ 'default' }
101
+ MuchStub.stub(@class, :withblock){ "default" }
103
102
  end
104
103
  subject{ @class }
105
104
 
106
105
  should "allow stubbing a method that doesn't take args" do
107
- assert_equal 'none', subject.noargs
106
+ assert_equal "none", subject.noargs
108
107
  end
109
108
 
110
109
  should "allow stubbing a method that takes args" do
111
- assert_equal 'one', subject.withargs(1)
112
- assert_equal 'default', subject.withargs(2)
110
+ assert_equal "one", subject.withargs(1)
111
+ assert_equal "default", subject.withargs(2)
113
112
  end
114
113
 
115
114
  should "allow stubbing a method that takes any args" do
116
- assert_equal 'default', subject.anyargs
117
- assert_equal 'default', subject.anyargs(1)
118
- assert_equal 'one-two', subject.anyargs(1, 2)
115
+ assert_equal "default", subject.anyargs
116
+ assert_equal "default", subject.anyargs(1)
117
+ assert_equal "one-two", subject.anyargs(1, 2)
119
118
  end
120
119
 
121
120
  should "allow stubbing a method that takes a minimum number of args" do
122
- assert_equal 'one-two', subject.minargs(1, 2)
123
- assert_equal 'one-two-three', subject.minargs(1, 2, 3)
124
- assert_equal 'default', subject.minargs(1, 2, 4)
125
- assert_equal 'default', subject.minargs(1, 2, 3, 4)
121
+ assert_equal "one-two", subject.minargs(1, 2)
122
+ assert_equal "one-two-three", subject.minargs(1, 2, 3)
123
+ assert_equal "default", subject.minargs(1, 2, 4)
124
+ assert_equal "default", subject.minargs(1, 2, 3, 4)
126
125
  end
127
126
 
128
127
  should "allow stubbing a method that takes a block" do
129
- assert_equal 'default', subject.withblock
130
- assert_equal 'default', subject.withblock{ 'my-block' }
128
+ assert_equal "default", subject.withblock
129
+ assert_equal "default", subject.withblock{ "my-block" }
131
130
  end
132
131
 
133
132
  should "not allow stubbing methods with invalid arity" do
@@ -153,55 +152,54 @@ module MuchStub
153
152
 
154
153
  assert_raises{ subject.withblock(1) }
155
154
  end
156
-
157
155
  end
158
156
 
159
157
  class ModuleTests < SystemTests
160
158
  desc "for singleton methods on a module"
161
159
  setup do
162
160
  @module = TestModule
163
- MuchStub.stub(@module, :noargs){ 'default' }
164
- MuchStub.stub(@module, :noargs).with{ 'none' }
161
+ MuchStub.stub(@module, :noargs){ "default" }
162
+ MuchStub.stub(@module, :noargs).with{ "none" }
165
163
 
166
- MuchStub.stub(@module, :withargs){ 'default' }
167
- MuchStub.stub(@module, :withargs).with(1){ 'one' }
164
+ MuchStub.stub(@module, :withargs){ "default" }
165
+ MuchStub.stub(@module, :withargs).with(1){ "one" }
168
166
 
169
- MuchStub.stub(@module, :anyargs){ 'default' }
170
- MuchStub.stub(@module, :anyargs).with(1, 2){ 'one-two' }
167
+ MuchStub.stub(@module, :anyargs){ "default" }
168
+ MuchStub.stub(@module, :anyargs).with(1, 2){ "one-two" }
171
169
 
172
- MuchStub.stub(@module, :minargs){ 'default' }
173
- MuchStub.stub(@module, :minargs).with(1, 2){ 'one-two' }
174
- MuchStub.stub(@module, :minargs).with(1, 2, 3){ 'one-two-three' }
170
+ MuchStub.stub(@module, :minargs){ "default" }
171
+ MuchStub.stub(@module, :minargs).with(1, 2){ "one-two" }
172
+ MuchStub.stub(@module, :minargs).with(1, 2, 3){ "one-two-three" }
175
173
 
176
- MuchStub.stub(@module, :withblock){ 'default' }
174
+ MuchStub.stub(@module, :withblock){ "default" }
177
175
  end
178
176
  subject{ @module }
179
177
 
180
178
  should "allow stubbing a method that doesn't take args" do
181
- assert_equal 'none', subject.noargs
179
+ assert_equal "none", subject.noargs
182
180
  end
183
181
 
184
182
  should "allow stubbing a method that takes args" do
185
- assert_equal 'one', subject.withargs(1)
186
- assert_equal 'default', subject.withargs(2)
183
+ assert_equal "one", subject.withargs(1)
184
+ assert_equal "default", subject.withargs(2)
187
185
  end
188
186
 
189
187
  should "allow stubbing a method that takes any args" do
190
- assert_equal 'default', subject.anyargs
191
- assert_equal 'default', subject.anyargs(1)
192
- assert_equal 'one-two', subject.anyargs(1, 2)
188
+ assert_equal "default", subject.anyargs
189
+ assert_equal "default", subject.anyargs(1)
190
+ assert_equal "one-two", subject.anyargs(1, 2)
193
191
  end
194
192
 
195
193
  should "allow stubbing a method that takes a minimum number of args" do
196
- assert_equal 'one-two', subject.minargs(1, 2)
197
- assert_equal 'one-two-three', subject.minargs(1, 2, 3)
198
- assert_equal 'default', subject.minargs(1, 2, 4)
199
- assert_equal 'default', subject.minargs(1, 2, 3, 4)
194
+ assert_equal "one-two", subject.minargs(1, 2)
195
+ assert_equal "one-two-three", subject.minargs(1, 2, 3)
196
+ assert_equal "default", subject.minargs(1, 2, 4)
197
+ assert_equal "default", subject.minargs(1, 2, 3, 4)
200
198
  end
201
199
 
202
200
  should "allow stubbing a method that takes a block" do
203
- assert_equal 'default', subject.withblock
204
- assert_equal 'default', subject.withblock{ 'my-block' }
201
+ assert_equal "default", subject.withblock
202
+ assert_equal "default", subject.withblock{ "my-block" }
205
203
  end
206
204
 
207
205
  should "not allow stubbing methods with invalid arity" do
@@ -227,55 +225,54 @@ module MuchStub
227
225
 
228
226
  assert_raises{ subject.withblock(1) }
229
227
  end
230
-
231
228
  end
232
229
 
233
230
  class ExtendedTests < SystemTests
234
231
  desc "for extended methods"
235
232
  setup do
236
233
  @class = Class.new{ extend TestMixin }
237
- MuchStub.stub(@class, :noargs){ 'default' }
238
- MuchStub.stub(@class, :noargs).with{ 'none' }
234
+ MuchStub.stub(@class, :noargs){ "default" }
235
+ MuchStub.stub(@class, :noargs).with{ "none" }
239
236
 
240
- MuchStub.stub(@class, :withargs){ 'default' }
241
- MuchStub.stub(@class, :withargs).with(1){ 'one' }
237
+ MuchStub.stub(@class, :withargs){ "default" }
238
+ MuchStub.stub(@class, :withargs).with(1){ "one" }
242
239
 
243
- MuchStub.stub(@class, :anyargs){ 'default' }
244
- MuchStub.stub(@class, :anyargs).with(1, 2){ 'one-two' }
240
+ MuchStub.stub(@class, :anyargs){ "default" }
241
+ MuchStub.stub(@class, :anyargs).with(1, 2){ "one-two" }
245
242
 
246
- MuchStub.stub(@class, :minargs){ 'default' }
247
- MuchStub.stub(@class, :minargs).with(1, 2){ 'one-two' }
248
- MuchStub.stub(@class, :minargs).with(1, 2, 3){ 'one-two-three' }
243
+ MuchStub.stub(@class, :minargs){ "default" }
244
+ MuchStub.stub(@class, :minargs).with(1, 2){ "one-two" }
245
+ MuchStub.stub(@class, :minargs).with(1, 2, 3){ "one-two-three" }
249
246
 
250
- MuchStub.stub(@class, :withblock){ 'default' }
247
+ MuchStub.stub(@class, :withblock){ "default" }
251
248
  end
252
249
  subject{ @class }
253
250
 
254
251
  should "allow stubbing a method that doesn't take args" do
255
- assert_equal 'none', subject.noargs
252
+ assert_equal "none", subject.noargs
256
253
  end
257
254
 
258
255
  should "allow stubbing a method that takes args" do
259
- assert_equal 'one', subject.withargs(1)
260
- assert_equal 'default', subject.withargs(2)
256
+ assert_equal "one", subject.withargs(1)
257
+ assert_equal "default", subject.withargs(2)
261
258
  end
262
259
 
263
260
  should "allow stubbing a method that takes any args" do
264
- assert_equal 'default', subject.anyargs
265
- assert_equal 'default', subject.anyargs(1)
266
- assert_equal 'one-two', subject.anyargs(1, 2)
261
+ assert_equal "default", subject.anyargs
262
+ assert_equal "default", subject.anyargs(1)
263
+ assert_equal "one-two", subject.anyargs(1, 2)
267
264
  end
268
265
 
269
266
  should "allow stubbing a method that takes a minimum number of args" do
270
- assert_equal 'one-two', subject.minargs(1, 2)
271
- assert_equal 'one-two-three', subject.minargs(1, 2, 3)
272
- assert_equal 'default', subject.minargs(1, 2, 4)
273
- assert_equal 'default', subject.minargs(1, 2, 3, 4)
267
+ assert_equal "one-two", subject.minargs(1, 2)
268
+ assert_equal "one-two-three", subject.minargs(1, 2, 3)
269
+ assert_equal "default", subject.minargs(1, 2, 4)
270
+ assert_equal "default", subject.minargs(1, 2, 3, 4)
274
271
  end
275
272
 
276
273
  should "allow stubbing a method that takes a block" do
277
- assert_equal 'default', subject.withblock
278
- assert_equal 'default', subject.withblock{ 'my-block' }
274
+ assert_equal "default", subject.withblock
275
+ assert_equal "default", subject.withblock{ "my-block" }
279
276
  end
280
277
 
281
278
  should "not allow stubbing methods with invalid arity" do
@@ -301,7 +298,6 @@ module MuchStub
301
298
 
302
299
  assert_raises{ subject.withblock(1) }
303
300
  end
304
-
305
301
  end
306
302
 
307
303
  class IncludedTests < SystemTests
@@ -309,48 +305,48 @@ module MuchStub
309
305
  setup do
310
306
  @class = Class.new{ include TestMixin }
311
307
  @instance = @class.new
312
- MuchStub.stub(@instance, :noargs){ 'default' }
313
- MuchStub.stub(@instance, :noargs).with{ 'none' }
308
+ MuchStub.stub(@instance, :noargs){ "default" }
309
+ MuchStub.stub(@instance, :noargs).with{ "none" }
314
310
 
315
- MuchStub.stub(@instance, :withargs){ 'default' }
316
- MuchStub.stub(@instance, :withargs).with(1){ 'one' }
311
+ MuchStub.stub(@instance, :withargs){ "default" }
312
+ MuchStub.stub(@instance, :withargs).with(1){ "one" }
317
313
 
318
- MuchStub.stub(@instance, :anyargs){ 'default' }
319
- MuchStub.stub(@instance, :anyargs).with(1, 2){ 'one-two' }
314
+ MuchStub.stub(@instance, :anyargs){ "default" }
315
+ MuchStub.stub(@instance, :anyargs).with(1, 2){ "one-two" }
320
316
 
321
- MuchStub.stub(@instance, :minargs){ 'default' }
322
- MuchStub.stub(@instance, :minargs).with(1, 2){ 'one-two' }
323
- MuchStub.stub(@instance, :minargs).with(1, 2, 3){ 'one-two-three' }
317
+ MuchStub.stub(@instance, :minargs){ "default" }
318
+ MuchStub.stub(@instance, :minargs).with(1, 2){ "one-two" }
319
+ MuchStub.stub(@instance, :minargs).with(1, 2, 3){ "one-two-three" }
324
320
 
325
- MuchStub.stub(@instance, :withblock){ 'default' }
321
+ MuchStub.stub(@instance, :withblock){ "default" }
326
322
  end
327
323
  subject{ @instance }
328
324
 
329
325
  should "allow stubbing a method that doesn't take args" do
330
- assert_equal 'none', subject.noargs
326
+ assert_equal "none", subject.noargs
331
327
  end
332
328
 
333
329
  should "allow stubbing a method that takes args" do
334
- assert_equal 'one', subject.withargs(1)
335
- assert_equal 'default', subject.withargs(2)
330
+ assert_equal "one", subject.withargs(1)
331
+ assert_equal "default", subject.withargs(2)
336
332
  end
337
333
 
338
334
  should "allow stubbing a method that takes any args" do
339
- assert_equal 'default', subject.anyargs
340
- assert_equal 'default', subject.anyargs(1)
341
- assert_equal 'one-two', subject.anyargs(1, 2)
335
+ assert_equal "default", subject.anyargs
336
+ assert_equal "default", subject.anyargs(1)
337
+ assert_equal "one-two", subject.anyargs(1, 2)
342
338
  end
343
339
 
344
340
  should "allow stubbing a method that takes a minimum number of args" do
345
- assert_equal 'one-two', subject.minargs(1, 2)
346
- assert_equal 'one-two-three', subject.minargs(1, 2, 3)
347
- assert_equal 'default', subject.minargs(1, 2, 4)
348
- assert_equal 'default', subject.minargs(1, 2, 3, 4)
341
+ assert_equal "one-two", subject.minargs(1, 2)
342
+ assert_equal "one-two-three", subject.minargs(1, 2, 3)
343
+ assert_equal "default", subject.minargs(1, 2, 4)
344
+ assert_equal "default", subject.minargs(1, 2, 3, 4)
349
345
  end
350
346
 
351
347
  should "allow stubbing a method that takes a block" do
352
- assert_equal 'default', subject.withblock
353
- assert_equal 'default', subject.withblock{ 'my-block' }
348
+ assert_equal "default", subject.withblock
349
+ assert_equal "default", subject.withblock{ "my-block" }
354
350
  end
355
351
 
356
352
  should "not allow stubbing methods with invalid arity" do
@@ -376,55 +372,54 @@ module MuchStub
376
372
 
377
373
  assert_raises{ subject.withblock(1) }
378
374
  end
379
-
380
375
  end
381
376
 
382
377
  class InheritedClassTests < SystemTests
383
378
  desc "for an inherited class method"
384
379
  setup do
385
380
  @class = Class.new(TestClass)
386
- MuchStub.stub(@class, :noargs){ 'default' }
387
- MuchStub.stub(@class, :noargs).with{ 'none' }
381
+ MuchStub.stub(@class, :noargs){ "default" }
382
+ MuchStub.stub(@class, :noargs).with{ "none" }
388
383
 
389
- MuchStub.stub(@class, :withargs){ 'default' }
390
- MuchStub.stub(@class, :withargs).with(1){ 'one' }
384
+ MuchStub.stub(@class, :withargs){ "default" }
385
+ MuchStub.stub(@class, :withargs).with(1){ "one" }
391
386
 
392
- MuchStub.stub(@class, :anyargs){ 'default' }
393
- MuchStub.stub(@class, :anyargs).with(1, 2){ 'one-two' }
387
+ MuchStub.stub(@class, :anyargs){ "default" }
388
+ MuchStub.stub(@class, :anyargs).with(1, 2){ "one-two" }
394
389
 
395
- MuchStub.stub(@class, :minargs){ 'default' }
396
- MuchStub.stub(@class, :minargs).with(1, 2){ 'one-two' }
397
- MuchStub.stub(@class, :minargs).with(1, 2, 3){ 'one-two-three' }
390
+ MuchStub.stub(@class, :minargs){ "default" }
391
+ MuchStub.stub(@class, :minargs).with(1, 2){ "one-two" }
392
+ MuchStub.stub(@class, :minargs).with(1, 2, 3){ "one-two-three" }
398
393
 
399
- MuchStub.stub(@class, :withblock){ 'default' }
394
+ MuchStub.stub(@class, :withblock){ "default" }
400
395
  end
401
396
  subject{ @class }
402
397
 
403
398
  should "allow stubbing a method that doesn't take args" do
404
- assert_equal 'none', subject.noargs
399
+ assert_equal "none", subject.noargs
405
400
  end
406
401
 
407
402
  should "allow stubbing a method that takes args" do
408
- assert_equal 'one', subject.withargs(1)
409
- assert_equal 'default', subject.withargs(2)
403
+ assert_equal "one", subject.withargs(1)
404
+ assert_equal "default", subject.withargs(2)
410
405
  end
411
406
 
412
407
  should "allow stubbing a method that takes any args" do
413
- assert_equal 'default', subject.anyargs
414
- assert_equal 'default', subject.anyargs(1)
415
- assert_equal 'one-two', subject.anyargs(1, 2)
408
+ assert_equal "default", subject.anyargs
409
+ assert_equal "default", subject.anyargs(1)
410
+ assert_equal "one-two", subject.anyargs(1, 2)
416
411
  end
417
412
 
418
413
  should "allow stubbing a method that takes a minimum number of args" do
419
- assert_equal 'one-two', subject.minargs(1, 2)
420
- assert_equal 'one-two-three', subject.minargs(1, 2, 3)
421
- assert_equal 'default', subject.minargs(1, 2, 4)
422
- assert_equal 'default', subject.minargs(1, 2, 3, 4)
414
+ assert_equal "one-two", subject.minargs(1, 2)
415
+ assert_equal "one-two-three", subject.minargs(1, 2, 3)
416
+ assert_equal "default", subject.minargs(1, 2, 4)
417
+ assert_equal "default", subject.minargs(1, 2, 3, 4)
423
418
  end
424
419
 
425
420
  should "allow stubbing a method that takes a block" do
426
- assert_equal 'default', subject.withblock
427
- assert_equal 'default', subject.withblock{ 'my-block' }
421
+ assert_equal "default", subject.withblock
422
+ assert_equal "default", subject.withblock{ "my-block" }
428
423
  end
429
424
 
430
425
  should "not allow stubbing methods with invalid arity" do
@@ -450,7 +445,6 @@ module MuchStub
450
445
 
451
446
  assert_raises{ subject.withblock(1) }
452
447
  end
453
-
454
448
  end
455
449
 
456
450
  class InheritedInstanceTests < SystemTests
@@ -458,48 +452,48 @@ module MuchStub
458
452
  setup do
459
453
  @class = Class.new(TestClass)
460
454
  @instance = @class.new
461
- MuchStub.stub(@instance, :noargs){ 'default' }
462
- MuchStub.stub(@instance, :noargs).with{ 'none' }
455
+ MuchStub.stub(@instance, :noargs){ "default" }
456
+ MuchStub.stub(@instance, :noargs).with{ "none" }
463
457
 
464
- MuchStub.stub(@instance, :withargs){ 'default' }
465
- MuchStub.stub(@instance, :withargs).with(1){ 'one' }
458
+ MuchStub.stub(@instance, :withargs){ "default" }
459
+ MuchStub.stub(@instance, :withargs).with(1){ "one" }
466
460
 
467
- MuchStub.stub(@instance, :anyargs){ 'default' }
468
- MuchStub.stub(@instance, :anyargs).with(1, 2){ 'one-two' }
461
+ MuchStub.stub(@instance, :anyargs){ "default" }
462
+ MuchStub.stub(@instance, :anyargs).with(1, 2){ "one-two" }
469
463
 
470
- MuchStub.stub(@instance, :minargs){ 'default' }
471
- MuchStub.stub(@instance, :minargs).with(1, 2){ 'one-two' }
472
- MuchStub.stub(@instance, :minargs).with(1, 2, 3){ 'one-two-three' }
464
+ MuchStub.stub(@instance, :minargs){ "default" }
465
+ MuchStub.stub(@instance, :minargs).with(1, 2){ "one-two" }
466
+ MuchStub.stub(@instance, :minargs).with(1, 2, 3){ "one-two-three" }
473
467
 
474
- MuchStub.stub(@instance, :withblock){ 'default' }
468
+ MuchStub.stub(@instance, :withblock){ "default" }
475
469
  end
476
470
  subject{ @instance }
477
471
 
478
472
  should "allow stubbing a method that doesn't take args" do
479
- assert_equal 'none', subject.noargs
473
+ assert_equal "none", subject.noargs
480
474
  end
481
475
 
482
476
  should "allow stubbing a method that takes args" do
483
- assert_equal 'one', subject.withargs(1)
484
- assert_equal 'default', subject.withargs(2)
477
+ assert_equal "one", subject.withargs(1)
478
+ assert_equal "default", subject.withargs(2)
485
479
  end
486
480
 
487
481
  should "allow stubbing a method that takes any args" do
488
- assert_equal 'default', subject.anyargs
489
- assert_equal 'default', subject.anyargs(1)
490
- assert_equal 'one-two', subject.anyargs(1, 2)
482
+ assert_equal "default", subject.anyargs
483
+ assert_equal "default", subject.anyargs(1)
484
+ assert_equal "one-two", subject.anyargs(1, 2)
491
485
  end
492
486
 
493
487
  should "allow stubbing a method that takes a minimum number of args" do
494
- assert_equal 'one-two', subject.minargs(1, 2)
495
- assert_equal 'one-two-three', subject.minargs(1, 2, 3)
496
- assert_equal 'default', subject.minargs(1, 2, 4)
497
- assert_equal 'default', subject.minargs(1, 2, 3, 4)
488
+ assert_equal "one-two", subject.minargs(1, 2)
489
+ assert_equal "one-two-three", subject.minargs(1, 2, 3)
490
+ assert_equal "default", subject.minargs(1, 2, 4)
491
+ assert_equal "default", subject.minargs(1, 2, 3, 4)
498
492
  end
499
493
 
500
494
  should "allow stubbing a method that takes a block" do
501
- assert_equal 'default', subject.withblock
502
- assert_equal 'default', subject.withblock{ 'my-block' }
495
+ assert_equal "default", subject.withblock
496
+ assert_equal "default", subject.withblock{ "my-block" }
503
497
  end
504
498
 
505
499
  should "not allow stubbing methods with invalid arity" do
@@ -525,55 +519,54 @@ module MuchStub
525
519
 
526
520
  assert_raises{ subject.withblock(1) }
527
521
  end
528
-
529
522
  end
530
523
 
531
524
  class DelegateClassTests < SystemTests
532
525
  desc "a class that delegates another object"
533
526
  setup do
534
527
  @class = DelegateClass
535
- MuchStub.stub(@class, :noargs){ 'default' }
536
- MuchStub.stub(@class, :noargs).with{ 'none' }
528
+ MuchStub.stub(@class, :noargs){ "default" }
529
+ MuchStub.stub(@class, :noargs).with{ "none" }
537
530
 
538
- MuchStub.stub(@class, :withargs){ 'default' }
539
- MuchStub.stub(@class, :withargs).with(1){ 'one' }
531
+ MuchStub.stub(@class, :withargs){ "default" }
532
+ MuchStub.stub(@class, :withargs).with(1){ "one" }
540
533
 
541
- MuchStub.stub(@class, :anyargs){ 'default' }
542
- MuchStub.stub(@class, :anyargs).with(1, 2){ 'one-two' }
534
+ MuchStub.stub(@class, :anyargs){ "default" }
535
+ MuchStub.stub(@class, :anyargs).with(1, 2){ "one-two" }
543
536
 
544
- MuchStub.stub(@class, :minargs){ 'default' }
545
- MuchStub.stub(@class, :minargs).with(1, 2){ 'one-two' }
546
- MuchStub.stub(@class, :minargs).with(1, 2, 3){ 'one-two-three' }
537
+ MuchStub.stub(@class, :minargs){ "default" }
538
+ MuchStub.stub(@class, :minargs).with(1, 2){ "one-two" }
539
+ MuchStub.stub(@class, :minargs).with(1, 2, 3){ "one-two-three" }
547
540
 
548
- MuchStub.stub(@class, :withblock){ 'default' }
541
+ MuchStub.stub(@class, :withblock){ "default" }
549
542
  end
550
543
  subject{ @class }
551
544
 
552
545
  should "allow stubbing a method that doesn't take args" do
553
- assert_equal 'none', subject.noargs
546
+ assert_equal "none", subject.noargs
554
547
  end
555
548
 
556
549
  should "allow stubbing a method that takes args" do
557
- assert_equal 'one', subject.withargs(1)
558
- assert_equal 'default', subject.withargs(2)
550
+ assert_equal "one", subject.withargs(1)
551
+ assert_equal "default", subject.withargs(2)
559
552
  end
560
553
 
561
554
  should "allow stubbing a method that takes any args" do
562
- assert_equal 'default', subject.anyargs
563
- assert_equal 'default', subject.anyargs(1)
564
- assert_equal 'one-two', subject.anyargs(1, 2)
555
+ assert_equal "default", subject.anyargs
556
+ assert_equal "default", subject.anyargs(1)
557
+ assert_equal "one-two", subject.anyargs(1, 2)
565
558
  end
566
559
 
567
560
  should "allow stubbing a method that takes a minimum number of args" do
568
- assert_equal 'one-two', subject.minargs(1, 2)
569
- assert_equal 'one-two-three', subject.minargs(1, 2, 3)
570
- assert_equal 'default', subject.minargs(1, 2, 4)
571
- assert_equal 'default', subject.minargs(1, 2, 3, 4)
561
+ assert_equal "one-two", subject.minargs(1, 2)
562
+ assert_equal "one-two-three", subject.minargs(1, 2, 3)
563
+ assert_equal "default", subject.minargs(1, 2, 4)
564
+ assert_equal "default", subject.minargs(1, 2, 3, 4)
572
565
  end
573
566
 
574
567
  should "allow stubbing a method that takes a block" do
575
- assert_equal 'default', subject.withblock
576
- assert_equal 'default', subject.withblock{ 'my-block' }
568
+ assert_equal "default", subject.withblock
569
+ assert_equal "default", subject.withblock{ "my-block" }
577
570
  end
578
571
 
579
572
  should "allow stubbing methods with invalid arity" do
@@ -599,55 +592,54 @@ module MuchStub
599
592
 
600
593
  assert_nothing_raised{ subject.withblock(1) }
601
594
  end
602
-
603
595
  end
604
596
 
605
597
  class DelegateInstanceTests < SystemTests
606
598
  desc "an instance that delegates another object"
607
599
  setup do
608
600
  @instance = DelegateClass.new
609
- MuchStub.stub(@instance, :noargs){ 'default' }
610
- MuchStub.stub(@instance, :noargs).with{ 'none' }
601
+ MuchStub.stub(@instance, :noargs){ "default" }
602
+ MuchStub.stub(@instance, :noargs).with{ "none" }
611
603
 
612
- MuchStub.stub(@instance, :withargs){ 'default' }
613
- MuchStub.stub(@instance, :withargs).with(1){ 'one' }
604
+ MuchStub.stub(@instance, :withargs){ "default" }
605
+ MuchStub.stub(@instance, :withargs).with(1){ "one" }
614
606
 
615
- MuchStub.stub(@instance, :anyargs){ 'default' }
616
- MuchStub.stub(@instance, :anyargs).with(1, 2){ 'one-two' }
607
+ MuchStub.stub(@instance, :anyargs){ "default" }
608
+ MuchStub.stub(@instance, :anyargs).with(1, 2){ "one-two" }
617
609
 
618
- MuchStub.stub(@instance, :minargs){ 'default' }
619
- MuchStub.stub(@instance, :minargs).with(1, 2){ 'one-two' }
620
- MuchStub.stub(@instance, :minargs).with(1, 2, 3){ 'one-two-three' }
610
+ MuchStub.stub(@instance, :minargs){ "default" }
611
+ MuchStub.stub(@instance, :minargs).with(1, 2){ "one-two" }
612
+ MuchStub.stub(@instance, :minargs).with(1, 2, 3){ "one-two-three" }
621
613
 
622
- MuchStub.stub(@instance, :withblock){ 'default' }
614
+ MuchStub.stub(@instance, :withblock){ "default" }
623
615
  end
624
616
  subject{ @instance }
625
617
 
626
618
  should "allow stubbing a method that doesn't take args" do
627
- assert_equal 'none', subject.noargs
619
+ assert_equal "none", subject.noargs
628
620
  end
629
621
 
630
622
  should "allow stubbing a method that takes args" do
631
- assert_equal 'one', subject.withargs(1)
632
- assert_equal 'default', subject.withargs(2)
623
+ assert_equal "one", subject.withargs(1)
624
+ assert_equal "default", subject.withargs(2)
633
625
  end
634
626
 
635
627
  should "allow stubbing a method that takes any args" do
636
- assert_equal 'default', subject.anyargs
637
- assert_equal 'default', subject.anyargs(1)
638
- assert_equal 'one-two', subject.anyargs(1, 2)
628
+ assert_equal "default", subject.anyargs
629
+ assert_equal "default", subject.anyargs(1)
630
+ assert_equal "one-two", subject.anyargs(1, 2)
639
631
  end
640
632
 
641
633
  should "allow stubbing a method that takes a minimum number of args" do
642
- assert_equal 'one-two', subject.minargs(1, 2)
643
- assert_equal 'one-two-three', subject.minargs(1, 2, 3)
644
- assert_equal 'default', subject.minargs(1, 2, 4)
645
- assert_equal 'default', subject.minargs(1, 2, 3, 4)
634
+ assert_equal "one-two", subject.minargs(1, 2)
635
+ assert_equal "one-two-three", subject.minargs(1, 2, 3)
636
+ assert_equal "default", subject.minargs(1, 2, 4)
637
+ assert_equal "default", subject.minargs(1, 2, 3, 4)
646
638
  end
647
639
 
648
640
  should "allow stubbing a method that takes a block" do
649
- assert_equal 'default', subject.withblock
650
- assert_equal 'default', subject.withblock{ 'my-block' }
641
+ assert_equal "default", subject.withblock
642
+ assert_equal "default", subject.withblock{ "my-block" }
651
643
  end
652
644
 
653
645
  should "allow stubbing methods with invalid arity" do
@@ -673,7 +665,6 @@ module MuchStub
673
665
 
674
666
  assert_nothing_raised{ subject.withblock(1) }
675
667
  end
676
-
677
668
  end
678
669
 
679
670
  class ParentAndChildClassTests < SystemTests
@@ -682,19 +673,17 @@ module MuchStub
682
673
  @parent_class = Class.new
683
674
  @child_class = Class.new(@parent_class)
684
675
 
685
- MuchStub.stub(@parent_class, :new){ 'parent' }
686
- MuchStub.stub(@child_class, :new){ 'child' }
676
+ MuchStub.stub(@parent_class, :new){ "parent" }
677
+ MuchStub.stub(@child_class, :new){ "child" }
687
678
  end
688
679
 
689
680
  should "allow stubbing the methods individually" do
690
- assert_equal 'parent', @parent_class.new
691
- assert_equal 'child', @child_class.new
681
+ assert_equal "parent", @parent_class.new
682
+ assert_equal "child", @child_class.new
692
683
  end
693
-
694
684
  end
695
685
 
696
686
  class TestClass
697
-
698
687
  def self.noargs; end
699
688
  def self.withargs(a); end
700
689
  def self.anyargs(*args); end
@@ -706,27 +695,22 @@ module MuchStub
706
695
  def anyargs(*args); end
707
696
  def minargs(a, b, *args); end
708
697
  def withblock(&block); end
709
-
710
698
  end
711
699
 
712
700
  module TestModule
713
-
714
701
  def self.noargs; end
715
702
  def self.withargs(a); end
716
703
  def self.anyargs(*args); end
717
704
  def self.minargs(a, b, *args); end
718
705
  def self.withblock(&block); end
719
-
720
706
  end
721
707
 
722
708
  module TestMixin
723
-
724
709
  def noargs; end
725
710
  def withargs(a); end
726
711
  def anyargs(*args); end
727
712
  def minargs(a, b, *args); end
728
713
  def withblock(&block); end
729
-
730
714
  end
731
715
 
732
716
  class DelegateClass
@@ -750,5 +734,4 @@ module MuchStub
750
734
  @delegate.respond_to?(name) ? @delegate.send(name, *args, &block) : super
751
735
  end
752
736
  end
753
-
754
737
  end