micro_mock 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.
- data/README.md +31 -25
- data/lib/micro_mock.rb +37 -24
- metadata +39 -26
data/README.md
CHANGED
|
@@ -1,43 +1,49 @@
|
|
|
1
1
|
# MicroMock
|
|
2
2
|
|
|
3
|
-
###
|
|
3
|
+
### A tiny mocking script.
|
|
4
4
|
|
|
5
|
-
MicroMock
|
|
5
|
+
MicroMock doesn't make any assumptions about the testing framework.
|
|
6
|
+
It leaves assertions/expectations up to you.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
Calling it a mocking script is a bit of a misnomer
|
|
9
|
+
since its really a dynamic class generator.
|
|
10
|
+
The term "stub" is used loosely since it adds real behavior...
|
|
11
|
+
and "mocking" a class with real behavior proves to be quite useful.
|
|
11
12
|
|
|
12
13
|
## Intall
|
|
13
14
|
```bash
|
|
14
15
|
gem install micro_mock
|
|
15
16
|
```
|
|
16
17
|
|
|
17
|
-
##
|
|
18
|
+
## Usage
|
|
18
19
|
```ruby
|
|
19
20
|
Mock = MicroMock.make
|
|
20
21
|
|
|
21
22
|
# mock a class method
|
|
22
|
-
Mock.stub
|
|
23
|
-
assert_equal 1, args.length # Test::Unit
|
|
24
|
-
args.length.should eq 1 # RSpec
|
|
25
|
-
end
|
|
23
|
+
Mock.stub(:foo) { true }
|
|
26
24
|
|
|
27
|
-
|
|
25
|
+
# make assertions
|
|
26
|
+
assert Mock.foo # Test::Unit
|
|
27
|
+
Mock.foo.should be_true # RSpec
|
|
28
28
|
|
|
29
29
|
# mock an instance method
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
mock
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
30
|
+
m = Mock.new
|
|
31
|
+
m.stub(:bar) { false }
|
|
32
|
+
|
|
33
|
+
# make assertions
|
|
34
|
+
assert_equal false, m.bar # Test::Unit
|
|
35
|
+
m.bar.should eq false # RSpec
|
|
36
|
+
|
|
37
|
+
# setup mock internal behavior
|
|
38
|
+
count = 1
|
|
39
|
+
m.stub(:a) { count += 1 }
|
|
40
|
+
m.stub(:b) { |i| self.a if i > 5 }
|
|
41
|
+
|
|
42
|
+
# make assertions
|
|
43
|
+
10.times { |i| m.b(i) }
|
|
44
|
+
assert_equal 5, count # Test::Unit
|
|
45
|
+
count.should eq 5 # RSpec
|
|
43
46
|
```
|
|
47
|
+
|
|
48
|
+
Of course you wouldn't normally test the mock itself... rather the code that uses the mock.
|
|
49
|
+
I'll work on adding some real world examples.
|
data/lib/micro_mock.rb
CHANGED
|
@@ -1,36 +1,48 @@
|
|
|
1
1
|
# MicroMock is a tiny mocking script.
|
|
2
|
-
# It doesn't make any assumptions about the testing framework
|
|
3
|
-
# and leaves assertions/expectations up to you.
|
|
4
2
|
#
|
|
5
|
-
#
|
|
3
|
+
# It doesn't make any assumptions about the testing framework.
|
|
4
|
+
# It leaves assertions/expectations up to you.
|
|
5
|
+
#
|
|
6
|
+
# Calling it a mocking script is a bit of a misnomer
|
|
7
|
+
# since its really a dynamic class generator.
|
|
8
|
+
#
|
|
9
|
+
# The term "stub" is used loosely since it adds real behavior...
|
|
10
|
+
# and "mocking" a class with real behavior proves to be quite useful.
|
|
6
11
|
#
|
|
7
12
|
# @example
|
|
8
13
|
# Mock = MicroMock.make
|
|
9
14
|
#
|
|
10
15
|
# # mock a class method
|
|
11
|
-
# Mock.stub
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
16
|
+
# Mock.stub(:foo) { true }
|
|
17
|
+
#
|
|
18
|
+
# # make assertions
|
|
19
|
+
# assert Mock.foo # Test::Unit
|
|
20
|
+
# Mock.foo.should be_true # RSpec
|
|
21
|
+
#
|
|
22
|
+
# # mock an instance method
|
|
23
|
+
# m = Mock.new
|
|
24
|
+
# m.stub(:bar) { false }
|
|
25
|
+
#
|
|
26
|
+
# # make assertions
|
|
27
|
+
# assert_equal false, m.bar # Test::Unit
|
|
28
|
+
# m.bar.should eq false # RSpec
|
|
29
|
+
#
|
|
30
|
+
# # setup mock internal behavior
|
|
31
|
+
# count = 1
|
|
32
|
+
# m.stub(:a) { count += 1 }
|
|
33
|
+
# m.stub(:b) { |i| self.a if i > 5 }
|
|
34
|
+
#
|
|
35
|
+
# # make assertions
|
|
36
|
+
# 10.times { |i| m.b(i) }
|
|
37
|
+
# assert_equal 5, count # Test::Unit
|
|
38
|
+
# count.should eq 5 # RSpec
|
|
39
|
+
#
|
|
40
|
+
# Of course you wouldn't normally test the mock itself... rather the code that uses the mock.
|
|
41
|
+
# I'll work on adding some real world examples.
|
|
32
42
|
module MicroMock
|
|
43
|
+
|
|
33
44
|
# Stubs a method.
|
|
45
|
+
# The term stub is used loosely since it adds real functionality.
|
|
34
46
|
# @param [Symbol] name The name of the method.
|
|
35
47
|
# @yield The block that will serve as the method definition.
|
|
36
48
|
def stub(name, &block)
|
|
@@ -46,4 +58,5 @@ module MicroMock
|
|
|
46
58
|
include MicroMock
|
|
47
59
|
end
|
|
48
60
|
end
|
|
61
|
+
|
|
49
62
|
end
|
metadata
CHANGED
|
@@ -1,51 +1,64 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: micro_mock
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
prerelease: false
|
|
5
|
+
segments:
|
|
6
|
+
- 0
|
|
7
|
+
- 0
|
|
8
|
+
- 2
|
|
9
|
+
version: 0.0.2
|
|
6
10
|
platform: ruby
|
|
7
|
-
authors:
|
|
11
|
+
authors:
|
|
8
12
|
- Nathan Hopkins
|
|
9
13
|
autorequire:
|
|
10
14
|
bindir: bin
|
|
11
15
|
cert_chain: []
|
|
12
|
-
|
|
16
|
+
|
|
17
|
+
date: 2012-09-24 00:00:00 -06:00
|
|
18
|
+
default_executable:
|
|
13
19
|
dependencies: []
|
|
14
|
-
description: ! ' MicroMock might just be the lightest mocking strategy available.
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
email:
|
|
21
|
+
description: " MicroMock might just be the lightest mocking strategy available.\n"
|
|
22
|
+
email:
|
|
18
23
|
- natehop@gmail.com
|
|
19
24
|
executables: []
|
|
25
|
+
|
|
20
26
|
extensions: []
|
|
27
|
+
|
|
21
28
|
extra_rdoc_files: []
|
|
22
|
-
|
|
29
|
+
|
|
30
|
+
files:
|
|
23
31
|
- lib/micro_mock.rb
|
|
24
32
|
- README.md
|
|
33
|
+
has_rdoc: true
|
|
25
34
|
homepage: http://hopsoft.github.com/micro_mock/
|
|
26
|
-
licenses:
|
|
35
|
+
licenses:
|
|
27
36
|
- MIT
|
|
28
37
|
post_install_message:
|
|
29
38
|
rdoc_options: []
|
|
30
|
-
|
|
39
|
+
|
|
40
|
+
require_paths:
|
|
31
41
|
- lib
|
|
32
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
requirements:
|
|
41
|
-
- -
|
|
42
|
-
- !ruby/object:Gem::Version
|
|
43
|
-
|
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
segments:
|
|
47
|
+
- 0
|
|
48
|
+
version: "0"
|
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
segments:
|
|
54
|
+
- 0
|
|
55
|
+
version: "0"
|
|
44
56
|
requirements: []
|
|
57
|
+
|
|
45
58
|
rubyforge_project:
|
|
46
|
-
rubygems_version: 1.
|
|
59
|
+
rubygems_version: 1.3.6
|
|
47
60
|
signing_key:
|
|
48
61
|
specification_version: 3
|
|
49
62
|
summary: A tiny mocking script.
|
|
50
63
|
test_files: []
|
|
51
|
-
|
|
64
|
+
|