teaspoon icon indicating copy to clipboard operation
teaspoon copied to clipboard

teaspoon 1.2.0 causes Teaspoon::EnvironmentNotFound error

Open benbcai opened this issue 4 years ago • 13 comments

I am getting the following Teaspoon::EnvironmentNotFound error when using version 1.2.0 of teaspoon that just got released yesterday. The error is coming from find_env. My project does have the teaspoon_env.rb file in the spec folder. The error does not occur when locking the version to 1.1.5.

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

/usr/local/bundle/gems/teaspoon-1.2.0/lib/teaspoon/environment.rb:39:in `find_env'

/usr/local/bundle/gems/teaspoon-1.2.0/lib/teaspoon/environment.rb:24:in `check_env!'

/usr/local/bundle/gems/teaspoon-1.2.0/lib/teaspoon/console.rb:8:in `initialize'

/usr/local/bundle/gems/teaspoon-1.2.0/lib/tasks/teaspoon.rake:14:in `new'

/usr/local/bundle/gems/teaspoon-1.2.0/lib/tasks/teaspoon.rake:14:in `block in <top (required)>'

/usr/local/bundle/gems/rake-12.3.3/exe/rake:27:in `<top (required)>'

/usr/local/bundle/bin/bundle:104:in `load'

/usr/local/bundle/bin/bundle:104:in `<main>'

My project is on the following version of rails and ruby: Rails: v5.2.4.1 Ruby: v2.6

benbcai avatar Mar 03 '20 19:03 benbcai

Interesting. I'll look into it.. does it work if you move it up to the root of the project? (I'm not proposing this as the solution, I'm just trying to understand.)

jejacks0n avatar Mar 03 '20 19:03 jejacks0n

Thanks @jejacks0n for looking into this. I moved teaspoon_env.rb to the project's root folder and still got the same error.

benbcai avatar Mar 03 '20 20:03 benbcai

We faced similar issue in our teaspoon environment. But this does not happen in teaspoon 1.1.5, so we are staying with version 1.1.5. May be something related to env file lookup got changed in the new version of teaspoon

awaismbajwa avatar May 27 '20 11:05 awaismbajwa

looking at the changes between 1.1.5 and 1.2.0 I believe you should be able to set ENV["TEASPOON_ENV"] to the path to your env file as a work around.

the problem was likely introduced around this change https://github.com/jejacks0n/teaspoon/commit/5b912da349a11d12ccdf1705a1aeb79e4f1e3a57

but i'm not finding exactly what is wrong.

mathieujobin avatar Mar 11 '21 04:03 mathieujobin

@benbcai can you please test with 1.2.1 and 1.2.2 ?

thanks

mathieujobin avatar Mar 16 '21 09:03 mathieujobin

Hi guys! Is this issues was resolved? Have same error rails 6.1 ruby 2.7 Thanks

transfer76 avatar Jun 15 '22 14:06 transfer76

I'm not too sure, I don't have this problem. I am also running Rails 6.1 and ruby 2.7

    teaspoon (1.2.2)
    teaspoon-jasmine (2.9.1)

and my config looks like this

Teaspoon.configure do |config|

  config.mount_at = "/teaspoon"

  config.root = nil

  config.asset_paths = ["spec/javascripts", "spec/javascripts/stylesheets"]

  config.fixture_paths = ["spec/javascripts/fixtures"]

  config.suite do |suite|

    suite.use_framework :jasmine, "1.3.1"

    suite.matcher = nil

    suite.helper = "spec_helper"

    suite.boot_partial = "boot"

    suite.body_partial = "body"

  end

  config.driver = :phantomjs

  config.coverage do |coverage|

  end
end

I run RAILS_ENV=test teaspoon with xvfb

mathieujobin avatar Jun 15 '22 23:06 mathieujobin

looking at the changes between 1.1.5 and 1.2.0 I believe you should be able to set ENV["TEASPOON_ENV"] to the path to your env file as a work around.

the problem was likely introduced around this change 5b912da

but i'm not finding exactly what is wrong.

What is wrong is: if an engine overrides Rails.root then teaspoon 1.2 is breaking the engine with Teaspoon::EnvironmentNotFound error. I think this change is breaking and teaspoon 1.2 should have been teaspoon 2.0.

Additionally I think Teaspoon.root should not be relevant when looking for teaspoon_env.rb. What should be relevant is only current directory.

Why? Because Teaspoon.root is defined in teaspoon_env.rb so it can not be used to locate teaspoon_env.rb. And Rails.root has been overridden in many engines.

marko-avlijas avatar Oct 05 '22 11:10 marko-avlijas

Why would an engine override Rails.root?

I kind of understand the point you're making, but like.. put the file in the path relative to whatever is returned in Rails.root, overridden, or otherwise. Right?

I'm totally open to a change if there's one that makes more sense.

jejacks0n avatar Oct 05 '22 15:10 jejacks0n

Why would an engine override Rails.root?

Why would rails root be overridable if i'ts bad or not necessary? :)

To answer your question: I don't know. I am new to the company and I've seen it overridden in many places with comment it's for testing. I just know I've encountered this issue when upgrading to rails 6.

marko-avlijas avatar Oct 05 '22 15:10 marko-avlijas

I mean, kinda -- but not kinda either. 😂

main:0> Rails.root()
=> #<Pathname:/Users/jejacks0n/Projects/okbro>
main:0> Rails.root = "foo"
NoMethodError: undefined method `root=' for Rails:Module
Did you mean?  root
from (pry):3:in `__pry__'

I also notice that Rails.root and Rails.version are right next to each other in the documentation -- does that mean I can go upgrading my project by setting my rails version directly? No, it doesn't.

Put your configuration file relative to Rails.root, wherever that might be, and symlink it elsewhere if must live elsewhere but I really don't understand why trying to stub or override Rails.root would ever be very wise. Teaspoon can't guess as to where you have the file. It used to be relative to Dir.pwd but that didn't work with nested rails projects and other complex scenarios.

jejacks0n avatar Oct 05 '22 15:10 jejacks0n

It's done like this: Rails.application.config.root = 'whatever/i/want' :smile:

TBH I don't know why you would do that, but I suspect everyone in this thread experiencing this issue has rails root changed whether they know it or not.

If anything I can suggest improving error message to include what folder it was looking in.

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

After: Unable to locate environment; searched inside /Users/rails-root-changer/work/strange_engine/overridden_root/ for [spec/teaspoon_env.rb, test/teaspoon_env.rb, teaspoon_env.rb]. Have you run the installer?

marko-avlijas avatar Oct 05 '22 16:10 marko-avlijas

That's a fair opinion and feedback @marko-avlijas. A PR with that would for sure get merged.

jejacks0n avatar Oct 06 '22 15:10 jejacks0n