什么是适合 Rails 3 的测试框架?
去年我一直在使用 Ruby On Rails。但是,无法进行单元测试。现在我必须编写单元测试代码。哪个测试框架好,为什么?
有这方面的好的教程吗?
我的系统配置:Ruby 1.9.2、Rails 3、Ubuntu 10
I am working with Ruby On Rails for the last year. But, could not work on Unit Testing. Now I have to write a unit testing code. Which testing framework is good and why?
Is there any good tutorial for this?
My system configuration: Ruby 1.9.2, Rails 3, Ubuntu 10
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第一个技巧是:尝试升级到 Rails 5.x。这是一个很好的做法,可以让您的系统始终保持干净且没有第三方错误。
你最好的朋友永远是 Rails 文档: http://guides.rubyonrails.org/ v3.2/testing.html
最后一种情况如果无法升级,可以使用Minitest/Rspec gems,旧版本兼容当前版本的开发。
要执行集成测试,您可以尝试使用 Capybara 或 Google Chrome Headless。
你可以看看一些大项目是如何做测试的,比如 RubyGems 站点,它是用 RoR 编写的,在 Github 上开放: https://github.com/rubygems/rubygems.org
The first tip is: Try upgrading to Rails 5.x. This is good practice to always leave your system clean and faultless from third parties.
Your greatest friend will always be the rails documentation: http://guides.rubyonrails.org/v3.2/testing.html
In last case if you can not upgrade, you can use the Minitest/Rspec gems, in old versions compatible with the current versions of development.
To perform integration testing you can try using Capybara or Google Chrome Headless.
You can look at how some big projects do tests, like the RubyGems site, which is written in RoR and is open in Github: https://github.com/rubygems/rubygems.org
我在过去两年中一直在使用 Rspec,从我的角度来看,它是我使用过的最简单的 Ruby 测试框架。
在 Rspec 中,您必须使用工厂创建模型对象并在脚本中使用它。
Rspec 中只需要写入 3 个块:
describe
、context
和it
。请参阅 - https://relishapp.com/rspec/ rspec-rails/v/3-0/docs/model-specs
I am using Rspec from last two years and from my point of view it is easiest testing framework for Ruby that I have used.
In Rspec, you have to create objects of your models using
factories
and use it in script.There are only 3 - blocks to write in Rspec :
describe
,context
andit
.Refer - https://relishapp.com/rspec/rspec-rails/v/3-0/docs/model-specs