I am getting an error on the 'response' for...
spec/features/test_name_spec.rb
require "spec_helper"
describe "the signin process", :type => :feature do
it "does not sign me in if I use the wrong password" do
visit '/users/sign_in'
within("#new_user") do
user = Fabricate(:user, email: '[email protected]', password: 'password')
fill_in 'Email', :with => 'user@ example.com'
fill_in 'Password', :with => 'badone'
end
click_button 'Log in'
expect(response).to render_template(:new)
end
end
the gemfile
group :test do
gem 'shoulda-matchers', '~> 2.8', require: false # now loaded inside of spec/spec_helper.rb
gem 'capybara', '~>2.4'
gem 'launchy'
gem 'capybara-email', github: "dockyard/capybara-email"
gem 'database_cleaner', '~> 1.5', '>= 1.5.1'
end
I am confused since the test above this one succeeds using expect but with page
expect(page).to have_content 'Signed in successfully.'
What could be going on here?
EDIT
I have changed it to...
expect(page).to have_content 'Log in'
which is basically the same thing, but I would still like to know why the response is erring. Is it not available in Capybara, or is there another problem why that would not work?
You're writing a feature spec. With feature specs, there is no response object. By design, with a feature spec you don't test using low level concerns such as what template was rendered, but higher level ones such as expected content being on the page.
You may be interested in request specs which map onto rails' integration tests and thus allow specs that span multiple requests but do expose response methods.
However you can't (or at least shouldn't) use capybara (visit, click_button, etc) inside request specs - many hours have been lost to problems that boiled down to mixing integration test language (get, post, response) and capybara. The two exist in completely separate worlds, for example a request triggered by capybara has no effect on response and a request triggered by get has no effect on page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With