I have a series of controller tests that have worked in the past. I've just
recently tried to resume using RSpec, and I started by trying to get the
existing tests working. I'm seeing quite consistently that tests involving
controllers are failing, and the problem seems to be with redirection.
Below are some tests from one controller and their failure messages. It
looks to me like the response is a dummy page with an <a> redirecting to
the appropriate page - but I don't know the relevance of that. This
controller is the controller that should handle users who are not logged in
(that is, it is the entry point for the website).
require 'spec_helper'
describe HomeController do
render_views
describe "GET 'index'" do
describe "when not logged in" do
before(:each) do
get 'index'
test_sign_out
end
subject { response }
it { should be_success }
it "should be titled as the app name" do
should have_selector "title", :content => @app_name
end
it "should have a header" do
should have_selector "h1"
end
describe "login form" do
it "should be present" do
should have_selector "form", :action => app_path.sessions_path,
:method => "post" do
it { should have_selector "input", :name => "email", :type =>
"email" }
it { should have_selector "input", :name => "password", :type
=> "password" }
it { should have_selector "input", :name => "remember_me",
:type => "checkbox" }
it { should have_selector "input", :name => "commit", :type =>
"submit", value => "Login" }
it { should have_selector "a", :content => "Forgot password",
:href => app_path.new_password_reset_path }
end
end
end
it "should have a sign up link" do
should have_selector "a", :content => "Sign up NOW!", :href =>
app_path.new_user_path
end
end
...
end
end
1) HomeController GET 'index' when not logged in
Failure/Error: it { should be_success }
expected success? to return true, got false
# ./spec/controllers/home_controller_spec.rb:16:in `block (4 levels)
in <top (required)>'
2) HomeController GET 'index' when not logged in should be titled as the
app name
Failure/Error: should have_selector "title", :content => @app_name
expected following output to contain a <title/> tag:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body>You are being <a
href="https://www.test.host/">redirected</a>.</body></html>
# ./spec/controllers/home_controller_spec.rb:19:in `block (4 levels)
in <top (required)>'
3) HomeController GET 'index' when not logged in should have a header
Failure/Error: should have_selector "h1"
expected following output to contain a <h1/> tag:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body>You are being <a
href="https://www.test.host/">redirected</a>.</body></html>
# ./spec/controllers/home_controller_spec.rb:23:in `block (4 levels)
in <top (required)>'
4) HomeController GET 'index' when not logged in should have a sign up
link
Failure/Error: should have_selector "a", :content => "Sign up NOW!",
:href => app_path.new_user_path
expected following output to contain a <a href='/users/new'>Sign up
NOW!</a> tag:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body>You are being <a
href="https://www.test.host/">redirected</a>.</body></html>
# ./spec/controllers/home_controller_spec.rb:39:in `block (4 levels)
in <top (required)>'
5) HomeController GET 'index' when not logged in login form should be
present
Failure/Error: should have_selector "form", :action =>
app_path.sessions_path, :method => "post" do
expected following output to contain a <form action='/sessions'
method='post'/> tag:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body>You are being <a
href="https://www.test.host/">redirected</a>.</body></html>
# ./spec/controllers/home_controller_spec.rb:28:in `block (5 levels)
in <top (required)>'
--
You received this message because you are subscribed to the Google Groups
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rspec/7449bacf-9385-447a-aad8-69daa8f8ef84%40googlegroups.com.