jejacks0n / teaspoon

Teaspoon: Javascript test runner for Rails. Use Selenium, BrowserStack, or PhantomJS.
1.43k stars 243 forks source link

Teaspoon::EnvironmentNotFound when running rails as a daemon #515

Closed itay-grudev closed 5 years ago

itay-grudev commented 7 years ago

When running rails as a daemon (rails s -d) and I go to http://localhost:3000/teaspoon/ I get the following error:

Unable to locate environment; searched in [spec/teaspoon_env.rb, test/teaspoon_env.rb, teaspoon_env.rb]. Have you run the installer?

teaspoon (1.1.5) lib/teaspoon/environment.rb:41:in `find_env'
teaspoon (1.1.5) lib/teaspoon/environment.rb:24:in `check_env!'
teaspoon (1.1.5) app/controllers/teaspoon/suite_controller.rb:32:in `check_env'

To clarify, the environment file is located at spec/teaspoon_env.rb.

I believe the problem comes from the usage of Dir.pwd in lib/teaspoon/environment.rb:34. When running Rails as a daemon, the current directory is only valid before rails is detached. After that it's behaviour is undefined. On my system it is /. Thus your code is actually looking for the file at the system root path: /spec/teaspoon_env.rb.

It works ok when you replace:

file = File.expand_path(filename, Dir.pwd)

with

file = Rails.root.join(filename)

But of course, since the gem might not be loaded from within Rails you could do:

begin
  file = Rails.root.join(filename)
rescue NameError
  file = File.expand_path(filename, Dir.pwd)
end

P.S. I would've made a PR, but I am not sure this is the most suitable solution, nor was I able to run your specs to verify it passed.

jejacks0n commented 5 years ago

Should be fixed on master now.