spy 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +65 -0
- data/README.md +2 -2
- data/lib/spy/agency.rb +11 -15
- data/lib/spy/mock.rb +4 -4
- data/lib/spy/version.rb +1 -1
- metadata +3 -2
data/CHANGELOG.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
## Spy 0.3.1 (March 13, 2013) ##
|
2
|
+
|
3
|
+
* Fix Agency recruiting of mock
|
4
|
+
|
5
|
+
## Spy 0.3.0 (March 12, 2013) ##
|
6
|
+
|
7
|
+
* Added Mock
|
8
|
+
|
9
|
+
Example:
|
10
|
+
|
11
|
+
book = Spy.mock(Book, author: "John Steinbeck")
|
12
|
+
|
13
|
+
* Deprecate Double and use Mock instead
|
14
|
+
* Fix Exceptions so they can have custom messages
|
15
|
+
|
16
|
+
## Spy 0.2.5 (March 9, 2013) ##
|
17
|
+
|
18
|
+
* Add custom exception classes
|
19
|
+
|
20
|
+
## Spy 0.2.4 (February 28, 2013) ##
|
21
|
+
|
22
|
+
* Fix airty checking of Spy::Subroutine#and_return
|
23
|
+
|
24
|
+
## Spy 0.2.3 (February 28, 2013) ##
|
25
|
+
|
26
|
+
* Fix marshal dumping
|
27
|
+
* Add Docs
|
28
|
+
* Make error messages clearer
|
29
|
+
|
30
|
+
## Spy 0.2.2 (February 26, 2013) ##
|
31
|
+
|
32
|
+
* Make compatible with ruby 2.0.0
|
33
|
+
|
34
|
+
## Spy 0.2.1 (February 25, 2013) ##
|
35
|
+
|
36
|
+
* fix missing CallLog
|
37
|
+
|
38
|
+
## Spy 0.2.0 (February 22, 2013) ##
|
39
|
+
|
40
|
+
* Add CallLog
|
41
|
+
* Fix constant stubbing
|
42
|
+
* Ensure spy is logging all calls even if an error is raised
|
43
|
+
* add Spy::Subroutine#called_with
|
44
|
+
|
45
|
+
## Spy 0.1.0 (February 20, 2013) ##
|
46
|
+
|
47
|
+
* add Spy#and_raise
|
48
|
+
* add Spy#and_throw
|
49
|
+
* add Spy#and_yield
|
50
|
+
* add Constant stubbing
|
51
|
+
* fix private method lookups
|
52
|
+
|
53
|
+
## Spy 0.0.1 (February 5, 2013) ##
|
54
|
+
|
55
|
+
* Stub objects
|
56
|
+
|
57
|
+
Example:
|
58
|
+
|
59
|
+
Spy.on(book, :title).and_return("East of Eden")
|
60
|
+
|
61
|
+
* Create Doubles
|
62
|
+
|
63
|
+
Example:
|
64
|
+
|
65
|
+
Spy.double("Double Name", stub: :method)
|
data/README.md
CHANGED
@@ -97,8 +97,8 @@ Book.new(title: "The Big Cheese").title #=> "Cannery Row"
|
|
97
97
|
### Test Mocks
|
98
98
|
|
99
99
|
A test mock is an object that quacks like a given class but will raise an error
|
100
|
-
when the method is not stubbed.
|
101
|
-
the original method.
|
100
|
+
when the method is not stubbed. Spy will not let you stub a method that wasn't
|
101
|
+
on the mocked class. You can spy on the classes and call through to the original method.
|
102
102
|
|
103
103
|
```ruby
|
104
104
|
book = Spy.mock(Book)
|
data/lib/spy/agency.rb
CHANGED
@@ -22,11 +22,8 @@ module Spy
|
|
22
22
|
# @return [spy]
|
23
23
|
def recruit(spy)
|
24
24
|
raise AlreadyStubbedError if @spies[spy.object_id]
|
25
|
-
|
26
|
-
|
27
|
-
else
|
28
|
-
raise ArgumentError, "#{spy}, was not a spy"
|
29
|
-
end
|
25
|
+
check_spy!(spy)
|
26
|
+
@spies[spy.object_id] = spy
|
30
27
|
end
|
31
28
|
|
32
29
|
# remove spy from the records
|
@@ -34,22 +31,15 @@ module Spy
|
|
34
31
|
# @return [spy]
|
35
32
|
def retire(spy)
|
36
33
|
raise NoSpyError unless @spies[spy.object_id]
|
37
|
-
|
38
|
-
@spies.delete(spy.object_id)
|
39
|
-
else
|
40
|
-
raise ArgumentError, "#{spy}, was not a spy"
|
41
|
-
end
|
34
|
+
@spies.delete(spy.object_id)
|
42
35
|
end
|
43
36
|
|
44
37
|
# checks to see if a spy is hooked
|
45
38
|
# @param spy [Subroutine, Constant, Double]
|
46
39
|
# @return [Boolean]
|
47
40
|
def active?(spy)
|
48
|
-
|
49
|
-
|
50
|
-
else
|
51
|
-
raise ArgumentError, "#{spy}, was not a spy"
|
52
|
-
end
|
41
|
+
check_spy!(spy)
|
42
|
+
@spies.has_key?(spy.object_id)
|
53
43
|
end
|
54
44
|
|
55
45
|
# unhooks all spies and clears records
|
@@ -74,5 +64,11 @@ module Spy
|
|
74
64
|
def spies
|
75
65
|
@spies.values
|
76
66
|
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def check_spy!(spy)
|
71
|
+
raise ArgumentError, "#{spy}, was not a spy" unless spy.is_a?(Base) || spy.respond_to?(:_mock_class, true)
|
72
|
+
end
|
77
73
|
end
|
78
74
|
end
|
data/lib/spy/mock.rb
CHANGED
@@ -8,7 +8,8 @@ module Spy
|
|
8
8
|
CLASSES_NOT_TO_OVERRIDE = [Enumerable, Numeric, Comparable, Class, Module, Object]
|
9
9
|
METHODS_NOT_TO_OVERRIDE = [:initialize, :method]
|
10
10
|
|
11
|
-
def initialize
|
11
|
+
def initialize(&mock_method)
|
12
|
+
Agency.instance.recruit(self)
|
12
13
|
end
|
13
14
|
|
14
15
|
def is_a?(other)
|
@@ -24,7 +25,7 @@ module Spy
|
|
24
25
|
def method(method_name)
|
25
26
|
new_method = super
|
26
27
|
if new_method.parameters.size >= 1 &&
|
27
|
-
new_method.parameters.last.last == :
|
28
|
+
new_method.parameters.last.last == :mock_method
|
28
29
|
|
29
30
|
begin
|
30
31
|
_mock_class.send(:remove_method, method_name)
|
@@ -52,7 +53,6 @@ module Spy
|
|
52
53
|
|
53
54
|
include Mock
|
54
55
|
end
|
55
|
-
Agency.instance.recruit(mock_klass)
|
56
56
|
mock_klass
|
57
57
|
end
|
58
58
|
|
@@ -114,7 +114,7 @@ module Spy
|
|
114
114
|
"*#{name}"
|
115
115
|
end
|
116
116
|
end.compact
|
117
|
-
args << "&
|
117
|
+
args << "&mock_method"
|
118
118
|
args.join(",")
|
119
119
|
end
|
120
120
|
end
|
data/lib/spy/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pry
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- .gitignore
|
119
119
|
- .travis.yml
|
120
120
|
- .yardopts
|
121
|
+
- CHANGELOG.md
|
121
122
|
- Gemfile
|
122
123
|
- LICENSE.txt
|
123
124
|
- README.md
|