mocoso 1.1.1 → 1.2.0
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 +10 -10
- data/mocoso.gemspec +1 -1
- data/test/scary_mocks_and_nice_stubs.rb +4 -4
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9f6f53b3e3a29820c1944832ff3de637d468e4e
|
4
|
+
data.tar.gz: 3fbc9ff9e2c65770153c6936ef7824acf9e89575
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91c1c78830ff902b84e0f5c27e6f431e9d0dcac1b21634f3b2ab1dfc1156426dd7f84d5109d2c1656a8eb977cf65dd4a5ad3782a4c77da185a647a18540220ae
|
7
|
+
data.tar.gz: bd5ec6b9bec963f5f73e8bbec7a88f6d8f182cd9e5abaf9dad1a83118246878cfb3a3758929be195002eb9697f6a8e14bc0a469ae18358adb28efe19129bc9fc
|
data/README.md
CHANGED
data/lib/mocoso.rb
CHANGED
@@ -23,7 +23,7 @@
|
|
23
23
|
# test 'mocking a class method' do
|
24
24
|
# user = User.new
|
25
25
|
#
|
26
|
-
# expect User, :find, with: [1],
|
26
|
+
# expect User, :find, with: [1], return: user do
|
27
27
|
# assert_equal user, User.find(1)
|
28
28
|
# end
|
29
29
|
#
|
@@ -65,7 +65,7 @@ module Mocoso
|
|
65
65
|
#
|
66
66
|
# You can pass a callable object (responds to +call+) as a value:
|
67
67
|
#
|
68
|
-
# Mocoso.stub subject, :foo, -> {
|
68
|
+
# Mocoso.stub subject, :foo, -> { 'foo' } do
|
69
69
|
# subject.foo # => "foo"
|
70
70
|
# end
|
71
71
|
#
|
@@ -73,7 +73,7 @@ module Mocoso
|
|
73
73
|
# subject.bar('foo') # => "foo"
|
74
74
|
# end
|
75
75
|
#
|
76
|
-
def stub object, method, result
|
76
|
+
def stub object, method, result
|
77
77
|
metaclass = object.singleton_class
|
78
78
|
original = object.method method
|
79
79
|
|
@@ -88,8 +88,8 @@ module Mocoso
|
|
88
88
|
end
|
89
89
|
|
90
90
|
# Expects that method +method+ is called with the arguments specified in the
|
91
|
-
# +:with+ option (defaults to +[]+ if it's not given) and
|
92
|
-
# specified in the +:
|
91
|
+
# +:with+ option (defaults to +[]+ if it's not given) and return the value
|
92
|
+
# specified in the +:return+ option. If expectations are not met, it raises
|
93
93
|
# Mocoso::ExpectationError error. It uses #stub internally, so it will restore
|
94
94
|
# the methods to their original implementation after the +block+ is executed.
|
95
95
|
#
|
@@ -98,7 +98,7 @@ module Mocoso
|
|
98
98
|
#
|
99
99
|
# user = User[1]
|
100
100
|
#
|
101
|
-
# Mocoso.expect user, :update, with: [{ name: 'new name' }],
|
101
|
+
# Mocoso.expect user, :update, with: [{ name: 'new name' }], return: true do
|
102
102
|
# subject.update unexpected: nil
|
103
103
|
# # => Mocoso::ExpectationError: Expected [{:name=>"new name"}], got [{:unexpected=>nil}]
|
104
104
|
#
|
@@ -106,19 +106,19 @@ module Mocoso
|
|
106
106
|
# # => true
|
107
107
|
# end
|
108
108
|
#
|
109
|
-
def expect object, method, options
|
109
|
+
def expect object, method, options
|
110
110
|
expectation = -> *params {
|
111
111
|
with = options.fetch :with, []
|
112
112
|
raise ExpectationError, "Expected #{with}, got #{params}" if params != with
|
113
|
-
options.fetch :
|
113
|
+
options.fetch :return
|
114
114
|
}
|
115
115
|
|
116
|
-
stub object, method, expectation, &
|
116
|
+
stub object, method, expectation, &proc
|
117
117
|
end
|
118
118
|
|
119
119
|
# Raised by #expect when a expectation is not fulfilled.
|
120
120
|
#
|
121
|
-
# Mocoso.expect object, :method, with: 'argument',
|
121
|
+
# Mocoso.expect object, :method, with: 'argument', return: nil do
|
122
122
|
# object.method 'unexpected argument'
|
123
123
|
# # => Mocoso::ExpectationError: Expected ["argument"], got ["unexpected argument"]
|
124
124
|
# end
|
data/mocoso.gemspec
CHANGED
@@ -56,7 +56,7 @@ test 'stubs method with a callable object that requires arguments' do |subject|
|
|
56
56
|
end
|
57
57
|
|
58
58
|
test 'succeeds if expectations are met' do |subject|
|
59
|
-
expect subject, :baz, with: ['value'],
|
59
|
+
expect subject, :baz, with: ['value'], return: 'result' do
|
60
60
|
assert_equal 'result', subject.baz('value')
|
61
61
|
end
|
62
62
|
|
@@ -64,19 +64,19 @@ test 'succeeds if expectations are met' do |subject|
|
|
64
64
|
end
|
65
65
|
|
66
66
|
test 'raises an error if expectation are not met' do |subject|
|
67
|
-
expect subject, :baz, with: ['value'],
|
67
|
+
expect subject, :baz, with: ['value'], return: 'result' do
|
68
68
|
assert_raise(Mocoso::ExpectationError) { subject.baz('another') }
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
72
|
test 'expectation without with option defaults to empty array' do |subject|
|
73
|
-
expect subject, :foo,
|
73
|
+
expect subject, :foo, return: 'new foo' do
|
74
74
|
assert_equal 'new foo', subject.foo
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
78
|
test 'expectation with multiple arguments' do |subject|
|
79
|
-
expect subject, :foo, with: ['new foo', { optional: true }],
|
79
|
+
expect subject, :foo, with: ['new foo', { optional: true }], return: 'new foo' do
|
80
80
|
assert_equal 'new foo', subject.foo('new foo', optional: true)
|
81
81
|
end
|
82
82
|
end
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mocoso
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.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-
|
11
|
+
date: 2013-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cutest
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
description: A simple stub & mock library
|
@@ -46,17 +46,17 @@ require_paths:
|
|
46
46
|
- lib
|
47
47
|
required_ruby_version: !ruby/object:Gem::Requirement
|
48
48
|
requirements:
|
49
|
-
- -
|
49
|
+
- - '>='
|
50
50
|
- !ruby/object:Gem::Version
|
51
51
|
version: '0'
|
52
52
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- -
|
54
|
+
- - '>='
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: '0'
|
57
57
|
requirements: []
|
58
58
|
rubyforge_project:
|
59
|
-
rubygems_version: 2.
|
59
|
+
rubygems_version: 2.0.3
|
60
60
|
signing_key:
|
61
61
|
specification_version: 4
|
62
62
|
summary: A simple stub & mock library
|