[英]Simple RSpec tests failing
I'm following this tutorial here, and everything has worked out very well so far. 我在这里关注本教程 ,到目前为止,一切工作都非常顺利。
But now that I've progressed to sessions, some simple rspec tests are failing: 但是,既然我已经进行了会话,那么一些简单的rspec测试就会失败:
describe SessionsController do
#[...]
describe "GET 'new'" do
it "should have the right title" do
get :new
response.should have_selector( "title", :content => "Sign in" )
end
end
#[...]
describe "POST 'create'" do
#[...]
it "should have the right title" do
post :create, :session => @attr
response.should have_selector("title", :content => "Sign in")
end
#[...]
end
end
When I run rspec, I always get: 当我运行rspec时,总是得到:
1) SessionsController GET 'new' should have the right title Failure/Error: response.should have_selector( "title", :content => "Sign in
1)SessionsController GET'new'应该具有正确的标题失败/错误:response.should have_selector(“ title”,:content =>“登录
) expected following output to contain a Sign in tag: w3.org/TR/REC-html40/loose.dtd"> # ./spec/controllers/sessions_controller_spec.rb:14:in `block (3 levels) in ')预期以下输出包含一个Sign in标签:w3.org/TR/REC-html40/loose.dtd“>#./spec/controllers/sessions_controller_spec.rb:14:在“
When I access the sessions/new page, the page contains a title tag like the following: 当我访问会话/新页面时,该页面包含一个标题标签,如下所示:
<title>Ruby on Rails Tutorial Sample App | Sign in</title>
Why do those tests fail, while all other similar (= tests for the title tag) tests work fine? 为什么所有其他类似(= title标签的测试)测试都能正常工作,而这些测试却失败了?
Here's the SessionController: 这是SessionController:
class SessionsController < ApplicationController
def new
@title = 'Sign in'
end
def create
user = User.authenticate( params[:session][:email], params[:session][:password] )
if user.nil?
flash.now[:error] = "Invalid email/password combination."
@title = 'Sign in'
render 'new'
else
sign_in user
redirect_to user
end
end
def destroy
sign_out
redirect_to root_path
end
end
What am I doing wrong here? 我在这里做错了什么?
thx for your help 谢谢你的帮助
You need to add render_views
to the top of the class. 您需要将
render_views
添加到类的顶部。 Without it, the actual html will not be generated and your have_selector
tests will fail. 没有它,将不会生成实际的html,并且
have_selector
测试将失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.