mocoso 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gems +1 -1
- data/LICENSE +19 -0
- data/README.md +38 -33
- data/lib/mocoso.rb +3 -3
- data/makefile +2 -0
- data/mocoso.gemspec +5 -5
- data/test/scary_mocks_and_nice_stubs.rb +10 -0
- metadata +12 -11
- data/UNLICENSE +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84fde22389db6d310917952800c3a3464ced1fb5
|
4
|
+
data.tar.gz: 408db6f0dafa0234cd1e627816dc85e804e39ba3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 822cc257ce2fee101df1202af9a172a499d646fd71585fa210dae2daf44904f42ab2bafdbba0a9faf23db01186da3b638a44b2e98fe19bac5708b866de92a34b
|
7
|
+
data.tar.gz: 312f6a5d353fd08fe169551ec6586a0e8b12fe231108b710d1a432e75bf335e3f36bdae52f9ad4d997983a4f9a6f3de727bee3681a73b1e7dc2be7df9fa0284d
|
data/.gems
CHANGED
@@ -1 +1 @@
|
|
1
|
-
cutest -v 1.2.
|
1
|
+
cutest -v 1.2.2
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014-2015 Francesco Rodríguez
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,57 +1,62 @@
|
|
1
1
|
Mocoso
|
2
2
|
======
|
3
3
|
|
4
|
-
Yet Another Simple Stub & Mock library. This is inspired by
|
5
|
-
[Minitest::Mock][minitest]
|
4
|
+
Yet Another Simple Stub & Mock library. This is inspired by
|
5
|
+
[Minitest::Mock][minitest] and [Override][override].
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
Description
|
8
|
+
-----------
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
Yes, there are a lot of good libraries out there, but I wanted one that
|
13
|
-
meets the following criteria:
|
10
|
+
Mocoso meets the following criteria:
|
14
11
|
|
12
|
+
* Simplicity.
|
15
13
|
* Always restore stubbed methods to their original implementations.
|
16
14
|
* Doesn't allow to stub or mock undefined methods.
|
17
15
|
* Doesn't monkey-patch any class or object.
|
18
|
-
* Test-framework agnostic
|
19
|
-
|
20
|
-
And the most important: simplicity.
|
21
|
-
|
22
|
-
Installation
|
23
|
-
------------
|
24
|
-
|
25
|
-
$ gem install mocoso
|
16
|
+
* Test-framework agnostic. No integration code.
|
26
17
|
|
27
18
|
Usage
|
28
19
|
-----
|
29
20
|
|
30
21
|
A quick example (uses [Cutest][cutest]):
|
31
22
|
|
32
|
-
|
33
|
-
|
23
|
+
```ruby
|
24
|
+
require "cutest"
|
25
|
+
require "mocoso"
|
34
26
|
|
35
|
-
|
27
|
+
include Mocoso
|
36
28
|
|
37
|
-
|
38
|
-
|
29
|
+
test "mocking a class method" do
|
30
|
+
user = User.new
|
39
31
|
|
40
|
-
|
41
|
-
|
42
|
-
|
32
|
+
expect(User, :find, with: [1], return: user) do
|
33
|
+
assert_equal user, User.find(1)
|
34
|
+
end
|
43
35
|
|
44
|
-
|
45
|
-
|
36
|
+
assert_equal nil, User.find(1)
|
37
|
+
end
|
46
38
|
|
47
|
-
|
48
|
-
|
39
|
+
test "stubbing an instance method" do
|
40
|
+
user = User.new
|
49
41
|
|
50
|
-
|
51
|
-
|
52
|
-
|
42
|
+
stub(user, :valid?, true) do
|
43
|
+
assert user.valid?
|
44
|
+
end
|
53
45
|
|
54
|
-
|
55
|
-
|
46
|
+
assert !user.valid?
|
47
|
+
end
|
48
|
+
```
|
56
49
|
|
57
50
|
Check [Official Documentation][docs] for more details.
|
51
|
+
|
52
|
+
Installation
|
53
|
+
------------
|
54
|
+
|
55
|
+
```bash
|
56
|
+
$ gem install mocoso
|
57
|
+
```
|
58
|
+
|
59
|
+
[docs]: http://rubydoc.info/github/harmoni/mocoso/
|
60
|
+
[cutest]: https://github.com/djanowski/cutest/
|
61
|
+
[override]: https://github.com/soveran/override/
|
62
|
+
[minitest]: https://github.com/seattlerb/minitest/
|
data/lib/mocoso.rb
CHANGED
@@ -75,7 +75,7 @@ module Mocoso
|
|
75
75
|
#
|
76
76
|
def stub(object, method, result)
|
77
77
|
metaclass = object.singleton_class
|
78
|
-
original
|
78
|
+
original = object.method(method)
|
79
79
|
|
80
80
|
metaclass.send(:define_method, method) do |*args|
|
81
81
|
result.respond_to?(:call) ? result.(*args) : result
|
@@ -106,14 +106,14 @@ module Mocoso
|
|
106
106
|
# # => true
|
107
107
|
# end
|
108
108
|
#
|
109
|
-
def expect(object, method, options)
|
109
|
+
def expect(object, method, options, &block)
|
110
110
|
expectation = ->(*params) {
|
111
111
|
with = options.fetch(:with, [])
|
112
112
|
raise ExpectationError, "Expected #{with}, got #{params}" if params != with
|
113
113
|
options.fetch(:return)
|
114
114
|
}
|
115
115
|
|
116
|
-
stub(object, method, expectation, &
|
116
|
+
stub(object, method, expectation, &block)
|
117
117
|
end
|
118
118
|
|
119
119
|
# Raised by #expect when a expectation is not fulfilled.
|
data/makefile
ADDED
data/mocoso.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "mocoso"
|
3
|
-
s.version = "1.2.
|
3
|
+
s.version = "1.2.2"
|
4
4
|
s.summary = "A simple stub & mock library."
|
5
5
|
s.description = s.summary
|
6
6
|
s.authors = ["Francesco Rodríguez"]
|
7
|
-
s.email = ["
|
8
|
-
s.homepage = "https://github.com/
|
9
|
-
s.license = "
|
7
|
+
s.email = ["frodsan@protonmail.ch"]
|
8
|
+
s.homepage = "https://github.com/harmoni/mocoso"
|
9
|
+
s.license = "MIT"
|
10
10
|
|
11
11
|
s.files = `git ls-files`.split("\n")
|
12
12
|
|
13
|
-
s.add_development_dependency "cutest"
|
13
|
+
s.add_development_dependency "cutest", "1.2.2"
|
14
14
|
end
|
@@ -35,6 +35,16 @@ test "stubbed method return new value" do |subject|
|
|
35
35
|
assert_equal before, subject.foo
|
36
36
|
end
|
37
37
|
|
38
|
+
test "stubs singleton method" do
|
39
|
+
before = Subject.foo
|
40
|
+
|
41
|
+
stub(Subject, :foo, "new foo") do
|
42
|
+
assert_equal "new foo", Subject.foo
|
43
|
+
end
|
44
|
+
|
45
|
+
assert_equal before, Subject.foo
|
46
|
+
end
|
47
|
+
|
38
48
|
test "stubs method with a callable object" do |subject|
|
39
49
|
before = subject.foo
|
40
50
|
|
metadata
CHANGED
@@ -1,45 +1,46 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mocoso
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
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:
|
11
|
+
date: 2015-09-26 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
|
-
version:
|
19
|
+
version: 1.2.2
|
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
|
-
version:
|
26
|
+
version: 1.2.2
|
27
27
|
description: A simple stub & mock library.
|
28
28
|
email:
|
29
|
-
-
|
29
|
+
- frodsan@protonmail.ch
|
30
30
|
executables: []
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
34
|
- ".gems"
|
35
|
+
- LICENSE
|
35
36
|
- README.md
|
36
|
-
- UNLICENSE
|
37
37
|
- lib/mocoso.rb
|
38
|
+
- makefile
|
38
39
|
- mocoso.gemspec
|
39
40
|
- test/scary_mocks_and_nice_stubs.rb
|
40
|
-
homepage: https://github.com/
|
41
|
+
homepage: https://github.com/harmoni/mocoso
|
41
42
|
licenses:
|
42
|
-
-
|
43
|
+
- MIT
|
43
44
|
metadata: {}
|
44
45
|
post_install_message:
|
45
46
|
rdoc_options: []
|
@@ -57,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
58
|
version: '0'
|
58
59
|
requirements: []
|
59
60
|
rubyforge_project:
|
60
|
-
rubygems_version: 2.
|
61
|
+
rubygems_version: 2.4.8
|
61
62
|
signing_key:
|
62
63
|
specification_version: 4
|
63
64
|
summary: A simple stub & mock library.
|
data/UNLICENSE
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
This is free and unencumbered software released into the public domain.
|
2
|
-
|
3
|
-
Anyone is free to copy, modify, publish, use, compile, sell, or
|
4
|
-
distribute this software, either in source code form or as a compiled
|
5
|
-
binary, for any purpose, commercial or non-commercial, and by any
|
6
|
-
means.
|
7
|
-
|
8
|
-
In jurisdictions that recognize copyright laws, the author or authors
|
9
|
-
of this software dedicate any and all copyright interest in the
|
10
|
-
software to the public domain. We make this dedication for the benefit
|
11
|
-
of the public at large and to the detriment of our heirs and
|
12
|
-
successors. We intend this dedication to be an overt act of
|
13
|
-
relinquishment in perpetuity of all present and future rights to this
|
14
|
-
software under copyright law.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
-
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
20
|
-
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
21
|
-
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
23
|
-
|
24
|
-
For more information, please refer to <http://unlicense.org/>
|