Skip to content
This repository

Bundler pre bug #171

Merged
merged 2 commits into from over 2 years ago

4 participants

chaffeqa Paul Annesley Jean Mertz Aslak Hellesøy
chaffeqa

Fixes Bundler --pre issue that only arrises if cucumber-rails is included outside of group :test.

Its a real edge case, but the fix was pretty painless and actually makes the code base more robust.

Basically any require of lib/cucumber/rails.rb will be ignored unless the call is from env.rb.

I also added a warning message to admonish users to put cucumber-rails under group :test (if the edge case is triggered)

chaffeqa

I did create a ticket for bundler btw: bundler/bundler#1448

Aslak Hellesøy aslakhellesoy merged commit c23d391 into from September 23, 2011
Aslak Hellesøy aslakhellesoy closed this September 23, 2011
Paul Annesley
pda commented October 23, 2011

The instructions in the warning message were not enough to prevent the warning for me.

Apart from moving cucumber-rails to a test-only bundler group, I had to prevent it being loaded by Bundler:

gem "cucumber-rails", "~> 1.0", require: false

Here's the backtrace of the warning I was getting prior to adding require: false:

⸩ rspec
/Users/paul/.rbenv/versions/1.9.3-rc1/lib/ruby/gems/1.9.1/gems/bundler-1.1.rc/lib/bundler/runtime.rb:76:in `require'
/Users/paul/.rbenv/versions/1.9.3-rc1/lib/ruby/gems/1.9.1/gems/bundler-1.1.rc/lib/bundler/runtime.rb:76:in `rescue in block in require'
/Users/paul/.rbenv/versions/1.9.3-rc1/lib/ruby/gems/1.9.1/gems/bundler-1.1.rc/lib/bundler/runtime.rb:62:in `block in require'
/Users/paul/.rbenv/versions/1.9.3-rc1/lib/ruby/gems/1.9.1/gems/bundler-1.1.rc/lib/bundler/runtime.rb:55:in `each'
/Users/paul/.rbenv/versions/1.9.3-rc1/lib/ruby/gems/1.9.1/gems/bundler-1.1.rc/lib/bundler/runtime.rb:55:in `require'
/Users/paul/.rbenv/versions/1.9.3-rc1/lib/ruby/gems/1.9.1/gems/bundler-1.1.rc/lib/bundler.rb:128:in `require'
/Users/paul/org/project/config/application.rb:7:in `<top (required)>'
/Users/paul/.rbenv/versions/1.9.3-rc1/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/paul/.rbenv/versions/1.9.3-rc1/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/paul/org/project/config/environment.rb:2:in `<top (required)>'
/Users/paul/.rbenv/versions/1.9.3-rc1/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/paul/.rbenv/versions/1.9.3-rc1/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/paul/org/project/spec/spec_helper.rb:8:in `<top (required)>'
/Users/paul/.rbenv/versions/1.9.3-rc1/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/paul/.rbenv/versions/1.9.3-rc1/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/paul/org/project/spec/models/example_spec.rb:1:in `<top (required)>'
/Users/paul/.rbenv/versions/1.9.3-rc1/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.0/lib/rspec/core/configuration.rb:459:in `load'
/Users/paul/.rbenv/versions/1.9.3-rc1/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.0/lib/rspec/core/configuration.rb:459:in `block in load_spec_files'
/Users/paul/.rbenv/versions/1.9.3-rc1/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.0/lib/rspec/core/configuration.rb:459:in `map'
/Users/paul/.rbenv/versions/1.9.3-rc1/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.0/lib/rspec/core/configuration.rb:459:in `load_spec_files'
/Users/paul/.rbenv/versions/1.9.3-rc1/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.0/lib/rspec/core/command_line.rb:18:in `run'
/Users/paul/.rbenv/versions/1.9.3-rc1/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.0/lib/rspec/core/runner.rb:80:in `run_in_process'
/Users/paul/.rbenv/versions/1.9.3-rc1/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.0/lib/rspec/core/runner.rb:69:in `run'
/Users/paul/.rbenv/versions/1.9.3-rc1/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.0/lib/rspec/core/runner.rb:10:in `block in autorun'

WARNING: Cucumber-rails required outside of env.rb.  The rest of loading is being defered until env.rb is called.
  To avoid this warning, move 'gem cucumber-rails' under only group :test in your Gemfile
Jean Mertz

same here, I already had the gem in the test group, but that didn't stop this message from showing up. using require: false solved this for now.

Aslak Hellesøy

What kind of ruby syntax is require: false ? Is that a new way to make a Hash?

Jean Mertz

Yes, it's the Ruby 1.9 style of assigning values in a hash. See here for the best explanation on the entire web.

chaffeqa

Sorry for taking so long to get back about this...

I'm guessing that since you use require: false the cucumber-rails lib isn't getting loaded by bundler.

Could you try it without the require: false and get back to me about whether it worked?

Aslak Hellesøy

Folks, please open a new ticket. This is a closed pull request.

Lewis Marshall lmars referenced this pull request from a commit January 30, 2014
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
28  features/fixing_bundler_pre.feature
... ...
@@ -0,0 +1,28 @@
  1
+Feature: Fixing Bundler Pre
  2
+  In order to keep fix a problem with bundler and rails
  3
+  As a user with cucumber-rails outside of test group in my Gemfile
  4
+  I want run features without errors
  5
+  
  6
+  
  7
+  Scenario: Install Cucumber-Rails with bundler prerelease
  8
+    Given I am using bundler prerelease
  9
+    And I have created a new Rails 3 app "rails-3-app" with cucumber-rails support and cucumber-rails is outside of test group
  10
+    And I successfully run `rake db:migrate`
  11
+    And I write to "features/tests.feature" with:
  12
+      """
  13
+      Feature: Tests
  14
+        Scenario: Tests
  15
+          When I go to the home page
  16
+      """
  17
+    And I run `bundle exec rake cucumber`
  18
+    Then it should pass with:
  19
+      """
  20
+      1 scenario (1 passed)
  21
+      1 step (1 passed)
  22
+      """
  23
+    And the output should contain "WARNING:"
  24
+    
  25
+  Scenario: Teardown
  26
+    Given I am using stable bundler
  27
+
  28
+
39  features/step_definitions/cucumber_rails_steps.rb
... ...
@@ -1,3 +1,42 @@
  1
+Given /^I have created a new Rails 3 app "([^"]*)" with cucumber\-rails support and cucumber-rails is outside of test group$/ do |app_name|
  2
+  steps %Q{
  3
+    When I successfully run `rails new #{app_name}`
  4
+    Then it should pass with:
  5
+      """
  6
+      README
  7
+      """
  8
+    And I cd to "#{app_name}"
  9
+    And I append to "Gemfile" with:
  10
+      """
  11
+      gem "cucumber-rails", :path => "../../.."
  12
+      gem "capybara", :group => :test
  13
+      gem "rspec-rails", :group => :test
  14
+      gem "database_cleaner", :group => :test
  15
+      gem 'factory_girl', :group => :test
  16
+
  17
+      """
  18
+    And I successfully run `bundle exec rails generate cucumber:install`
  19
+  }
  20
+  if(ENV['ARUBA_REPORT_DIR'])
  21
+    @aruba_report_start = Time.new
  22
+    sleep(1)
  23
+  end
  24
+end
  25
+
  26
+Given /^I am using bundler prerelease$/ do
  27
+  steps %Q{
  28
+    Given I successfully run `gem uninstall bundler`
  29
+    And I successfully run `gem install bundler --pre`
  30
+  }
  31
+end
  32
+
  33
+Given /^I am using stable bundler$/ do
  34
+  steps %Q{
  35
+    Given I successfully run `gem uninstall bundler`
  36
+    And I successfully run `gem install bundler`
  37
+  }
  38
+end
  39
+
1 40
 Given /^I have created a new Rails 3 app "([^"]*)" with cucumber\-rails support$/ do |app_name|
2 41
   steps %Q{
3 42
     When I successfully run `rails new #{app_name}`
44  lib/cucumber/rails.rb
... ...
@@ -1,23 +1,29 @@
1  
-require 'rails'
2  
-require 'cucumber/rails/application'
3  
-ENV["RAILS_ENV"] ||= "test"
4  
-ENV["RAILS_ROOT"] ||= File.expand_path(File.dirname(caller.detect{|f| f =~ /\/env\.rb:/}) + '/../..')
5  
-require File.expand_path(ENV["RAILS_ROOT"] + '/config/environment')
6  
-require 'cucumber/rails/action_controller'
  1
+env_caller = File.dirname(caller.detect{|f| f =~ /\/env\.rb:/}) if caller.detect{|f| f =~ /\/env\.rb:/}
  2
+if env_caller
  3
+  require 'rails'
  4
+  require 'cucumber/rails/application'
  5
+  ENV["RAILS_ENV"] ||= "test"
  6
+  ENV["RAILS_ROOT"] ||= File.expand_path(env_caller + "/../..")
  7
+  require File.expand_path(ENV["RAILS_ROOT"] + '/config/environment')
  8
+  require 'cucumber/rails/action_controller'
7 9
 
8  
-if defined?(ActiveRecord::Base)
9  
-  require 'rails/test_help'
10  
-else
11  
-  require 'action_dispatch/testing/test_process'
12  
-  require 'action_dispatch/testing/integration'
13  
-end
  10
+  if defined?(ActiveRecord::Base)
  11
+    require 'rails/test_help'
  12
+  else
  13
+    require 'action_dispatch/testing/test_process'
  14
+    require 'action_dispatch/testing/integration'
  15
+  end
14 16
 
15  
-if !Rails.application.config.cache_classes
16  
-  warn "WARNING: You have set Rails' config.cache_classes to false (most likely in config/environments/cucumber.rb).  This setting is known to cause problems with database transactions. Set config.cache_classes to true if you want to use transactions.  For more information see https://rspec.lighthouseapp.com/projects/16211/tickets/165."
17  
-end
  17
+  if !Rails.application.config.cache_classes
  18
+    warn "WARNING: You have set Rails' config.cache_classes to false (most likely in config/environments/cucumber.rb).  This setting is known to cause problems with database transactions. Set config.cache_classes to true if you want to use transactions.  For more information see https://rspec.lighthouseapp.com/projects/16211/tickets/165."
  19
+  end
18 20
 
19  
-require 'cucumber/rails/world'
20  
-require 'cucumber/rails/hooks'
21  
-require 'cucumber/rails/capybara'
  21
+  require 'cucumber/rails/world'
  22
+  require 'cucumber/rails/hooks'
  23
+  require 'cucumber/rails/capybara'
22 24
 
23  
-require 'cucumber/web/tableish'
  25
+  require 'cucumber/web/tableish'
  26
+else
  27
+  warn "WARNING: Cucumber-rails required outside of env.rb.  The rest of loading is being defered until env.rb is called.
  28
+  To avoid this warning, move 'gem cucumber-rails' under only group :test in your Gemfile"
  29
+end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.