simple_mock 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +9 -0
- data/README.md +15 -2
- data/lib/simple_mock/mock_delegator.rb +1 -0
- data/lib/simple_mock/version.rb +1 -1
- data/simple_mock.gemspec +1 -1
- data/test/unit/mock_delegator_test.rb +7 -0
- metadata +16 -9
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://secure.travis-ci.org/tatey/simple_mock.png?branch=master)](http://travis-ci.org/tatey/simple_mock)
|
4
4
|
|
5
|
-
A fast, tiny (
|
5
|
+
A fast, tiny (82 lines) hybrid mocking library that supports classical and partial mocking. Partial mocking mixes classical mocking with real objects. There's no monkey patching `Object` or copying. Mock objects are isolated leaving real objects completely untainted. Plays nicely with MiniTest and [RSpec](http://rspec.info/). The interface is 100% compatible with [MiniTest::Mock](https://github.com/seattlerb/minitest) so there is nothing new to learn. SimpleMock's one and only dependancy is Ruby 1.9.2 or greater.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -29,7 +29,7 @@ mock_model.valid? # => true
|
|
29
29
|
mock_model.verify # => true
|
30
30
|
```
|
31
31
|
|
32
|
-
###
|
32
|
+
### Partial Mocking
|
33
33
|
|
34
34
|
Pass an object to mix expectations with the real object's original behaviour.
|
35
35
|
|
@@ -40,6 +40,8 @@ end
|
|
40
40
|
|
41
41
|
real_model = Post.new
|
42
42
|
mock_model = SimpleMock.new real_model
|
43
|
+
mock_model.class # => Post
|
44
|
+
|
43
45
|
mock_model.expect :valid?, true
|
44
46
|
|
45
47
|
mock_model.valid? # => true
|
@@ -55,10 +57,21 @@ mock_model.valid # => true
|
|
55
57
|
real_model.valid? # => false
|
56
58
|
|
57
59
|
real_model.object_id == mock_model.__getobj__.object_id # => true
|
60
|
+
real_model.object_id != mock_model.object_id # => true
|
58
61
|
```
|
59
62
|
|
60
63
|
More documentation is available at [rubydoc.info](http://rubydoc.info/gems/simple_mock/frames).
|
61
64
|
|
65
|
+
## Performance
|
66
|
+
|
67
|
+
SimpleMock is fast. In [this benchmark](https://gist.github.com/1871840) we create an array, set an expectation and call that method 10,000 times.
|
68
|
+
|
69
|
+
``` plain
|
70
|
+
user system total real
|
71
|
+
mocha: 0.000000 0.000000 0.000000 (0.000279)
|
72
|
+
simple_mock: 0.000000 0.000000 0.000000 (0.000057)
|
73
|
+
```
|
74
|
+
|
62
75
|
## Caveats
|
63
76
|
|
64
77
|
Like MiniTest::Mock, `#expect` and `#verify` are reserved methods. Expectations should not be defined on real objects which implement these methods. As an alternative, consider creating an anonymous class which inherits from SimpleDelegator.
|
data/lib/simple_mock/version.rb
CHANGED
data/simple_mock.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.email = ["tate@tatey.com"]
|
10
10
|
s.homepage = 'https://github.com/tatey/simple_mock'
|
11
11
|
s.summary = %q{A fast, tiny hybrid mocking library.}
|
12
|
-
s.description = %q{A fast, tiny hybrid mocking library.
|
12
|
+
s.description = %q{A fast, tiny (82 lines) hybrid mocking library that supports classical and partial mocking. Partial mocking mixes classical mocking with real objects. There's no monkey patching `Object` or copying. Mock objects are isolated leaving real objects completely untainted.}
|
13
13
|
|
14
14
|
s.rubyforge_project = "simple_mock"
|
15
15
|
|
@@ -59,4 +59,11 @@ class MockDelegatorTest < MiniTest::Unit::TestCase
|
|
59
59
|
delegator.plus_one
|
60
60
|
assert tracer.verify
|
61
61
|
end
|
62
|
+
|
63
|
+
def test_class_is_mocked_class
|
64
|
+
klass = Class.new
|
65
|
+
delegator = MockDelegator.new klass.new
|
66
|
+
|
67
|
+
assert_equal klass.new.class, delegator.class
|
68
|
+
end
|
62
69
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_mock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,16 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: A fast, tiny (82 lines) hybrid mocking library that supports classical
|
31
|
+
and partial mocking. Partial mocking mixes classical mocking with real objects.
|
32
|
+
There's no monkey patching `Object` or copying. Mock objects are isolated leaving
|
33
|
+
real objects completely untainted.
|
28
34
|
email:
|
29
35
|
- tate@tatey.com
|
30
36
|
executables: []
|
@@ -33,6 +39,7 @@ extra_rdoc_files: []
|
|
33
39
|
files:
|
34
40
|
- .gitignore
|
35
41
|
- .travis.yml
|
42
|
+
- CHANGELOG.md
|
36
43
|
- Gemfile
|
37
44
|
- LICENSE
|
38
45
|
- README.md
|
@@ -66,10 +73,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
73
|
version: '0'
|
67
74
|
segments:
|
68
75
|
- 0
|
69
|
-
hash: -
|
76
|
+
hash: -3628456372320224322
|
70
77
|
requirements: []
|
71
78
|
rubyforge_project: simple_mock
|
72
|
-
rubygems_version: 1.8.
|
79
|
+
rubygems_version: 1.8.23
|
73
80
|
signing_key:
|
74
81
|
specification_version: 3
|
75
82
|
summary: A fast, tiny hybrid mocking library.
|