1
votes

I've recently had to migrate a project from rails 4.0 to rails 4.1 and in the process I've also updated RSpec to RSpec (3.0.0).

The project previously had the following in certain feature specs being tested with Capybara:

require 'spec_helper' require 'support/integration_helpers.rb'
require 'support/admin_support/admin_user_creation_helpers.rb'

include BuildDefaults

The include BuildDefaults refers to a module spec/support/build_defaults.rb and has various helper methods to ensure that the database has been populated correctly. For some reason this has now stopped working and gives the following error (and stack trace):

path_to/spec/features/admin_features/admin_login_out_spec.rb:4:in <top (required)>': uninitialized constant BuildDefaults (NameError) from /Users/u_name/.rvm/gems/ruby-2.1.2@gemset_name/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:in block in load_spec_files' from /Users/u_name/.rvm/gems/ruby-2.1.2@gemset_name/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:in each' from /Users/u_name/.rvm/gems/ruby-2.1.2@gemset_name/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:in load_spec_files' from /Users/u_name/.rvm/gems/ruby-2.1.2@gemset_name/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:97:in setup' from /Users/u_name/.rvm/gems/ruby-2.1.2@gemset_name/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:85:inrun' from /Users/u_name/.rvm/gems/ruby-2.1.2@gemset_name/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:70:in run' from /Users/u_name/.rvm/gems/ruby-2.1.2@gemset_name/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:38:ininvoke' from /Users/u_name/.rvm/gems/ruby-2.1.2@gemset_name/gems/rspec-core-3.0.2/exe/rspec:4:in <top (required)>' from /Users/u_name/Documents/rails/work/c_central_4.1.1/gemset_name/bin/rspec:7:in ' from /Users/u_name/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in require' from /Users/u_name/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in require' from -e:1:in `'

Would anybody happen to know why this has happened?

I would greatly appreciate any help on the matter.

I have looked at various other SO questions with a similar title as this one but none of them seem to be relevant.

Side note 1

It is worth noting that I have removed Spork from my test environment as it was not playing nicely for some reasons but have instead configured the project to use Spring. Though I don't think that this has anything to do with the issue, I did have to completely rebuild the test environment (running rails g rspec:install for instance) and then used Transpec to update the Rspec syntax.

1

1 Answers

4
votes

Having spent some time looking around for a solution to this I eventually came across the official upgrade documentation (I know, I know).

As it says in the docs,

Default helper files created in RSpec 3.x have changed

In prior versions, only a single spec_helper.rb file was generated. This file has been moved to rails_helper.rb. The new spec_helper.rb is the same standard helper generated by running rspec --init.

This change was made to accomplish two general goals:

  • Keep the installation process in sync with regular RSpec changes

  • Provide an out-of-the-box way to avoid loading Rails for those specs that do not require it

This second point got me thinking about the fact that a feature spec for capybara would need to load the application stack. As such, by loading the rails_helper.rb instead of the spec_helper.rb the spec/support/build_defaults.rb is now included in the load path.

Hope this helps somebody in the future.