[rspec-devel] [ rspec-Bugs-6971 ] and_yield does not work when the arity is -1

noreply at rubyforge.org noreply at rubyforge.org
Tue Dec 5 10:55:44 EST 2006


Bugs item #6971, was opened at 2006-11-29 23:06
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=6971&group_id=797

>Category: mock module
Group: None
>Status: Closed
>Resolution: Accepted
Priority: 3
Submitted By: Brian Takita (btakita)
>Assigned to: Brian Takita (btakita)
Summary: and_yield does not work when the arity is -1

Initial Comment:
def foo(bar)
  bar.call {|*args|}
end

bar = mock("bar)
bar.should_receive(:call).and_yield
foo(bar)  # Mock 'bar' yielded || to block with arity of -1

----------------------------------------------------------------------

>Comment By: David Chelimsky (dchelimsky)
Date: 2006-12-05 15:55

Message:
Patch applied (trunk rev. 1261)

----------------------------------------------------------------------

Comment By: Brian Takita (btakita)
Date: 2006-12-04 06:42

Message:
I attached the patch for fix with its spec.

See spec:
a Mock expectation
- should yield blocks that take a variable number of arguments

and invoke_with_yield in message_expectation.rb

----------------------------------------------------------------------

Comment By: Brian Takita (btakita)
Date: 2006-12-04 06:25

Message:
Right. I feel like this should work.
The block takes a variable number or arguments and I give it
no arguments. In Ruby, I'm able to call a proc that has an
arity of -1 with 0 arguments.

proc {}.call # This works.
proc {||}.call # This works.
proc {||}.call(1) # This does not work.
proc {|*args| }.call # This works.
proc {|arg| }.call # This does not work.

----------------------------------------------------------------------

Comment By: David Chelimsky (dchelimsky)
Date: 2006-12-01 03:03

Message:
As I understand it, this is the correct behavior:

irb(main):021:0> proc {}.arity
=> -1
irb(main):022:0> proc {||}.arity
=> 0
irb(main):023:0> proc {|arg|}.arity
=> 1
irb(main):024:0> proc {|*args|}.arity
=> -1

In your example, you are yielding 0 orgs to a proc with an arity of -1.

Am I missing something?


----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=6971&group_id=797


More information about the rspec-devel mailing list