Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

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

#6

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.

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

State: new
Milestone: none
Assigned to: nobody

Activity

No comments yet.

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.