我将如何测试这个观点?
所以我正在编写我的应用程序,使用 Rails、Cucumber、RSpec 执行功能优先的 BDD。
我的客户要求在您填写字段时计算总数。
我的问题是,这并不是真正的功能,更多的是规范。这与创建发票的功能有关,但我认为这并不能证明整个集成测试的合理性。
这只是正在运行的 JavaScript。
所以我的想法告诉我在视图规范中为此编写一个规范。这是正确的吗?是否可以在 rspec 中测试这些 javascript 案例?
或者我应该进一步隔离它并直接使用 JavaScript 测试框架?
So I'm writing my app doing feature-first BDD with Rails, Cucumber, RSpec.
My client requested that a total gets calculated as you fill in the fields.
My question is, this is not really a feature, more of a spec. This is related to the feature of creating the invoice, but I don't think it justifies a whole integration test.
It's just javascript that's running.
So my mind is telling me to write a spec for this in the view spec. Is this correct? And is it possible to test these javascript cases in rspec?
Or should I isolate this a step further and go straight for a javascript testing framework?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您只是想测试 JavaScript 代码,我推荐 Jasmine。
If you're just trying to test your JavaScript code, I recommend Jasmine.
我真的建议您从计划添加到应用程序中的每个功能开始进行集成测试,它们是了解您试图解决的问题以及与客户沟通软件新功能的宝贵工具。
要在页面上测试 JavaScript,您可能需要查看 Selenium,凭记忆您可以使用 Selenium使用 Capybara 测试网页时,可以替代
Rack::Test
。就 Cucumber 而言,我建议创建一个新的功能文件来创建发票,并设置一个场景来测试当您在字段中输入特定字符串时是否计算出正确的总和。类似:
显然我对您的表单了解不够,不知道需要填写哪些字段,但这是我如何测试它的大致轮廓。我还会在视图规范中进行测试,以确保表单中有计算总价值的部分。
之后,我会在 Jasmine 中编写 Javascript 规范,并实现代码来计算并显示总数。
I'd really recommend you start with integration tests for every feature you plan to add to your app, they're an invaluable tool for understanding the problem your trying to solve and communicating new additions to the software with clients.
To test JavaScript on your page, you may want to look into Selenium, from memory you can use Selenium as a drop in replacement of
Rack::Test
when using Capybara to test web pages.As far as Cucumber goes, I'd suggest making a new feature file for creating the invoice and having a scenario that tests that the correct total total gets calculated when you enter a certain string into a field. Something like:
Obviously I don't know enough about your form to know what fields need to be filled out, but that's a general outline of how I'd test it. I'd also make a test in the view spec to ensure that there is a section for the calculated total value in the form.
After that, I'd drop down to writing specs for the Javascript in Jasmine and implement the code to calculate and display the total.