How do I trace which file RSpec is loading?
I'm using Rails 3.0.1, RSpec-Rails 2.0.1 and Webrat 0.7.1. I have the following test:
describ开发者_JAVA百科e PagesController do
describe "GET 'main'" do
it "should have the right title" do
get 'main'
response.should have_selector("title", :content => "My title")
end
end
end
The HTML of pages#main checks out: it contains My Title. When I run rspec, it gives me a failure on this test, and says it expects to find the tag in the following line:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
Since this is not the file stored at pages#main, I take it that rspec is, for some reason, loading the wrong page. How do I solve this? Or, failing a general solution, how can I get rspec to tell me which page it is trying to load, so that I can try to figure out why it is going to this other page? Thanks.
You need to tell RSpec to render the views:
describe PagesController do
render_views # Add this line to tell RSpec to render the views
describe "GET 'main'" do
.
.
end
Here is a better way to post log/test.log:
Processing by PagesController#main as HTML
Rendered pages/main.html.erb within layouts/application (0.4ms)
Completed 200 OK in 5ms (Views: 5.1ms | ActiveRecord: 0.0ms)
Processing by PagesController#main as HTML
Completed 200 OK in 1ms (Views: 0.9ms | ActiveRecord: 0.0ms)
It looks to me like the first one results in a page being rendered - what is the second call for?
精彩评论