micro_mock 0.1.0 → 0.1.1
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 +14 -14
- data/lib/micro_mock.rb +4 -4
- data/lib/micro_mock/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
### Perhaps the lightest mocking strategy available
|
4
4
|
|
5
|
-
Calling it a mocking script is a bit of a misnomer since its really a dynamic class generator
|
6
|
-
and "mocking" with real behavior proves to be quite useful.
|
5
|
+
Calling it a mocking script is a bit of a misnomer since its really a dynamic class generator
|
6
|
+
...and "mocking" with real behavior proves to be quite useful.
|
7
7
|
|
8
8
|
## Intall
|
9
9
|
|
@@ -23,8 +23,8 @@ MyMock.attr(:foo)
|
|
23
23
|
# add a class attr with a default value
|
24
24
|
MyMock.attr(:attr_with_default, "Class value")
|
25
25
|
|
26
|
-
#
|
27
|
-
MyMock.
|
26
|
+
# add a class method
|
27
|
+
MyMock.meth(:say_foo) { |arg| "#{foo} #{arg}!" }
|
28
28
|
|
29
29
|
# create a mock instance
|
30
30
|
mock = MyMock.new
|
@@ -35,8 +35,8 @@ mock.attr(:bar)
|
|
35
35
|
# add an instance attr with a default value
|
36
36
|
mock.attr(:attr_with_default, "Instance value")
|
37
37
|
|
38
|
-
#
|
39
|
-
mock.
|
38
|
+
# add an instance method
|
39
|
+
mock.meth(:say_bar) { |arg| "#{bar} #{arg}!" }
|
40
40
|
|
41
41
|
# use the mock
|
42
42
|
MyMock.attr_with_default # => "Class value"
|
@@ -58,8 +58,8 @@ MockList = MicroMock.make(Array)
|
|
58
58
|
|
59
59
|
list = MockList.new
|
60
60
|
|
61
|
-
#
|
62
|
-
list.
|
61
|
+
# add an instance method that does something interesting
|
62
|
+
list.meth :prefixed do |prefix|
|
63
63
|
map { |value| "#{prefix}:#{value}"}
|
64
64
|
end
|
65
65
|
|
@@ -74,12 +74,12 @@ Here is an example that mocks part of ActiveRecord.
|
|
74
74
|
```ruby
|
75
75
|
Model = MicroMock.make
|
76
76
|
model = Model.new
|
77
|
-
model.
|
78
|
-
model.
|
79
|
-
model.
|
80
|
-
model.
|
81
|
-
Model.
|
82
|
-
Model.
|
77
|
+
model.meth(:destroy) { @destroyed = true }
|
78
|
+
model.meth(:destroyed?) { @destroyed }
|
79
|
+
model.meth(:update_attributes) { |*args| @attributes_updated = true }
|
80
|
+
model.meth(:save) { |*args| @saved = true }
|
81
|
+
Model.meth(:find) { |*args| model.clone }
|
82
|
+
Model.meth(:all) { (1..5).map { model.clone } }
|
83
83
|
|
84
84
|
# try it out
|
85
85
|
list = Model.all # => [#<MicroMock70331390241500:0x007fee9b1b1bb0 @args=[]>, #<MicroMock...]
|
data/lib/micro_mock.rb
CHANGED
@@ -23,13 +23,13 @@ module MicroMock
|
|
23
23
|
instance_variable_set "@#{name}", default_value
|
24
24
|
end
|
25
25
|
|
26
|
-
#
|
27
|
-
# The term stub is used loosely since it adds real functionality.
|
26
|
+
# Creates a method.
|
28
27
|
# @param [Symbol] name The name of the method.
|
29
|
-
# @yield The block that will serve as the method
|
30
|
-
def
|
28
|
+
# @yield The block that will serve as the method body.
|
29
|
+
def meth(name, &block)
|
31
30
|
context.send :define_method, name, &block
|
32
31
|
end
|
32
|
+
alias_method :stub, :meth
|
33
33
|
|
34
34
|
private
|
35
35
|
|
data/lib/micro_mock/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: micro_mock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-24 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! ' Perhaps the lightest mocking strategy available.
|
15
15
|
|