@request not available in before(:all) but is available in before(:each) in RSpec-Rails

View: New views
3 Messages — Rating Filter:   Alert me  

@request not available in before(:all) but is available in before(:each) in RSpec-Rails

by bcardarella :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

More playing with RSpec-Rails.

I've noticed that I do not have access to the @request object in before
(:all) but do in before(:each)

Is this expected behavior?
_______________________________________________
rspec-users mailing list
rspec-users@...
http://rubyforge.org/mailman/listinfo/rspec-users

Re: @request not available in before(:all) but is available in before(:each) in RSpec-Rails

by David Chelimsky-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Oct 28, 2009, at 2:05 PM, Brian Cardarella wrote:

> More playing with RSpec-Rails.
>
> I've noticed that I do not have access to the @request object in  
> before
> (:all) but do in before(:each)
>
> Is this expected behavior?

Yes. In general, before(:all) is intended for setting global state and  
should only be used for expensive operations like setting up databases  
and network connections. It is true that instance variables created in  
a before(:all) block are copied to each example, but they do not have  
access to the things that are generated per-example, like the request  
object.

HTH,
David
_______________________________________________
rspec-users mailing list
rspec-users@...
http://rubyforge.org/mailman/listinfo/rspec-users

Re: @request not available in before(:all) but is available in before(:each) in RSpec-Rails

by bcardarella :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks again Dave. I'm slowly learning the world of Rspec :)

On Oct 28, 3:43 pm, David Chelimsky <dchelim...@...> wrote:

> On Oct 28, 2009, at 2:05 PM, Brian Cardarella wrote:
>
> > More playing with RSpec-Rails.
>
> > I've noticed that I do not have access to the @request object in  
> > before
> > (:all) but do in before(:each)
>
> > Is this expected behavior?
>
> Yes. In general, before(:all) is intended for setting global state and  
> should only be used for expensive operations like setting up databases  
> and network connections. It is true that instance variables created in  
> a before(:all) block are copied to each example, but they do not have  
> access to the things that are generated per-example, like the request  
> object.
>
> HTH,
> David
> _______________________________________________
> rspec-users mailing list
> rspec-us...@...://rubyforge.org/mailman/listinfo/rspec-users
_______________________________________________
rspec-users mailing list
rspec-users@...
http://rubyforge.org/mailman/listinfo/rspec-users