[rspec-users] mock weirdness

Nikolay Sturm forum at erisiandiscord.de
Mon Aug 22 06:11:18 EDT 2011


Hi,

I have a strange problem with mocking an object that has a method called
'load'. With Rails 2.3 and rspec-rails 1.3 I could do sth like this:

describe Foo do
  let(:bar) { mock(Bar).as_null_object }
  before(:each) do
    Bar.stub(:new).and_return(bar)
  end

  it 'does something' do
    Foo.do_something
  end
end

with

class Foo
  def do_something
    bar = Bar.new
    bar.load
  end
end

After an upgrade to rails 3.0.10 and rspec-rails 2.6.1 I get an
ArgumentError:
  wrong number of arguments (0 for 1)

If I add "bar.method(:load)" to do_something(), it prints

#<Method: RSpec::Mocks::Mock(ActiveSupport::Dependencies::Loadable)#load>

which doesn't look right to me. I am using ree-1.8.7-2011.03.

Does anyone have an idea what this is about and how to properly deal
with this?

cheers,

Nikolay

--
"It's all part of my Can't-Do approach to life." Wally


More information about the rspec-users mailing list