#6 new
James Mead

[#16769] how to ensure signature compliance while mocking in ruby

Reported by James Mead | January 1st, 2009 @ 06:47 PM

Date: 2008-01-02 15:56 Opener: James Mead

Submitted on behalf of Pradeep Gatram pradeep.gatram@gmail.com based on ruby-talk thread: http://groups.google.com/group/r...


require 'rubygems'
require 'mocha'
require 'test/unit'

class Foo

 def self.method1
   Bar.method2('param1', 'param2')
 end
 
end

class Bar

  def method2(param1)
  end
  
end

class FooTest < Test::Unit::TestCase
  
  def test_method1
   Bar.expects(:method2).with('param1', 'param2').once
   Foo.method1
  end

end

See http://pastie.textmate.org/133998 for syntax-highlighted version of code.

The above test should give some kind of warning when the expectation for Bar.method2 does not match the signature of the real Bar.method2 method i.e. the arity is different. This should be configurable so as not to upset TDD folk.

No comments found

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

A mocking & stubbing library for Ruby.

* <a href="http://github.com/floehopper/mocha">GitHub repository</a>
* <a href="http://mocha.rubyforge.org">Documentation</a>
* <a href="http://groups.google.com/group/mocha-developer">Mailing List</a>

People watching this ticket

Pages