Skip to content

Instantly share code, notes, and snippets.

@goooooouwa
Last active August 24, 2016 07:40
Show Gist options
  • Save goooooouwa/52686c8e88ec276f011ff9426bbaf957 to your computer and use it in GitHub Desktop.
Save goooooouwa/52686c8e88ec276f011ff9426bbaf957 to your computer and use it in GitHub Desktop.

rspec-rails doesn't require 'rspec-core' intensionally.

So without the 'rspec' command, 'rspec-core' is not required anywhere.

When using RSpec with Cucumber (which doesn't invoke the 'rspec' command'), we need to add 'rspec-expectations' and 'rspec-core' in Gemfile, so that bundler will auto-require them into Rails environment.

Why add a gem in Gemfile if it's already dependented by another gem? Being dependented only get it being installed, but not required. It's the depending gem's responsiblity to require the depedented gem. In this case, though 'rspec-rails' depends on 'rspec-core', it doesn't require 'rspec-core' in code (as explained above). So we need to add them to Gemfile, or require them explicitly somewhere in the codebase.

So if If you want to use rspec-core, you need to add it to your Gemfile. Cucumber will automatically load rspec-core's methods to be available in your step definitions. https://github.com/cucumber/cucumber/wiki/RSpec-Expectations

Root Cause

Explaination

rspec-rails gem does not require 'rspec-core' directly in code. It does that by depending on the 'rspec' command, which loads rspec-core before doing anything else. rspec/rspec-rails#1558 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment