RailsTutorial 3.2 Ch 9 - “before { valid_signin(user) }"导致 RSpec 测试失败 [英] RailsTutorial 3.2 Ch 9 - "before { valid_signin(user) }" causes RSpec test to fail

查看:33
本文介绍了RailsTutorial 3.2 Ch 9 - “before { valid_signin(user) }"导致 RSpec 测试失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用 RailsTutorial 3.2,第 9.3.1 节用户索引.

I'm currently in RailsTutorial 3.2, Section 9.3.1 User Index.

清单 9.27 指示对 spec/requests/authentication_pages_spec.rb 代码进行如下

Listing 9.27 directs an edit to the spec/requests/authentication_pages_spec.rb code as follows:

require 'spec_helper'

describe "Authentication" do
    .
    .
    .
    describe "with valid information" do
      let(:user) { FactoryGirl.create(:user) }
      before { valid_signin(user) }

      it { should have_selector('title', text: user.name) }

      it { should have_link('Users',    href: users_path) }
      it { should have_link('Profile',  href: user_path(user)) }
      it { should have_link('Settings', href: edit_user_path(user)) }
      it { should have_link('Sign out', href: signout_path) }

      it { should_not have_link('Sign in', href: signin_path) }
      .
      .
      .
    end
  end
end

执行此操作后,相应部分的测试失败.我一直非常忠实地遵循教程,所以我的代码和设置在其他方面几乎相同.

After doing this, the corresponding section of tests fails. I have been following the tutorial very faithfully, so my code and setup are otherwise pretty much identical.

在测试了一些东西之后,我发现改变

After testing a few things out, I've found that changing the

before { valid_signin(user) } 

要读的行

before { sign_in user }

反而会让所有测试再次通过.valid_signin(user) 行是否在语法上有问题,或者这是否表明我的代码中的其他地方存在错误?

instead will make all the tests pass again. Is there something about the valid_signin(user) line that is off syntactically, or does this point to an error elsewhere in my code?

(该应用程序完全按照预期工作,只是测试表明它没有.)

(The app works exactly like it's supposed to, it's just the test that says it doesn't.)

推荐答案

如果您查看清单 8.34,您将在 spec/support/utilities.rb 文件中看到 valid_signin 的定义.

If you look at listing 8.34 you will see the def of valid_signin in the spec/support/utilities.rb file.

这篇关于RailsTutorial 3.2 Ch 9 - “before { valid_signin(user) }"导致 RSpec 测试失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆