Spec'ing Rails request.env params

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

On Thu, Feb 14, 2008 at 6:45 PM, Mikel L. [email protected]
wrote:

Mikel


rspec-users mailing list
[email protected]
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.

Pat

On Fri, Feb 15, 2008 at 2:52 PM, Pat M. [email protected] wrote:

On Thu, Feb 14, 2008 at 6:45 PM, Mikel L. [email protected] 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.
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.

Thanks Pat, it can’t be that easy… I am SURE I tried that… In
fact, I think it was the first thing I tried… maybe I had a typo and
thought “OK, that doesn’t work, must be something else…” - don’t you
hate that ? :smiley:

I’ll try it out :slight_smile:

Thanks

Mikel