Kaminari和Capybara发生冲突

编程入门 行业动态 更新时间:2024-10-27 06:34:06
本文介绍了Kaminari和Capybara发生冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

水豚的分页方法和Kaminari的分页方法之间似乎存在某种冲突。

I seem to have some sort of conflict between the page method of capybara and the page method of Kaminari.

这就是我的猜测,无论如何,这是错误:

That's what I guessed, anyway, here is the error :

Failure/Error: before { sign_in_as user } ActionView::Template::Error: wrong number of arguments (1 for 0) # ./app/models/feed.rb:9:in `microposts' [Rest of the backtrace]

代码示例:

class Feed def microposts(opts = { urgent: false }) urgent = opts[:urgent] p Microposts.where(id: 1).page # <Capybara::Session> p Microposts.where(id: 1).page(1) # Error end end

如果我删除了分页符,则测试正常。

If I remove the pagination, the test works fine.

我不知道这是怎么可能的,我想水豚正在添加对象范围的页面方法,但是当Kaminari将其页面方法添加到ActiveRecord :: Base时(如果我没记错的话),它应该覆盖水豚的方法。

I don't understand how this is possible, I guess Capybara is adding the "page" method to the Object scope, but as Kaminari add its page method to ActiveRecord::Base (if I recall correctly) it should override Capybara's one.

我没看到有人遇到这种麻烦,这怎么可能?

I did not see anyone having this kind of trouble, how is it possible ?

谢谢。

推荐答案

我对Capybara 2.x遇到了同样的问题

I had the same problem with Capybara 2.x

我的功能规格在规范/功能目录。通过阅读Capybara文档,我意识到,如果您的 spec_helper ,则无需在您的 spec_helper 中包含 Capybara :: DSL 使用功能目录。

My feature specs are in the spec/feature directory. I realised from reading the Capybara documentation that there is no need to include the Capybara::DSL in your spec_helper if your using the features directory. It's already included.

如果您在<$ c $中包含Capybara :: DSL ,则会发出警告。 c> spec_helper 会污染全局名称空间,这就是为什么这是个坏主意!

There is a warning given if you include Capybara::DSL in the spec_helper that it will pollute the global namespace and this is exactly why it's a bad idea!

在Capybara上查看此rspec-rails页面以获取详细信息

更多推荐

Kaminari和Capybara发生冲突

本文发布于:2023-10-22 09:20:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1517098.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发生冲突   Kaminari   Capybara

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!