mocoso 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/lib/mocoso.rb +19 -15
- data/mocoso.gemspec +1 -1
- 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: 28d0d3a0e008702420b77c694201274bee0f074f
|
4
|
+
data.tar.gz: 7fc938881701274f8170549426e908623283a3c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75c5b235d40842390adbf5f00ffbb7c0606a92352a5a0f8dcb1ba47a2ca00de81f55f64a8319e27f2e4b9a1f742a9e1f966e08d9cb14318066d3809e3154120d
|
7
|
+
data.tar.gz: ba1dfe75fc54f4ff04715a246d377a52009322234c83d42ebafb43fe5c2f890af5802d54f738734b422161340a67b3d63a56c0f87c06b41808a86efd04735b1c
|
data/README.md
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
Mocoso
|
2
2
|
======
|
3
3
|
|
4
|
-
Yet Another Simple Stub & Mock library. This is stolen from
|
4
|
+
Yet Another Simple Stub & Mock library. This is inspired by (stolen from)
|
5
5
|
[Minitest::Mock][minitest], [Override][override] and [Mocha][mocha].
|
6
6
|
|
7
|
-
**Made in Peru.**
|
8
|
-
|
9
7
|
Motivation
|
10
8
|
----------
|
11
9
|
|
@@ -42,6 +40,8 @@ A quick example (uses [Cutest][cutest]):
|
|
42
40
|
expect User, :find, with: [1], returns: user do
|
43
41
|
assert_equal user, User.find(1)
|
44
42
|
end
|
43
|
+
|
44
|
+
assert_equal nil, User.find(1)
|
45
45
|
end
|
46
46
|
|
47
47
|
test 'stubbing an instance method' do
|
@@ -50,6 +50,8 @@ A quick example (uses [Cutest][cutest]):
|
|
50
50
|
stub user, :valid?, true do
|
51
51
|
assert user.valid?
|
52
52
|
end
|
53
|
+
|
54
|
+
assert !user.valid?
|
53
55
|
end
|
54
56
|
|
55
57
|
Check [Official Documentation][docs] for more details.
|
data/lib/mocoso.rb
CHANGED
@@ -26,19 +26,23 @@
|
|
26
26
|
# expect User, :find, with: [1], returns: user do
|
27
27
|
# assert_equal user, User.find(1)
|
28
28
|
# end
|
29
|
+
#
|
30
|
+
# assert_equal nil, User.find(1)
|
29
31
|
# end
|
30
32
|
#
|
31
33
|
# test 'stubbing an instance method' do
|
32
34
|
# user = User.new
|
33
35
|
#
|
34
|
-
# stub user, valid
|
36
|
+
# stub user, :valid?, true do
|
35
37
|
# assert user.valid?
|
36
38
|
# end
|
39
|
+
#
|
40
|
+
# assert !user.valid?
|
37
41
|
# end
|
38
42
|
#
|
39
43
|
# Note: this example uses the test framework Cutest[1]:
|
40
44
|
#
|
41
|
-
# Mocoso is stolen from Override[2], Minitest::Mock[3] and Mocha[4].
|
45
|
+
# Mocoso is inspired by (stolen from) Override[2], Minitest::Mock[3] and Mocha[4].
|
42
46
|
#
|
43
47
|
# * [1]: https://github.com/djanowski/cutest/
|
44
48
|
# * [2]: https://github.com/soveran/override/
|
@@ -46,15 +50,6 @@
|
|
46
50
|
# * [4]: https://github.com/freerange/mocha/
|
47
51
|
#
|
48
52
|
module Mocoso
|
49
|
-
# Raised by #expect when a expectation is not fulfilled.
|
50
|
-
#
|
51
|
-
# Mocoso.expect object, :method, with: 'argument', returns: nil do
|
52
|
-
# object.method 'unexpected argument'
|
53
|
-
# # => Mocoso::ExpectationError: Expected ["argument"], got ["unexpected argument"]
|
54
|
-
# end
|
55
|
-
#
|
56
|
-
ExpectationError = Class.new StandardError
|
57
|
-
|
58
53
|
# Rewrites each method from +methods+ and defined in +object+. +methods+ is a
|
59
54
|
# Hash that represents stubbed method name symbols as keys and corresponding
|
60
55
|
# return values as values. The methods are restored after the given +block+
|
@@ -83,7 +78,7 @@ module Mocoso
|
|
83
78
|
original = object.method method
|
84
79
|
|
85
80
|
metaclass.send :define_method, method do |*args|
|
86
|
-
result.respond_to?(:call) ? result.
|
81
|
+
result.respond_to?(:call) ? result.(*args) : result
|
87
82
|
end
|
88
83
|
|
89
84
|
yield
|
@@ -92,7 +87,7 @@ module Mocoso
|
|
92
87
|
metaclass.send :define_method, method, original
|
93
88
|
end
|
94
89
|
|
95
|
-
#
|
90
|
+
# Expects that method +method+ is called with the arguments specified in the
|
96
91
|
# +:with+ option (defaults to +[]+ if it's not given) and returns the value
|
97
92
|
# specified in the +:returns+ option. If expectations are not met, it raises
|
98
93
|
# Mocoso::ExpectationError error. It uses #stub internally, so it will restore
|
@@ -113,11 +108,20 @@ module Mocoso
|
|
113
108
|
#
|
114
109
|
def expect object, method, options, &block
|
115
110
|
expectation = -> *params {
|
116
|
-
with = options.fetch
|
111
|
+
with = options.fetch :with, []
|
117
112
|
raise ExpectationError, "Expected #{with}, got #{params}" if params != with
|
118
|
-
options.fetch
|
113
|
+
options.fetch :returns
|
119
114
|
}
|
120
115
|
|
121
116
|
stub object, method, expectation, &block
|
122
117
|
end
|
118
|
+
|
119
|
+
# Raised by #expect when a expectation is not fulfilled.
|
120
|
+
#
|
121
|
+
# Mocoso.expect object, :method, with: 'argument', returns: nil do
|
122
|
+
# object.method 'unexpected argument'
|
123
|
+
# # => Mocoso::ExpectationError: Expected ["argument"], got ["unexpected argument"]
|
124
|
+
# end
|
125
|
+
#
|
126
|
+
ExpectationError = Class.new StandardError
|
123
127
|
end
|
data/mocoso.gemspec
CHANGED
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.1.
|
4
|
+
version: 1.1.1
|
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-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cutest
|