繁体   English   中英

简单的RSpec测试失败

[英]Simple RSpec tests 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

当我运行rspec时,总是得到:

1)SessionsController GET'new'应该具有正确的标题失败/错误:response.should have_selector(“ title”,:content =>“登录
)预期以下输出包含一个Sign in标签:w3.org/TR/REC-html40/loose.dtd“>#./spec/controllers/sessions_controller_spec.rb:14:在“

当我访问会话/新页面时,该页面包含一个标题标签,如下所示:

<title>Ruby on Rails Tutorial Sample App | Sign in</title> 

为什么所有其他类似(= title标签的测试)测试都能正常工作,而这些测试却失败了?

这是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

我在这里做错了什么?

谢谢你的帮助

您需要将render_views添加到类的顶部。 没有它,将不会生成实际的html,并且have_selector测试将失败。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM