I am trying to get my test suite working and am having some issues.
#home_controller_spec.rb
require 'spec_helper'
describe HomeController do
describe "GET 'index'" do
it "should be successful" do
get 'index'
response.should be_success
end
it "should have the right h2" do
get 'index'
response.should have_selector('h2', :content => 'Home')
end
end
end
The first test works and passes just fine. Any time I try to run
response.should have_selector('[anything]')
it gives this error:
2) HomeController GET 'index' should have the right h2
Failure/Error: res开发者_StackOverflowponse.should have_selector('h2','Home')
expected css "Home" to return something
# ./spec/controllers/home_controller_spec.rb:12:in `block (3 levels) in <top (required)>'
I'm using Rails 3.1 and RSpec 2.6 and have already uninstalled and reinstalled Rspec. The same result happens in all of my controller tests.
Any ideas how to fix this error?
Thanks in advance!
Edit: Uninstalled all gems. Reinstalled all gems. Re-setup RSpec, Capybara and Guard. Seems to be working now. Thanks for the help. Not sure what was wrong.
By default RSpec doesn't render templates in controller specs. You can either:
1) Move the test into a view spec
2) Add render_views
to the describe block in the controller spec, which will then render the template.
Option 1 is preferred IMO. You could also use a request spec to test for content. If you are writing request specs, view specs are usually superfluous.
With rspec-rails gem V. 2.10.0 It worked good for me
it "should have the right title" do
visit '/pages/howto'
page.should have_selector("title", :text => "Abusa.me | Como funciona?")
end
精彩评论