mocoso 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/mocoso.rb +6 -3
- data/mocoso.gemspec +1 -1
- data/test/scary_mocks_and_nice_stubs.rb +2 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c12b98f62eb01e570daf1a9101b16a168837ec7d
|
4
|
+
data.tar.gz: cafcefb94d91446ff97bfb0e8ab72883be345101
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af1706795d43d65d19045663aee87eaf42448ef47c6a1147193282bf522000be8dfccb1800bd852c0bb5e09451dbab42d968ca943ba749c70354ca88a19a96f2
|
7
|
+
data.tar.gz: 1a2aeaea3ae9b6f2b86a7c922c353c9c4173ffb00638c506921f7715ceba1315b5fac551241097175a15a9738a99a8b851dc04748e5f30cdf0854b451c32a686
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Mocoso [](https://travis-ci.org/frodsan/mocoso)
|
2
2
|
======
|
3
3
|
|
4
|
-
Yet Another Simple Stub & Mock library. This is
|
4
|
+
Yet Another Simple Stub & Mock library. This is stolen from tools such as
|
5
5
|
[Minitest::Mock][minitest], [Override][override] and [Mocha][mocha].
|
6
6
|
|
7
7
|
Motivation
|
data/lib/mocoso.rb
CHANGED
@@ -34,7 +34,7 @@
|
|
34
34
|
#
|
35
35
|
# Note: this example uses the test framework Cutest[1]:
|
36
36
|
#
|
37
|
-
# Mocoso is
|
37
|
+
# Mocoso is stolen from Override[2], Minitest::Mock[3] and Mocha[4].
|
38
38
|
#
|
39
39
|
# * [1]: https://github.com/djanowski/cutest/
|
40
40
|
# * [2]: https://github.com/soveran/override/
|
@@ -97,8 +97,11 @@ module Mocoso
|
|
97
97
|
|
98
98
|
methods.each do |method, result|
|
99
99
|
metaclass.send :alias_method, stub_method_name(method), method
|
100
|
-
|
101
|
-
|
100
|
+
|
101
|
+
if result.respond_to?(:call)
|
102
|
+
metaclass.send(:define_method, method) { |*args| result.call(*args) }
|
103
|
+
else
|
104
|
+
metaclass.send(:define_method, method) { result }
|
102
105
|
end
|
103
106
|
end
|
104
107
|
|
data/mocoso.gemspec
CHANGED
@@ -37,7 +37,7 @@ test 'stubs method with a callable object' do |subject|
|
|
37
37
|
stub subject, foo: -> { 'new foo' }
|
38
38
|
|
39
39
|
assert subject.foo != before
|
40
|
-
|
40
|
+
assert_equal 'new foo', subject.foo
|
41
41
|
end
|
42
42
|
|
43
43
|
test 'stubs method with a callable object with arguments' do |subject|
|
@@ -46,6 +46,7 @@ test 'stubs method with a callable object with arguments' do |subject|
|
|
46
46
|
stub subject, foo: ->(a) { "new #{a}" }
|
47
47
|
|
48
48
|
assert subject.foo('foo') != before
|
49
|
+
assert_equal 'new foo', subject.foo('foo')
|
49
50
|
end
|
50
51
|
|
51
52
|
test 'stubs method without side effects if a block is given' do
|