orangutan 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 0
3
- :patch: 2
3
+ :patch: 3
4
4
  :major: 0
@@ -4,7 +4,7 @@ require 'orangutan/call'
4
4
 
5
5
  module Orangutan
6
6
  class Chantek
7
- attr_reader :calls
7
+ attr_reader :calls, :stubs
8
8
 
9
9
  def initialize
10
10
  @calls = []
@@ -21,8 +21,8 @@ module Orangutan
21
21
  snake = m_info.name.scan(/[A-Z][a-z0-9]*/).map {|a|a.downcase}.join('_').to_sym
22
22
  define_method snake do |*args|
23
23
  yield_container, return_container = __react__(snake, args)
24
- yield yield_container.value if yield_container && block_given?
25
- __return__(method, return_container)
24
+ yield *yield_container.value if yield_container && block_given?
25
+ return __return__(method, return_container)
26
26
  end
27
27
  end
28
28
  end
@@ -45,6 +45,7 @@ module Orangutan
45
45
  return expectation if expectation.matches?(method, *args)
46
46
  end
47
47
  end
48
+ nil
48
49
  end
49
50
  end
50
51
  end
@@ -5,6 +5,12 @@ module Orangutan
5
5
  class Expectation
6
6
  attr_reader :return_container, :yield_container, :raiser
7
7
 
8
+ def initialize
9
+ @return_container = nil
10
+ @yield_container = nil
11
+ @raiser = nil
12
+ end
13
+
8
14
  def receives method
9
15
  @method = method
10
16
  self
@@ -15,12 +21,12 @@ module Orangutan
15
21
  self
16
22
  end
17
23
 
18
- def return value
24
+ def return *value
19
25
  @return_container = Container.new value
20
26
  self
21
27
  end
22
28
 
23
- def yield value
29
+ def yield *value
24
30
  @yield_container = Container.new value
25
31
  self
26
32
  end
@@ -8,13 +8,13 @@ module Orangutan
8
8
 
9
9
  def method_missing method, *args
10
10
  yield_container, return_container = __react__(method, args)
11
- yield yield_container.value if yield_container && block_given?
11
+ yield *yield_container.value if yield_container && block_given?
12
12
  __return__(method, return_container)
13
13
  end
14
14
  private
15
15
  def __return__ method, return_container
16
- return return_container.value if return_container
17
- return @parent.stub(:"#{@name}/#{method}") if @recursive
16
+ return *return_container.value if return_container
17
+ return @parent.stub(:"#{@name}/#{method}", :recursive => true) if @recursive
18
18
  nil
19
19
  end
20
20
 
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{orangutan}
5
- s.version = "0.0.2"
5
+ s.version = "0.0.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Mark Ryall"]
9
- s.date = %q{2009-05-10}
9
+ s.date = %q{2009-05-11}
10
10
  s.description = %q{A mocking library that supports creation of ironruby mock objects (in addition to pure ruby ones)}
11
11
  s.email = %q{mark@ryall.name}
12
12
  s.extra_rdoc_files = [
@@ -19,7 +19,6 @@ Gem::Specification.new do |s|
19
19
  "lib/orangutan.rb",
20
20
  "lib/orangutan/call.rb",
21
21
  "lib/orangutan/chantek.rb",
22
- "lib/orangutan/clean_slate.rb",
23
22
  "lib/orangutan/container.rb",
24
23
  "lib/orangutan/expectation.rb",
25
24
  "lib/orangutan/raiser.rb",
@@ -21,17 +21,40 @@ describe Orangutan::Chantek, 'creating ruby stubs' do
21
21
  @o.when(:foo).receives(:bar).return('baz')
22
22
  @foo.bar.should == 'baz'
23
23
  end
24
+
25
+ it 'should allow multiple method return values to be stubbed' do
26
+ @o.when(:foo).receives(:bar).return('baz', 'bat')
27
+ @foo.bar.should == ['baz', 'bat']
28
+ end
24
29
 
25
30
  it 'should allow method return values to be stubbed for method invocations with specific arguments' do
26
31
  @o.when(:foo).receives(:bar).with(7).return('baz')
27
32
  @foo.bar(7).should == 'baz'
28
33
  end
34
+
35
+ it 'should not match method invocations with incorrect specific arguments' do
36
+ @o.when(:foo).receives(:bar).with(7).return('baz')
37
+ @foo.bar(8).should == nil
38
+ end
39
+
40
+ it 'should allow method return values to be stubbed for method invocations with multiple specific arguments' do
41
+ @o.when(:foo).receives(:bar).with(7,8).return('baz')
42
+ @foo.bar(7,8).should == 'baz'
43
+ end
29
44
 
30
45
  it 'should allow stubbed methods to yield' do
31
46
  @o.when(:foo).receives(:bar).with(7).yield('baz')
32
- a = nil
33
- @foo.bar(7) {|s| a = s}
34
- a.should == 'baz'
47
+ @foo.bar(7) do |v|
48
+ v.should == 'baz'
49
+ end
50
+ end
51
+
52
+ it 'should allow stubbed methods to yield multiple values' do
53
+ @o.when(:foo).receives(:bar).with(7).yield('baz', 'bar')
54
+ @foo.bar(7) do |a,b|
55
+ a.should == 'baz'
56
+ b.should == 'bar'
57
+ end
35
58
  end
36
59
 
37
60
  it 'should allow stubbed methods to yield nils' do
@@ -1,3 +1,5 @@
1
+ require 'orangutan'
2
+
1
3
  module Orangutan
2
4
  describe Chantek, 'creating recursive ruby stubs' do
3
5
  before do
@@ -20,5 +22,10 @@ module Orangutan
20
22
  @o.calls[0].should == Call.new(:foo, :bar,[])
21
23
  @o.calls[1].should == Call.new(:"foo/bar", :baz,[])
22
24
  end
25
+
26
+ it "should create recursive stubs" do
27
+ @foo.a.b.c
28
+ @o.stubs.keys.should == [:foo, :"foo/a", :"foo/a/b", :"foo/a/b/c"]
29
+ end
23
30
  end
24
31
  end
@@ -26,8 +26,12 @@ module Orangutan
26
26
  @e.yield_container.should == nil
27
27
  end
28
28
 
29
- it 'should store yield_value' do
30
- @e.yield(1).yield_container.should == Container.new(1)
29
+ it 'should store yield value' do
30
+ @e.yield(1).yield_container.should == Container.new([1])
31
+ end
32
+
33
+ it 'should store multiple yield values' do
34
+ @e.yield(1,2).yield_container.should == Container.new([1,2])
31
35
  end
32
36
 
33
37
  it 'should not return by default' do
@@ -35,7 +39,11 @@ module Orangutan
35
39
  end
36
40
 
37
41
  it 'should store return value' do
38
- @e.return(1).return_container.should == Container.new(1)
42
+ @e.return(1).return_container.should == Container.new([1])
43
+ end
44
+
45
+ it 'should store multiple return values' do
46
+ @e.return(1,2).return_container.should == Container.new([1,2])
39
47
  end
40
48
 
41
49
  it 'should not raise by default' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orangutan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Ryall
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-10 00:00:00 +10:00
12
+ date: 2009-05-11 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -28,7 +28,6 @@ files:
28
28
  - lib/orangutan.rb
29
29
  - lib/orangutan/call.rb
30
30
  - lib/orangutan/chantek.rb
31
- - lib/orangutan/clean_slate.rb
32
31
  - lib/orangutan/container.rb
33
32
  - lib/orangutan/expectation.rb
34
33
  - lib/orangutan/raiser.rb
@@ -1,32 +0,0 @@
1
- module Orangutan
2
- class CleanSlate
3
- instance_methods.each { |m| undef_method m unless m =~ /^__/ }
4
-
5
- def initialize name, parent, recursive
6
- @name, @parent, @recursive = name, parent, recursive
7
- end
8
-
9
- def method_missing method, *args
10
- yield_container, return_container = __react__(method, args)
11
- yield yield_container.value if yield_container && block_given?
12
- __return__(method, return_container)
13
- end
14
- private
15
- def __return__ method, return_container
16
- return return_container.value if return_container
17
- return @parent.stub(:"@name/method") if @recursive
18
- nil
19
- end
20
-
21
- def __react__ method, args
22
- yield_container, return_value = nil, nil
23
- @parent.calls << Orangutan::Call.new(@name, method, args)
24
- first_match = @parent.first_match(@name, method, args)
25
- if first_match
26
- first_match.raiser.execute if first_match.raiser
27
- yield_container, return_value = first_match.yield_container, first_match.return_value
28
- end
29
- return yield_container, return_value
30
- end
31
- end
32
- end