How about:
object.methods.each { |m| object.expects(m).never }
> How about:
> object.methods.each { |m| object.expects(m).never }
That produces a SystemStackError: stack level too deep
see :
$ irb
irb> require 'mocha'
irb> String.methods.each { |m| String.expects(m).never }
SystemStackError: stack level too deep
Alain
It would read terribly inline, but with a helper method it could be
something like:
it "doesn't touch Foo" do
mocking_constant :Foo => mock do
Bar.new.baz
end
end
(I have you passing in a new value for the constant only because I
don't know what would make sense for you. Obviously you could just
default it so you didn't have to pass in a Hash.)
-hume.
require 'rubygems'
require 'test/unit'
require 'mocha'
# insert override_constant implementation here
module FactoryModule
class Factory
end
end
class NoMethodsAtAllTest < Test::Unit::TestCase
def test_no_methods_are_called_on_factory
FactoryModule.override_constant :Factory, mock('Factory') do
FactoryModule::Factory.explode
end
end
end
NoMethodsAtAllTest.new('test_no_methods_are_called_on_factory')
override_constant is a helper i wrote a while back for constants
defined within specific namespaces, I hadn't considered using it to
override full classes, but class names are just constants. Thanks for
the idea Mr. Hume!
Here's the implementation of override_constant
http://www.dweebd.com/ruby/temporarily-modifying-a-constant/