soveran-override 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +4 -0
- data/lib/override.rb +15 -8
- data/test/all_test.rb +6 -0
- metadata +1 -1
data/README.markdown
CHANGED
@@ -21,6 +21,10 @@ Usage
|
|
21
21
|
override(@user, :name => "Foobar", :email => "foobar@example.org")
|
22
22
|
override(User, :find => @user)
|
23
23
|
|
24
|
+
Or alternatively:
|
25
|
+
|
26
|
+
override(User, :find => override(User.spawn, :name => "Foobar, :email => "foobar@example.org"))
|
27
|
+
|
24
28
|
In case you don't know what spawn means, check my other library for
|
25
29
|
testing at http://github.com/soveran/spawner.
|
26
30
|
|
data/lib/override.rb
CHANGED
@@ -1,16 +1,22 @@
|
|
1
1
|
# Override
|
2
2
|
#
|
3
|
-
# This is the pure esence of the stubbing concept: it takes an object,
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
3
|
+
# This is the pure esence of the stubbing concept: it takes an object,
|
4
|
+
# a hash of methods/results, and proceeds to rewrite each method in the
|
5
|
+
# object. It can be used as a stubbing strategy in most cases, and I'd
|
6
|
+
# say that cases that don't fit this pattern have a very bad code smell,
|
7
7
|
# because are either dealing with internals or with side effects.
|
8
8
|
#
|
9
|
-
# Usage
|
9
|
+
# Usage
|
10
10
|
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
11
|
+
# require 'override'
|
12
|
+
#
|
13
|
+
# @user = User.spawn
|
14
|
+
# override(@user, :name => "Foobar", :email => "foobar@example.org")
|
15
|
+
# override(User, :find => @user)
|
16
|
+
#
|
17
|
+
# Or alternatively:
|
18
|
+
#
|
19
|
+
# override(User, :find => override(User.spawn, :name => "Foobar, :email => "foobar@example.org"))
|
14
20
|
#
|
15
21
|
# In case you don't know what spawn means, check my other library for
|
16
22
|
# testing at http://github.com/soveran/spawner.
|
@@ -28,4 +34,5 @@ def override object, methods
|
|
28
34
|
result
|
29
35
|
end
|
30
36
|
end
|
37
|
+
object
|
31
38
|
end
|
data/test/all_test.rb
CHANGED