DeX*_*eX3 1 rspec ruby-on-rails rspec2 ruby-on-rails-3
我在这里遵循这个教程,到目前为止一切都很顺利.
但是现在我已经进入了会话,一些简单的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
Run Code Online (Sandbox Code Playgroud)
当我运行rspec时,我总是得到:
1)SessionsController GET'new'应该有正确的标题失败/错误:response.should have_selector("title",:content =>"登录
)预期后面的输出包含一个登录标记:w3.org/TR/REC -html40/loose.dtd">#./ spec/control/session_controller_spec.rb:14:在'块(3级)中'
当我访问会话/新页面时,该页面包含如下标题标记:
<title>Ruby on Rails Tutorial Sample App | Sign in</title>
Run Code Online (Sandbox Code Playgroud)
为什么那些测试失败,而所有其他类似的(=标题标签测试)测试工作正常?
这是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
Run Code Online (Sandbox Code Playgroud)
我在这做错了什么?
谢谢你的帮助
归档时间: |
|
查看次数: |
1470 次 |
最近记录: |