[rspec-users] Controller Spec & DataMapper Chaining

Ken Chien ken.chien at gmail.com
Fri Mar 18 11:46:14 EDT 2011


What problems are you running into?

It appears that you should stub out Widget.all before all examples, unless
you really want to hit the database.


Ken


2011/3/18 Sid Wood <sidwood2 at gmail.com>

> Hi there,
>
> I'm fairly new to RSpec, and DataMapper and I'm trying to write a
> controller spec for an index action that will include DM query chaining.
>
> Here is a very simplified version of the Controller#index I'm working on
>
>
> def index
>   @widgets = Widget.all(:order => [ :name.asc ])
>   if params[:alpha]
>     @widgets = @widgets.by_alpha(params[:alpha])
>   elsif params[:beta]
>     @widgets = @widgets.by_beta(params[:beta])
>   end
> end
>
> I'm trying to write a spec for this and I'm struggling. It feels like it'll
> be something uber simple but I'm just not getting it.
>
> describe "GET 'index'" do
>   it "should be successful" do
>     get :index
>     response.should be_success
>   end
>
>   it "assigns all widgets as @widgets" do
>     widgets = [Factory.stub(:widget), Factory.stub(:widget)]
>     Widget.stub(:all) { [widgets] }
>     get :index
>     assigns(:widgets).should == [widgets]
>   end
>
>   #...
> end
>
> Any assistance would be greatly appreciated.
>
> Kind regards,
>
> Sid
>
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110318/c0ffcc5f/attachment-0001.html>


More information about the rspec-users mailing list