mocoso 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/mocoso.rb +9 -36
- data/mocoso.gemspec +1 -1
- data/test/scary_mocks_and_nice_stubs.rb +1 -17
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76a80a460d924893db612381bac7a81d3ffaa1a2
|
4
|
+
data.tar.gz: 289580d3fea0301109093fc70445777dd4712d75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a965a66f88678883c46863c3d95f93887c476616e715853f1f903e41c3eff399b6060633bc657da45912b8702f3514946477ef29bc71732e814674f44ec20545
|
7
|
+
data.tar.gz: 1a82908dfd0d84c0119adc7f2eb3ec93b85e7f9cf6d8b05448325e493792beec2ab33f5f59f5f09095e96cfe754f9fc6c1286506fe5fd7cb11d58b4111d2ff2c
|
data/README.md
CHANGED
data/lib/mocoso.rb
CHANGED
@@ -78,35 +78,18 @@ module Mocoso
|
|
78
78
|
# subject.bar('foo') # => "foo"
|
79
79
|
# end
|
80
80
|
#
|
81
|
-
# If you try to stub a method that is not defined by the +object+,
|
82
|
-
# it raises an error.
|
83
|
-
#
|
84
|
-
# Mocoso.stub Object.new, undefined: nil
|
85
|
-
# # => NameError: undefined method `undefined' for class `Object'
|
86
|
-
#
|
87
|
-
# The same thing happens if a stubbed method is not invoked:
|
88
|
-
#
|
89
|
-
# Mocoso.stub subject, :foo, 'value' do
|
90
|
-
# end
|
91
|
-
# # => Expected method foo not invoked
|
92
|
-
#
|
93
81
|
def stub object, method, result, &block
|
94
82
|
metaclass = object.singleton_class
|
95
83
|
original = object.method method
|
96
|
-
invoked = false
|
97
84
|
|
98
85
|
metaclass.send :define_method, method do |*args|
|
99
|
-
invoked = true
|
100
86
|
result.respond_to?(:call) ? result.call(*args) : result
|
101
87
|
end
|
102
88
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
metaclass.send :define_method, method, original
|
108
|
-
raise "Expected method #{method} not invoked" if !invoked
|
109
|
-
end
|
89
|
+
yield
|
90
|
+
ensure
|
91
|
+
metaclass.send :undef_method, method
|
92
|
+
metaclass.send :define_method, method, original
|
110
93
|
end
|
111
94
|
|
112
95
|
# Expect that method +method+ is called with the arguments specified in the
|
@@ -129,22 +112,12 @@ module Mocoso
|
|
129
112
|
# end
|
130
113
|
#
|
131
114
|
def expect object, method, options, &block
|
132
|
-
|
133
|
-
end
|
134
|
-
|
135
|
-
# Intended for private use, but you can overwrite the +call+ method
|
136
|
-
# if you want to support more expectation options.
|
137
|
-
class Expectation # :nodoc:
|
138
|
-
attr :options
|
139
|
-
|
140
|
-
def initialize options
|
141
|
-
@options = options
|
142
|
-
end
|
143
|
-
|
144
|
-
def call *params
|
115
|
+
expectation = -> *params {
|
145
116
|
with = options.fetch(:with) { [] }
|
146
117
|
raise ExpectationError, "Expected #{with}, got #{params}" if params != with
|
147
|
-
options.fetch
|
148
|
-
|
118
|
+
options.fetch(:returns)
|
119
|
+
}
|
120
|
+
|
121
|
+
stub object, method, expectation, &block
|
149
122
|
end
|
150
123
|
end
|
data/mocoso.gemspec
CHANGED
@@ -18,7 +18,7 @@ setup do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
test 'raises error if block is not given' do |subject|
|
21
|
-
assert_raise { stub(subject, foo
|
21
|
+
assert_raise { stub(subject, :foo, 'foo') }
|
22
22
|
end
|
23
23
|
|
24
24
|
test 'raises error if object not respond to the given method' do |subject|
|
@@ -80,19 +80,3 @@ test 'expectation with multiple arguments' do |subject|
|
|
80
80
|
assert_equal 'new foo', subject.foo('new foo', optional: true)
|
81
81
|
end
|
82
82
|
end
|
83
|
-
|
84
|
-
test 'raises error if stubbed method is never invoked' do |subject|
|
85
|
-
assert_raise {
|
86
|
-
stub subject, :foo, 'value' do
|
87
|
-
end
|
88
|
-
}
|
89
|
-
end
|
90
|
-
|
91
|
-
test 'stub within a stub' do |subject|
|
92
|
-
stub subject, :foo, 'outer' do
|
93
|
-
stub subject, :foo, 'inner' do
|
94
|
-
assert_equal 'inner', subject.foo
|
95
|
-
end
|
96
|
-
assert_equal 'outer', subject.foo
|
97
|
-
end
|
98
|
-
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mocoso
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francesco Rodríguez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cutest
|