How to deal with mocking nested resources in RSpec and Rails? -


i've got nested resource of user reading lists (a user has_many reading lists). i'm trying mock in controller specs, having trouble keeping concise. here's before code #show action:

@reading_lists = mock("reading lists") @reading_lists.stub!(:find).with("1").and_return(@reading_list) @user = mock_model(user, :reading_lists => @reading_lists) user.stub!(:find).with("1").and_return(@user) :show, :user_id => "1", :id => "1" 

which testing:

def show   @user = user.find(params[:user_id])   @reading_list = @user.reading_lists.find params[:id] end 

this seems crazy amount of boilerplate - there better way mock out?

there not better way mock out, right note lot of boiler plate. reason user.reading_lists.find law of demeter violation. whether or not view law of demeter important, mocking through violations of painful.

i'd recommend either using real models or simplifying interaction model. can't how without seeing you're trying specify.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -