I have this statement in the layout of my application (using haml) - if request.env["HTTP_USER_AGENT"].include?("MSIE") = stylesheet_link_tag ''blueprint/ie.css'' = stylesheet_link_tag ''confirm_ie.css'' The problem is that request.env["HTTP_USER_AGENT"] is nil when I go to some page in the features I write with cucumber and webrat This is the error I get You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.include? (ActionView::TemplateError) On line #23 of layouts/application.html.haml ?How can I stub these methods for the reponse object? Thanks Juan M. Cervera -- Posted via http://www.ruby-forum.com/.
I''m sure it''s possible, but sorry I don''t know how offhand. I''ll tell you what I know and see if it''s enough to help you figure it out for yourself. The code you write in cucumber steps (which calls webrat) runs inside the context of a rails ActionController::Integration::Session. Have a look at the docs for that - somebody must have done this before for rails. You can play with this in script/console by calling the ''app'' object e.g. $ script/console > app.post "/session", :username => ''matt'', :password => ''secret'' If you want it to behave just like in your steps, require ''webrat'' so that the ActionController::Integration::Session class is monkey- patched with the webrat goodness. On 30 Sep 2008, at 15:25, Juanma Cervera wrote:> I have this statement in the layout of my application (using haml) > > - if request.env["HTTP_USER_AGENT"].include?("MSIE") > = stylesheet_link_tag ''blueprint/ie.css'' > = stylesheet_link_tag ''confirm_ie.css'' > > The problem is that request.env["HTTP_USER_AGENT"] is nil when I go to > some page in the features I write with cucumber and webrat > > This is the error I get > You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.include? > (ActionView::TemplateError) > On line #23 of layouts/application.html.haml > > > ?How can I stub these methods for the reponse object? > > Thanks > Juan M. Cervera > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Thanks Matt. I have check the rails api and see that I can pass a hash with the headers as a parameter with the post command. post "/session", {:username => ''matt'', :password => ''secret''}, {:HTTP_USER_AGENT => "MSIE"} and this works for me, by now, I don''t know if I will have some more troubles with webrat. Thanks. -- Posted via http://www.ruby-forum.com/.
Cool. Be aware that you''re by-passing webrat by using the post method - that''s one of the ''raw'' rails calls that webrat wraps up in its elegant set of methods. It may be that you can pass this same hash to clicks_button but I don''t know - you''d have to check the webrat source. On 30 Sep 2008, at 17:21, Juanma Cervera wrote:> Thanks Matt. > I have check the rails api and see that I can pass a hash with the > headers as a parameter with the post command. > > post "/session", > {:username => ''matt'', :password => ''secret''}, > {:HTTP_USER_AGENT => "MSIE"} > > and this works for me, by now, I don''t know if I will have some more > troubles with webrat. > > Thanks. > > > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Well, Matt was right. I have not got the solution for my problems. The problem is that I can''t set the headers with click_button or visits. If anyone knows how to set the request headers with these methods of webrat, this would be very helpful. Thank yus Matt Wynne wrote:> Cool. > > Be aware that you''re by-passing webrat by using the post method - > that''s one of the ''raw'' rails calls that webrat wraps up in its > elegant set of methods. > > It may be that you can pass this same hash to clicks_button but I > don''t know - you''d have to check the webrat source.-- Posted via http://www.ruby-forum.com/.