Kaminari和Capybara发生冲突 [英] Kaminari and Capybara conflict

查看:97
本文介绍了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发生冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆