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 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, a
4
- # method and the desired result, and proceeds to rewrite the method in
5
- # the object. It can be used as a stubbing strategy in most cases, and
6
- # I'd say that cases that don't fit this pattern have a very bad smell
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
- # @user = User.spawn
12
- # override(@user, :name => "Foobar", :email => "foobar@example.org")
13
- # override(User, :find => @user)
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
@@ -84,4 +84,10 @@ class TestOverride < Test::Unit::TestCase
84
84
  assert_equal 3, @foo.qux
85
85
  end
86
86
  end
87
+
88
+ context "chaining successive calls" do
89
+ should "return the object and allow chained calls" do
90
+ assert_equal 1, override(@foo, :bar => 1).bar
91
+ end
92
+ end
87
93
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soveran-override
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Martens