Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

teaspoon 1.2.0 causes Teaspoon::EnvironmentNotFound error #576

Open
benbcai opened this issue Mar 3, 2020 · 13 comments
Open

teaspoon 1.2.0 causes Teaspoon::EnvironmentNotFound error #576

benbcai opened this issue Mar 3, 2020 · 13 comments

Comments

@benbcai
Copy link

benbcai commented Mar 3, 2020

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

@jejacks0n
Copy link
Owner

jejacks0n commented Mar 3, 2020

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.)

@benbcai
Copy link
Author

benbcai commented Mar 3, 2020

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

@awaismbajwa
Copy link

awaismbajwa commented May 27, 2020

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

@mathieujobin
Copy link
Collaborator

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.

@mathieujobin
Copy link
Collaborator

@benbcai can you please test with 1.2.1 and 1.2.2 ?

thanks

@transfer76
Copy link

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

@mathieujobin
Copy link
Collaborator

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

@marko-avlijas
Copy link

marko-avlijas commented Oct 5, 2022

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.

@jejacks0n
Copy link
Owner

jejacks0n commented Oct 5, 2022

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.

@marko-avlijas
Copy link

marko-avlijas commented Oct 5, 2022

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.

@jejacks0n
Copy link
Owner

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.

@marko-avlijas
Copy link

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

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?

@jejacks0n
Copy link
Owner

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

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

No branches or pull requests

6 participants