简体   繁体   English

控制器中发生错误时,黄瓜仅显示水豚错误

[英]Cucumber only showing Capybara errors when there's an error in a Controller

I keep having an annoying issue with Cucumber. 我一直对黄瓜有烦人的问题。 If there are any errors in the Controller, it only shows the errors raised by capybara. 如果控制器中有任何错误,则仅显示由水豚引发的错误。 I'm sure that's not the way it used to work? 我确定那不是以前的工作方式吗?

For example, if an exception was raised, the only output I see is: expected to find css "h1" with text "blah " 例如,如果引发异常,则我看到的唯一输出是: expected to find css "h1" with text "blah ”的expected to find css "h1" with text "blah

In order to actually see the error, I have to puts page.body in order to see the Controller error 为了真正看到错误,我必须puts page.body才能看到控制器错误

Is this expected behaviour? 这是预期的行为吗?

It is the expected behavior. 这是预期的行为。 Capybara is acting in the role of the user and responding to what it sees back from the server. Capybara扮演用户的角色,并响应其从服务器中看到的内容。 Yes, it is annoying and makes failures hard to debug. 是的,这很烦人,并且使故障难以调试。

After you find the problem using tricks like puts page.body you should improve your lower-level test coverage to detect the cause of the error, giving a more informative failure, and then fix the problem. 在使用puts page.body类的技巧找到问题之后,您应该提高较低级别的测试覆盖率,以检测错误的原因,提供更多有用的信息,然后解决问题。 The better your lower-level test coverage is, the less often you'll have an error in Ruby code when running a full-stack test. 您的低级测试覆盖范围越好,运行全栈测试时,您在Ruby代码中出错的可能性就越小。

By the way, I would characterize this as an issue with full-stack testing (eg Capybara) and not a Cucumber-related issue. 顺便说一下,我将其描述为全栈测试的问题(例如Capybara),而不是黄瓜相关的问题。 Cucumber can run tests that are not full-stack, and you can run full-stack tests outside of Cucumber (eg by using Capybara in RSpec) Cucumber可以运行非全栈测试,并且您可以在Cucumber之外运行全栈测试(例如,通过在RSpec中使用Capybara)

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

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