Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.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 迈克尔·哈特尔';s RubyonRails教程测试失败第8章_Ruby On Rails_Ruby_Rspec - Fatal编程技术网

Ruby on rails 迈克尔·哈特尔';s RubyonRails教程测试失败第8章

Ruby on rails 迈克尔·哈特尔';s RubyonRails教程测试失败第8章,ruby-on-rails,ruby,rspec,Ruby On Rails,Ruby,Rspec,我是新手。我正在学习MichaelHartl的教程,RubyonRails教程-使用Rails学习Web开发(http://ruby.railstutorial.org/). 我试图通过一些测试时发现了一个错误。执行bundle exec rspec时的输出是下一个: .........................................F..... Failures: 1) Authentication signin with invalid information

我是新手。我正在学习MichaelHartl的教程,RubyonRails教程-使用Rails学习Web开发(http://ruby.railstutorial.org/). 我试图通过一些测试时发现了一个错误。执行bundle exec rspec时的输出是下一个:

.........................................F.....

Failures:

  1) Authentication signin with invalid information 
     Failure/Error: it { should have_selector('div.alert.alert-error', text: 'Invalid') }
       expected css "div.alert.alert-error" with text "Invalid" to return something
     # ./spec/requests/authentication_pages_spec.rb:23:in `block (4 levels) in <top (required)>'

Finished in 1.39 seconds
47 examples, 1 failure

Failed examples:

rspec ./spec/requests/authentication_pages_spec.rb:23 # Authentication signin with invalid information
会话\u controler.rb sessions\u helper.rb
如果你需要任何其他文件,请让我知道,我会张贴它。提前谢谢。

我已经浏览了您的代码,除了中的分号之外

 self.current_user = user;
我没有看到任何奇怪的东西。你还没有发布你正在测试的方法

if user && user.authenticate(params[:session][:password])
不过,问题可能就在这里

查找问题的一般步骤:

  • 如果正在使用,请重新启动spark
  • 手动测试失败的规范:功能正常吗
  • 如果没有,请修复它
  • 如果功能正常,但规范仍然失败,请在测试期间使用launchy和save_和open_页面查看页面
补充1:

好吧,那部分在你的说明书里

before { visit signin_path }

describe "with invalid information" do
  before { click_button "Sign in" }

引导您进入SessionController创建操作(因为链接链接到在config/routes.rb中映射的登录路径),并且可能出错的主要逻辑是
user.authenticate(params[:session][:password])
-它由提供了\u secure\u密码。

您好,欢迎使用堆栈溢出
..
在这里不起作用,所以要格式化代码,突出显示它并使用编辑框上方的
{}
控件。谢谢你的建议,韦恩,我很想保留格式。非常感谢你的回答@bento!隐马尔可夫模型。。。问题是我对RubyonRails和Rspec的使用还很陌生,我还不知道如何识别测试中的错误。我不明白Rspec所说的和您所说的方法验证之间有什么关系。显然,该功能正在运行,但根据教程,在执行rspec测试后不应出现错误……正如您所说的@bento,方法authenticate是has_secure_password的一部分,那么,它怎么会出错呢?我一直在开发教程,我在其他部分或rspec测试中得到了一个非常类似的错误,错误非常相似:
1)保存用户失败/错误后,用户页面使用有效信息注册:它{应该有_选择器('div.alert.alert success',text:'Welcome')}预期css“div.alert.alert success”使用文本“欢迎”返回内容#./spec/requests/user_pages_spec.rb:39:in
block(5级)`您是否尝试过保存和打开页面?只需包括launchy gem,并在预期失败之前放置save_和open_页面。说真的,现在我开始相信问题在于css和div.alert.alert-error。我正在Cucumber中开发更多的测试,答案是:
expected css“div.alert.alert error”返回一些内容(RSpec::expections::ExpectationNotMetError)/features/step\u definitions/authentication\u steps.rb:10:in'/^他应该会看到一条错误消息$/'features/signing\u in.feature:6:in'他应该会看到一条错误消息'
我要试试你说的关于保存和打开页面的内容。我以前从没听说过这件事,但我不会因为尝试而失去任何东西。非常感谢
 self.current_user = user;
if user && user.authenticate(params[:session][:password])
before { visit signin_path }

describe "with invalid information" do
  before { click_button "Sign in" }