Linus Oleander
Linus Oleander

Reputation: 18127

Test arguments in Rspec?

Is it possible to check what arguments is being passed to a method when testing with rspec?

If I for i.e want to test class A, inside class A i call class B, B is already tested. The only thing I want to test is the ingoing arguments to B.

class A
  def method
    number = 10
    B.calling(number)
  end
end

class B
  def self.calling(argument)
    # This code in this class is already testet
  end
end

How do I test the ingoing arguments to B.calling?

Upvotes: 2

Views: 3650

Answers (1)

nruth
nruth

Reputation: 1068

if you're using rspec mock/stubs try

B.should_receive(calling).with(10)

http://kerryb.github.com/iprug-rspec-presentation/ covers a lot of basic usage, or see the docs or rspec book.

Upvotes: 2

Related Questions