[rspec-users] Collection proxies need to be stubbed ?
Francois Beausoleil
francois.beausoleil at gmail.com
Sat Jan 20 23:45:17 EST 2007
Hi all !
I just started writing specs on a new project. I would just like to
validate that this is the way you would write it. I know about mocks,
stubs and expectations. I don't think this is a problem for me.
My question really boils down to:
def index
@projects = current_user.projects.active
end
My spec needs to return the proxy, no ? Here's my code:
context "A logged in user visiting the index action" do
controller_name :dashboard
setup do
@user = mock("user")
controller.stub!(:current_user).and_return(@user)
@user.should_receive(:projects).and_return(projects_proxy = Object.new)
projects_proxy.should_receive(:active).and_return([:a, :b])
get :index
end
specify "should have a list of projects available" do
assigns[:projects].should == [:a, :b]
end
specify "should render the index view" do
controller.should_render :template => "dashboard/index"
end
specify "should be a successful call" do
response.should_be_success
end
end
Thanks !
--
François Beausoleil
http://blog.teksol.info/
http://piston.rubyforge.org/
More information about the rspec-users
mailing list