Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails教程:第8.1.5章错误(使用flash消息渲染;清单8.11和8.12)_Ruby On Rails_Ruby On Rails 3_Testing_Rspec Rails_Railstutorial.org - Fatal编程技术网

Ruby on rails Rails教程:第8.1.5章错误(使用flash消息渲染;清单8.11和8.12)

Ruby on rails Rails教程:第8.1.5章错误(使用flash消息渲染;清单8.11和8.12),ruby-on-rails,ruby-on-rails-3,testing,rspec-rails,railstutorial.org,Ruby On Rails,Ruby On Rails 3,Testing,Rspec Rails,Railstutorial.org,我正在学习RoR教程。在第8.1.5章的最后一部分,当所有rspec测试都变为绿色时,我的测试就不能工作了。我运行bundle exec rspec spec/requests/authentication_pages_spec.rb-e“使用无效信息登录”,在四个测试中,有一个测试失败,出现以下错误: 1) Authentication signin with invalid information after visiting another page Failure/Error: it

我正在学习RoR教程。在第8.1.5章的最后一部分,当所有rspec测试都变为绿色时,我的测试就不能工作了。我运行bundle exec rspec spec/requests/authentication_pages_spec.rb-e“使用无效信息登录”,在四个测试中,有一个测试失败,出现以下错误:

1) Authentication signin with invalid information after visiting another page 
 Failure/Error: it { should_not have_selector('div.alert.alert-error') }
   expected css "div.alert.alert-error" not to return anything
 # ./spec/requests/authentication_pages_spec.rb:25:in `block (5 levels) in <top (required)>'
如果你有任何想法或想法,请让我知道,我完全被难住了

更换

it { should_not have_selector('div.alert.alert-error') }

我克隆并发现了你的问题

头文件中的链接(app/views/layouts/_header.html.erb)不会出现在任何地方:

<li><%= link_to "Home",    '#' %></li>
<li><%= link_to "Help",    '#' %></li>
…但是当你点击一个没有任何地方的链接时

  describe "after visiting another page" do
    before { click_link "Home" } # goes nowhere
    it { should_not have_selector('div.alert.alert-error') }
  end
end
…该错误仍在页面上,因此测试将正确失败

一旦您将
“主路径”
链接目的地从
“#”
更改为
根路径
,您的测试应该通过

看看课文,如果你在第8章,你似乎错过了几章中的一个步骤,所以一旦你回到并修复它,你应该处于一个更好的状态


我还建议安装
launchy
gem,以便您可以在测试中调用有用的水豚方法,如
save_和_open_页面
,它将为您打开一个浏览器,显示您调用该方法时页面的状态;对调试有很大帮助。

很难查看代码并准确地看到问题所在。你能把你的代码上传到GitHub上,并在你的问题中提供一个链接,这样我们就可以自己复制它了吗?Ryan,GitHub链接在这里:Paul——非常感谢。它起作用了!我不知道为什么我想不出来,但是谢谢你让我知道——我被难住了好几天!别担心。享受本教程其余部分的乐趣!
it { should_not have_selector('div.alert.alert-error', text: 'Invalid') }
<li><%= link_to "Home",    '#' %></li>
<li><%= link_to "Help",    '#' %></li>
describe "with invalid information" do
  before { click_button "Sign in" }

  it { should have_selector('title', text: 'Sign in') }
  it { should have_selector('div.alert.alert-error', text: 'Invalid') }
  describe "after visiting another page" do
    before { click_link "Home" } # goes nowhere
    it { should_not have_selector('div.alert.alert-error') }
  end
end