Permalink
Browse files

Fix Rails already initialized error (again)

The initial fix expanded the test paths, which would break when
distributing from Mac to Linux (/private/tmp instead of /tmp). Now, we
utilize the fact that Cucumber checks for RAILS_ROOT to ensure the
environment isn't loaded twice (by non-unique paths).
  • Loading branch information...
1 parent d840a9d commit 5848c94bfce7896219dd20660392b35f90f3e4fc @sandro committed Jan 7, 2013
Showing with 4 additions and 1 deletion.
  1. +3 −0 lib/specjour/cucumber/preloader.rb
  2. +1 −1 lib/specjour/manager.rb
@@ -3,6 +3,9 @@ module Cucumber
module Preloader
def self.load(paths, output)
Specjour.benchmark("Loading Cucumber Environment") do
+ if defined?(::Rails) && !ENV['RAILS_ROOT']
+ ENV['RAILS_ROOT'] = Rails.root.to_s # Load the current rails environment if it exists
+ end
require 'cucumber' unless defined?(::Cucumber::Cli)
args = paths.unshift '--format', 'Specjour::Cucumber::DistributedFormatter'
cli = ::Cucumber::Cli::Main.new(args, output)
View
@@ -95,7 +95,7 @@ def pid
end
def project_path
- File.expand_path(project_name, File.realpath('/tmp'))
+ File.expand_path(project_name, '/tmp')
@pierreozoux

pierreozoux Jan 8, 2013

Collaborator

Hi,

on my mac (not Gentoo) I've this (strange) error [0]

/tmp/workspace/config/application.rb:38 is : config.action_view.javascript_expansions[:defaults] = nil

I have the feeling that the path is not well loaded for this specifically... I am taking a look to that issue. If you have an idea?

[0] :
/tmp/workspace/config/application.rb:38:in <class:Application>': undefined method[]=' for nil:NilClass (NoMethodError)
from /tmp/workspace/config/application.rb:13:in <module:Seedrs>' from /tmp/workspace/config/application.rb:12:in<top (required)>'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in require' from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:inblock in require'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:236:in load_dependency' from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:inrequire'
from /tmp/workspace/config/environment.rb:2:in <top (required)>' from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:inrequire'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in block in require' from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:236:inload_dependency'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in require' from /tmp/workspace/spec/spec_helper.rb:27:inblock in <top (required)>'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork.rb:24:in prefork' from /tmp/workspace/spec/spec_helper.rb:3:in<top (required)>'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in require' from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:inblock in require'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:236:in load_dependency' from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:inrequire'
from /tmp/workspace/spec/models/user_spec.rb:3:in <top (required)>' from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:245:inload'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:245:in block in load' from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:236:inload_dependency'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:245:in load' from /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:inblock in load_spec_files'
from /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in each' from /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:inload_spec_files'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/bundler/gems/specjour-0cab17b0f2e9/lib/specjour/rspec/preloader.rb:13:in load_spec_files' from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/bundler/gems/specjour-0cab17b0f2e9/lib/specjour/rspec/preloader.rb:5:inblock in load'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/benchmark.rb:295:in realtime' from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/bundler/gems/specjour-0cab17b0f2e9/lib/specjour.rb:86:inbenchmark'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/bundler/gems/specjour-0cab17b0f2e9/lib/specjour/rspec/preloader.rb:3:in load' from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/bundler/gems/specjour-0cab17b0f2e9/lib/specjour/loader.rb:84:inload_app'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/bundler/gems/specjour-0cab17b0f2e9/lib/specjour/loader.rb:22:in start' from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/bundler/gems/specjour-0cab17b0f2e9/lib/specjour/cli.rb:57:inload'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/thor-0.16.0/lib/thor/task.rb:27:in run' from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/thor-0.16.0/lib/thor/invocation.rb:120:ininvoke_task'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/thor-0.16.0/lib/thor.rb:275:in dispatch' from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/thor-0.16.0/lib/thor/base.rb:425:instart'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/bundler/gems/specjour-0cab17b0f2e9/lib/specjour/cli.rb:24:in start' from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/bundler/gems/specjour-0cab17b0f2e9/bin/specjour:5:in

'

@sandro

sandro Jan 10, 2013

Owner

Hmm, not sure about the error. I see spork in your backtrace, maybe we're running into an issue there? Have you tried replacing spork with https://github.com/jstorimer/spin or https://github.com/burke/zeus?

@pierreozoux

pierreozoux Jan 10, 2013

Collaborator

I tried without spork, it's not from there... It's really strange..

@sandro

sandro Jan 12, 2013

Owner

Are we sure that it's this line in particular? If you revert this line in your local copy of the gem, does specjour work as expected?

@pierreozoux

pierreozoux Jan 14, 2013

Collaborator

Yes, If I revert just this line, it works as expected... And the issue is just MacOS (not Gentoo). The response is different : one is /tmp and the other one is /private/tmp. I don't know which Gem can't understand what's /private/tmp ? Just, you can try also to do a pwd /tmp and sudo pwd /tmp the response is different also. But as a normal user, if I go to cd /private/tmpmy system understand it, and as my gem should run as me (normal user)... Strange...

@sergiopatricio

sergiopatricio Mar 18, 2014

@pierreozoux I was investigating this and the problem was on some old tests on our project. It is now fixed and specjour is working fine.

@pierreozoux

pierreozoux Mar 18, 2014

Collaborator

Great! 👍

end
def start

0 comments on commit 5848c94

Please sign in to comment.