使用 Rails3 和 RSpec2 进行 RSpec View 测试
RSpec2 不包含 have_tag
测试助手。使用 webrat 的 have_tag
或 have_selector
匹配器是不可能的,因为 Webrat 和 Rails 3 尚不兼容。有没有办法编写有用的RSpec视图测试?可以使用 assert_select
代替 have_tag
,但首先可以使用 Test::Unit
进行测试。或者不再推荐编写 RSpec 视图测试,因为与 Capybara 或 Cucumber 的集成测试更好?
RSpec2 does not include an have_tag
test helper. Using webrat's have_tag
or have_selector
matchers instead is not possible because Webrat and Rails 3 are not compatible yet. Is there a way to write useful RSpec view tests? It is possible to use assert_select
instead of have_tag
, but then one could Test::Unit
tests in the first place. Or is it no longer recommendable to write RSpec view tests, because integration tests with Capybara or Cucumber are better?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,Webrat 可与 Rails 3 配合使用。我对此进行了测试,并且能够使用 have_selector 匹配器(have_tag 不起作用)。
您可以查看此 Google 网上论坛讨论。基本上,您不需要 webrat 自述文件中提到的 Webrat.configure 块,并按照邮件列表解决方案,在您的 spec_helper.rb 中添加这些行:
如您所见,Webrat 不再更新,所以是的,您使用 Cucumber (+ Capybara) 进行集成测试可能会更好。
Actually, Webrat works with Rails 3. I have tested this and I was able to use the have_selector matcher (have_tag didn't work).
You can take a look at this Google group discussion. Basically, you don't need the Webrat.configure block mentioned in the webrat readme, and following the mailing list solution, add these lines in your spec_helper.rb:
As you can see, Webrat is not so updated anymore, so yes, you might be better off with integration testing with Cucumber (+ Capybara).
Webrat 太麻烦了,用 Capybara 配合 RSpec 也是可以的。 Capybara DSL(具有函数
has_selector?
、has_content?
等)可用于以下 RSpec 测试:spec/requests
、<代码>规范/验收,或规范/集成
。如果您使用最新版本的 Capybara (~> 1.0.1) - 0.4.0 等旧版本将不支持此功能 - 并将以下几行添加到您的
spec_helper.rb
文件中,那么您可以例如编写以下 RSpec 请求测试
Webrat caused too much trouble, it is also possible to use Capybara with RSpec. The Capybara DSL (with the functions
has_selector?
,has_content?
, etc.) is available for the following RSpec tests:spec/requests
,spec/acceptance
, orspec/integration
.If you use the latest version of Capybara (~> 1.0.1) - older versions like 0.4.0 won't support this - and add the following lines to your
spec_helper.rb
filethen you could write for example the following RSpec request test