Skip to content

Commit be02358

Browse files
committed
remove doubles because they are stupid
1 parent e34dfb5 commit be02358

File tree

12 files changed

+11
-323
lines changed

12 files changed

+11
-323
lines changed

README.md

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -115,25 +115,6 @@ To stub methods during instantiation just add arguments.
115115
book = Spy.mock(book, :first_name, author: "Neil Gaiman")
116116
```
117117

118-
### Test Doubles
119-
120-
You really shouldn't use these and use Mocks as much as possible. If you really
121-
want to use it you must require `spy/double`.
122-
A test double is an object that stands in for a real object.
123-
124-
```ruby
125-
require 'spy/double'
126-
Spy.double("book")
127-
```
128-
129-
Spy will let you stub on any method even if it doesn't exist if the object is a double.
130-
131-
Spy comes with a shortcut to define an object with methods.
132-
133-
```ruby
134-
Spy.double("book", title: "Grapes of Wrath", author: "John Steinbeck")
135-
```
136-
137118
### Arbitrary Handling
138119

139120
If you need to have a custom method based in the method inputs just send a block to `#and_return`

lib/spy.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require "spy/core_ext/marshal"
22
require "spy/agency"
3+
require "spy/base"
34
require "spy/call_log"
45
require "spy/constant"
56
require "spy/exceptions"

lib/spy/agency.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ def find(id)
2222
# @return [spy]
2323
def recruit(spy)
2424
raise AlreadyStubbedError if @spies[spy.object_id]
25-
case spy
26-
when Subroutine, Constant, Double
25+
if spy.is_a? Base
2726
@spies[spy.object_id] = spy
2827
else
2928
raise ArgumentError, "#{spy}, was not a spy"
@@ -35,8 +34,7 @@ def recruit(spy)
3534
# @return [spy]
3635
def retire(spy)
3736
raise NoSpyError unless @spies[spy.object_id]
38-
case spy
39-
when Subroutine, Constant, Double
37+
if spy.is_a? Base
4038
@spies.delete(spy.object_id)
4139
else
4240
raise ArgumentError, "#{spy}, was not a spy"
@@ -47,8 +45,7 @@ def retire(spy)
4745
# @param spy [Subroutine, Constant, Double]
4846
# @return [Boolean]
4947
def active?(spy)
50-
case spy
51-
when Subroutine, Constant, Double
48+
if spy.is_a? Base
5249
@spies.has_key?(spy.object_id)
5350
else
5451
raise ArgumentError, "#{spy}, was not a spy"

lib/spy/base.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Spy
2+
module Base
3+
end
4+
end

lib/spy/constant.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Spy
22
class Constant
3-
3+
include Base
44
# @!attribute [r] base_module
55
# @return [Module] the module that is being watched
66
#

lib/spy/double.rb

Lines changed: 0 additions & 34 deletions
This file was deleted.

lib/spy/mock.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module Spy
44
# If you attempt to stub a method on the mock that doesn't exist on the
55
# original class it will raise an error.
66
module Mock
7+
include Base
78
CLASSES_NOT_TO_OVERRIDE = [Enumerable, Numeric, Comparable, Class, Module, Object]
89
METHODS_NOT_TO_OVERRIDE = [:initialize, :method]
910

lib/spy/subroutine.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module Spy
22
class Subroutine
3+
include Base
34
# @!attribute [r] base_object
45
# @return [Object] the object that is being watched
56
#
@@ -45,7 +46,6 @@ def hook(opts = {})
4546
@hook_opts = opts
4647
@original_method_visibility = method_visibility_of(method_name)
4748
hook_opts[:visibility] ||= original_method_visibility
48-
hook_opts[:force] ||= base_object.is_a?(Double)
4949

5050
if original_method_visibility || !hook_opts[:force]
5151
@original_method = current_method

spec/spy/mock_spec.rb

Lines changed: 0 additions & 222 deletions
This file was deleted.

spec/spy/mutate_const_spec.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@ class TestSubClass < TestClass
1616
P = :p
1717
end
1818

19-
require "rspec/mocks/mutate_const"
20-
2119
module Spy
2220
describe "Constant Mutating" do
2321

24-
require "rspec/mocks/mutate_const"
25-
include RSpec::Mocks::RecursiveConstMethods
26-
2722
def reset_rspec_mocks
2823
Spy.teardown
2924
end
@@ -360,9 +355,6 @@ def change_const_value_to(value)
360355
end
361356

362357
describe Constant do
363-
require "rspec/mocks/mutate_const"
364-
include RSpec::Mocks::RecursiveConstMethods
365-
366358
def reset_rspec_mocks
367359
Spy.teardown
368360
end

0 commit comments

Comments
 (0)