Reputation: 1308
In a rails app, if I use a different request format for mobiles. e.g. render *.mobile.erb. What are the best practices to write tests for this? I use RSpec and can't find information on how to force it to render mobile views.
Upvotes: 2
Views: 1211
Reputation: 3004
I'm assuming you mean view specs (as opposed to integration tests)? RSpec2's render
method delegates to ActionView::Base#render
so you can pass :file, :template, :format, etc to render
in your view specs. A better approach would probably be to just specify the correct view when describing the spec like so (example ripped form RSpec2's website):
describe "events/index.mobile.erb" do
it "renders _event partial for each event" do
assign(:events, [stub_model(Event), stub_model(Event)])
render
view.should render_template(:partial => "_event", :count => 2)
end
end
For integration tests you will need to set the user-agent. Here is a link to another question that addresses changing the user-agent (it's the same for RSpec): Is it possible to specify a user agent in a rails integration test or spec?
Best of luck!
Upvotes: 4
Reputation: 663
I don't know the exact answer but just change the user-agent of the request's headers to a mobile's User-agent
Upvotes: 0