I’m working on some code that uses association proxies. I’m trying to
get away from using fixtures, and move more to mocking and stubbing.
So far, so good, but the methods I cant figure out, even with
extensive googling, are how to simulate the association_proxy.build
method in rails.
I’m on edge rails and edge rspec.
Datawise, a bar has_many suggested_beers, and a suggested_beer belongs
to a bar
suggested_beers_controller
end
private
def find_bar
@bar = Bar.find(params[:bar_id])
end
suggested_beers_controller_spec.rb
This is generated with rspec_scaffold, and i’ve added in the beer_id,
bar_id, and ip_address attributes for stubbing.
@mock_suggested_beer ||= mock_model(SuggestedBeer, stubs) get :new, :bar_id => "1" response.should render_template('new') end it "should create a new suggested_beer" do
SuggestedBeer.should_receive(:new).and_return(mock_suggested_beer)
get :new, :bar_id => “1”
end
“should create a new suggested_beer” fails with this message
Spec::Mocks::MockExpectationError in ‘SuggestedBeersController
responding to GET /bars/1/suggested_beers/new should create a new
suggested_beer’
Mock ‘SuggestedBeer_1016’ received unexpected message :[]= with
(“bar_id”, 1)
I don’t know how to fix this.
I’ve looked at several articles, specifically
http://www.lukeredpath.co.uk/2007/10/18/demeters-revenge
and Attempting to Make Sense of RSpec use - RSpec - Ruby-Forum
but I’m still confused.
Any help is much appreciated!
Sam Granieri, Jr
[email protected]
Chicago, IL
irc (freenode): samgranieri
http://www.samgranieri.com
http://www.beerbin.com
Recommend me at WWR!
http://www.workingwithrails.com/person/7374-sam-granieri