soveran-override 0.0.7 → 0.0.8

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.markdown CHANGED
@@ -6,7 +6,7 @@ The as-simple-as-possible-but-not-simpler stubbing library.
6
6
  Description
7
7
  -----------
8
8
 
9
- This is the pure esence of the stubbing concept: it takes an object,
9
+ Override is the essence of the stubbing concept: it takes an object,
10
10
  a hash of methods/results, and proceeds to rewrite each method in the
11
11
  object. It can be used as a stubbing strategy in most cases, and I'd
12
12
  say that cases that don't fit this pattern have a very bad code smell,
@@ -17,8 +17,10 @@ Usage
17
17
 
18
18
  require 'override'
19
19
 
20
+ include Override
21
+
20
22
  user = User.spawn
21
- override(@user, :name => "Foobar", :email => "foobar@example.org")
23
+ override(user, :name => "Foobar", :email => "foobar@example.org")
22
24
  override(User, :find => user)
23
25
 
24
26
  Or alternatively:
@@ -42,8 +44,7 @@ And then, in your tests:
42
44
 
43
45
  assert_equal "Foobar", User.find(1).name
44
46
 
45
- In case you don't know what spawn means, check my other library for
46
- testing at http://github.com/soveran/spawner.
47
+ In case you don't know what spawn means, check my library [Spawner](http://github.com/soveran/spawner).
47
48
 
48
49
  It is a common pattern to set expectations for method calls. You can do
49
50
  it with the `expect` function:
data/lib/override.rb CHANGED
@@ -1,19 +1,21 @@
1
1
  require "rubygems"
2
2
  require "metaid"
3
3
 
4
- def override object, methods
5
- methods.each do |method, result|
6
- result.respond_to?(:to_proc) ?
7
- object.meta_def(method, &result.to_proc) :
8
- object.meta_def(method) { |*_| result }
4
+ module Override
5
+ def override object, methods
6
+ methods.each do |method, result|
7
+ result.respond_to?(:to_proc) ?
8
+ object.meta_def(method, &result.to_proc) :
9
+ object.meta_def(method) { |*_| result }
10
+ end
11
+ object
9
12
  end
10
- object
11
- end
12
13
 
13
- def expect object, method, options
14
- expectation = lambda do |*params|
15
- raise ArgumentError unless params == options[:with]
16
- options[:return]
14
+ def expect object, method, options
15
+ expectation = lambda do |*params|
16
+ raise ArgumentError unless params == options[:with]
17
+ options[:return]
18
+ end
19
+ override(object, method => expectation)
17
20
  end
18
- override(object, method => expectation)
19
21
  end
data/test/all_test.rb CHANGED
@@ -42,6 +42,8 @@ class Callable
42
42
  end
43
43
 
44
44
  class TestOverride < Test::Unit::TestCase
45
+ include Override
46
+
45
47
  context "dealing with arguments" do
46
48
  setup do
47
49
  @foo = Foo.new
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.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Martens