[rspec-users] Spec'ing Rails request.env params

Pat Maddox pergesu at gmail.com
Thu Feb 14 22:52:11 EST 2008

On Thu, Feb 14, 2008 at 6:45 PM, Mikel Lindsaar <raasdnil at gmail.com> wrote:
> I have an internal system that has a rails controller action that
>  needs to behave differently based on browser type reported by
>  request.env['HTTP_USER_AGENT']
>  But I can't find a way to stub! mock or set this setting from within a spec.
>  Looked through Test::Unit and can't find a straight forward way in there either.
>  Anyone had any luck with this?
>  Mikel
>  _______________________________________________
>  rspec-users mailing list
>  rspec-users at rubyforge.org
>  http://rubyforge.org/mailman/listinfo/rspec-users

I think you can just set it before making a request...

request.env['HTTP_USER_AGENT'] = 'mozilla blah blah'
get :new

I've never had to do it before, but I just tried it and it seems to work.


More information about the rspec-users mailing list