【问题标题】:Hartl Rails section 8.3 rspec errorHartl Rails 第 8.3 节 rspec 错误
【发布时间】:2012-04-23 18:21:01
【问题描述】:

我正在学习 hartl rails 教程

我在第 8.3 节的末尾,应用程序运行正常,但出现 rspec 错误

1) User pages signup with valid information after saving the user 
 Failure/Error: it { should have_link('Sign out') }
   expected link "Sign out" to return something
 # ./spec/requests/user_pages_spec.rb:48:in `block (5 levels) in <top (required)>'

user_pages_spec.rb 中涉及到的部分是

it "should create a user" do
    expect { click_button submit }.to change(User, :count).by(1)
  end  
  describe "after saving the user" do
    it { should have_link('Sign out') }
  end

我不知道如何解决这个问题。还有其他与此类似的帖子,但唉,我无法让他们的解决方案适用于我的情况。谢谢。

【问题讨论】:

  • 尝试在describelike this 中添加before { click_button submit }。如果这不起作用,您可以发布您的UsersController#create 代码。

标签: ruby-on-rails-3 railstutorial.org


【解决方案1】:

您似乎需要在检查链接之前创建帐户。测试的内容比您发布的要多。这是我在阅读教程时使用的代码的 sn-p。

describe "after saving the user" do
  before { click_button "Create my account" }
  it { should have_link('Sign out') }
end

【讨论】:

  • 我希望“它应该创建一个用户”中的代码来进行创建。不是这样吗?
  • “应该创建用户”测试后,测试条件重置。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-13
  • 1970-01-01
相关资源
最近更新 更多