Yes it's by design, no you cannot circumvent it. What you can do is use mocks 
to avoid expensive DB hits, or have multiple expectations in a single example.

Pat

p.s. This is Ruby, so you absolutely *can* circumvent it. How to do that and 
whether it's worth the trouble is up to you to figure out.



On Oct 12, 2011, at 12:09 PM, nathanvda <nathan...@gmail.com> wrote:

> Nobody?
> 
> On Oct 11, 1:05 pm, nathanvda <nathan...@gmail.com> wrote:
>> I have a simple controller test, containing a.o. the following code:
>> 
>>     context "POST :create" do
>>       before (:each) do
>>         post :create, :user_id => @user.id,
>>              :account => { .. some data ... }
>>       end
>>       it { response.status.should == 201 }
>>       it { response.location.should be_present }
>>     end
>> 
>> Now I thought of a very simple way to speed up this test, and to use a
>> `before(:all)` instead of a `before(:each)`. In that case the POST
>> would only be done once.
>> 
>> So i wrote:
>> 
>>     context "POST :create" do
>>       before (:all) do
>>         post :create, :user_id => @user.id,
>>              :account => { .. some data ... }
>>       end
>>       it { response.status.should == 201 }
>>       it { response.location.should be_present }
>>     end
>> 
>> But then I get the following errors:
>> 
>>      RuntimeError:
>>        @routes is nil: make sure you set it in your test's setup
>> method.
>> 
>> Is this by design? Is there a way to circumvent it?
>> _______________________________________________
>> rspec-users mailing list
>> rspec-us...@rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to