Search code examples
ruby-on-railscapybarajquery-select2rspec-railsselect2-rails

Why Rspec cannot find the select2 method?


I've just joined a new company and when I'm using the select2 method in Rspec, I get the following error: NoMethodError:undefined method `select2' for...

We use the 'capybara-select-2' gem.

So I added in spec_helper.rb the following config: config.include CapybaraSelect2 and it's perfectly works. Problem, when tests are pushed on heroku, it raises an error: uninitialized constant CapybaraSelect2.

The weird thing is my colleague doesn't need to add the config line for using this method...

Do you have any idea why he can use it without it and I can't? Thanks for your help.


Solution

  • My CTO finally found a way to make my code working:

    I was calling config.include CapybaraSelect2 at the end of spec_helper.rb so he moved it within rails_helper.rb, just as following:

    config.include Devise::Test::IntegrationHelpers
    config.include ActiveSupport::Testing::TimeHelpers
    config.include ::Passwordless::TestHelpers::SystemTestCase
    config.include CapybaraSelect2
    

    Everything works fine now!