Kaminari and Capybara conflict

纵然是瞬间 提交于 2019-12-04 10:07:32

I had the same problem with Capybara 2.x

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.

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!

Check out this rspec-rails page on Capybara for details

This is a little bit of a hack but I was able to work around the problem (where Capybara 'pollutes' the object space) by undef-ing the method in my spec:

# Capybara adds a 'page' method to the Object class which conflicts with the Kaminari scope
# Remove it here to allow things to work
Object.send :undef_method, :page

I have traced back where this is happening and essentially:

  1. The #page method comes from Capybara::DSL
  2. The Capybara::DSL method is included into the Object class via RSpec's #configure.include method (see lib/capybara/rspec.rb).
  3. RSpec then includes it into the 'group', however I believe this is where it drops into Object.

The solution here might just be to change the name of the method in Capybara, but I guess thats not a decision I'm willing to make :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!