rsubstitute 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rsubstitute.rb CHANGED
@@ -1,18 +1,16 @@
1
1
  class Call
2
- def initialize(method, *args, &block)
3
- @method, @args, @block = method, args, block
2
+ def initialize(method, args)
3
+ @method, @args = method, args
4
4
  end
5
5
 
6
- def matches(method, *args, &block)
6
+ def matches(method, args)
7
7
  @method == method and args_match(args)
8
8
  end
9
9
 
10
10
  private
11
11
 
12
12
  def args_match(args)
13
- return true if @args == args
14
- return false if @args.nil? or args.nil?
15
- return @args <=> args
13
+ @args == args
16
14
  end
17
15
  end
18
16
 
@@ -40,13 +38,13 @@ class Substitute
40
38
  def method_missing(method, *args, &block)
41
39
  assert_was_received = @assert_next
42
40
  @assert_next = false
43
- if assert_was_received and not @calls.any? {|x| x.matches(method, args, block)}
41
+ if assert_was_received and not @calls.any? {|x| x.matches(method, args)}
44
42
  raise "Call #{method} not received with specified args"
45
43
  end
46
44
 
47
- @calls << Call.new(method, args, block)
45
+ @calls << Call.new(method, args)
48
46
  matching_result_pair = @results.reverse.find do |x|
49
- x[0].matches(method, args, block)
47
+ x[0].matches(method, args)
50
48
  end
51
49
  if (matching_result_pair.nil?)
52
50
  value_to_return = Object.new
@@ -20,7 +20,13 @@ describe "when method is called on substitute" do
20
20
 
21
21
  it "throws when the same method with different args was received" do
22
22
  lambda {
23
- @sub.received.some_method("a")
23
+ @sub.received.some_method(999)
24
+ }.should raise_exception
25
+ end
26
+
27
+ it "throws when the same method with different number of args was received" do
28
+ lambda {
29
+ @sub.received.some_method(123, 2345, 456)
24
30
  }.should raise_exception
25
31
  end
26
32
  end
@@ -34,12 +40,12 @@ describe "when setting a return value for a method" do
34
40
 
35
41
  it "returns that value when called" do
36
42
  result = @sub.some_method(1)
37
- result.should == @value_to_return
43
+ result.should equal @value_to_return
38
44
  end
39
45
 
40
46
  it "returns something else when called with different args" do
41
47
  result = @sub.some_method(2)
42
- result.should != @value_to_return
48
+ result.should_not equal @value_to_return
43
49
  end
44
50
 
45
51
  it "returns a new value when a new value is set for the method" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - David Tchepak
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-09 00:00:00 +10:00
17
+ date: 2010-09-10 00:00:00 +10:00
18
18
  default_executable:
19
19
  dependencies: []
20
20