Why Rspec cannot find the select2 method?

116 Views Asked by At

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.

2

There are 2 best solutions below

0
raphael-allard On BEST ANSWER

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!

1
Thomas Walpole On

Your coworker probably did gem install capybara-select-2 at some point installing it globally into his environment, while you're using it via bundler. You should make sure it has been included into the :test group in your gemfile.

That being said I wouldn't recommend using that gem anymore, it hasn't been updated in years.