connorshea / vscode-ruby-test-adapter

A Ruby test adapter extension for the VS Code Test Explorer
https://marketplace.visualstudio.com/items?itemName=connorshea.vscode-ruby-test-adapter
MIT License
85 stars 52 forks source link

Broken behavior when opening from UI vs opening from terminal #27

Open smrtsmrf opened 5 years ago

smrtsmrf commented 5 years ago

I am using rvm for different ruby versions with different projects, and I'm using a mac.

When I open up vs code from the terminal using code ., everything works perfectly.

However, when I open up vs code from the spotlight/dock, the test explorer doesn't work. I've checked and in vs code integrated terminal all the environment variables and ruby version are setup correctly. Somehow it seems though that the extension is looking in the wrong place for things. This is the error I get:

[2019-10-04 17:15:18.812] [ERROR] Error while finding RSpec test suite: Command failed: bundle exec rspec --require /Users/<user>/.vscode/extensions/connorshea.vscode-ruby-test-adapter-0.6.0/custom_formatter.rb --format CustomFormatter --order defined --dry-run
/Users/<user>/.rvm/gems/ruby-2.6.3/gems/bundler-2.0.2/lib/bundler/spec_set.rb:87:in `block in materialize': Could not find nokogiri-1.10.3 in any of the sources (Bundler::GemNotFound)
    from /Users/<user>/.rvm/gems/ruby-2.6.3/gems/bundler-2.0.2/lib/bundler/spec_set.rb:81:in `map!'
    from /Users/<user>/.rvm/gems/ruby-2.6.3/gems/bundler-2.0.2/lib/bundler/spec_set.rb:81:in `materialize'
    from /Users/<user>/.rvm/gems/ruby-2.6.3/gems/bundler-2.0.2/lib/bundler/definition.rb:170:in `specs'
    from /Users/<user>/.rvm/gems/ruby-2.6.3/gems/bundler-2.0.2/lib/bundler/definition.rb:237:in `specs_for'
    from /Users/<user>/.rvm/gems/ruby-2.6.3/gems/bundler-2.0.2/lib/bundler/definition.rb:226:in `requested_specs'
    from /Users/<user>/.rvm/gems/ruby-2.6.3/gems/bundler-2.0.2/lib/bundler/runtime.rb:108:in `block in definition_method'
    from /Users/<user>/.rvm/gems/ruby-2.6.3/gems/bundler-2.0.2/lib/bundler/runtime.rb:20:in `setup'
    from /Users/<user>/.rvm/gems/ruby-2.6.3/gems/bundler-2.0.2/lib/bundler.rb:107:in `setup'
    from /Users/<user>/.rvm/gems/ruby-2.6.3/gems/bundler-2.0.2/lib/bundler/setup.rb:20:in `<top (required)>'
    from /Users/<user>/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/<user>/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'

(It should be noted that the nokogiri gem is one that my project depends on, but the extension is looking in the wrong place for it.)

Here's the output of my gem env:

RubyGems Environment:
  - RUBYGEMS VERSION: 3.0.6
  - RUBY VERSION: 2.6.2 (2019-03-13 patchlevel 47) [x86_64-darwin18]
  - INSTALLATION DIRECTORY: /Users/<user>/.rvm/gems/ruby-2.6.2@mayhem
  - USER INSTALLATION DIRECTORY: /Users/<user>/.gem/ruby/2.6.0
  - RUBY EXECUTABLE: /Users/<user>/.rvm/rubies/ruby-2.6.2/bin/ruby
  - GIT EXECUTABLE: /usr/local/bin/git
  - EXECUTABLE DIRECTORY: /Users/<user>/.rvm/gems/ruby-2.6.2@mayhem/bin
  - SPEC CACHE DIRECTORY: /Users/<user>/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /Users/<user>/.rvm/rubies/ruby-2.6.2/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-18
  - GEM PATHS:
     - /Users/<user>/.rvm/gems/ruby-2.6.2@mayhem
     - /Users/<user>/.rvm/rubies/ruby-2.6.2/lib/ruby/gems/2.6.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /Users/<user>/.rvm/gems/ruby-2.6.2@mayhem/bin
     - /Users/<user>/.rvm/gems/ruby-2.6.2@global/bin
     - /Users/<user>/.rvm/rubies/ruby-2.6.2/bin
     - /Users/<user>/.rvm/bin
     - /usr/local/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin
     - /usr/local/opt/protobuf/bin
     - /usr/local/share/android-sdk/platform-tools
     - /usr/local/share/android-sdk/build-tools/29.0.2
     - /usr/local/share/android-sdk/tools

So for some reason, the extension is looking in 2.6.3, even though in the terminal it confirms that it should be using 2.6.2 for this project.

I even tried setting my default rvm to use 2.6.2, but I still get the same error when launching from the UI/spotlight/dock (this time it is looking in the 2.6.2 section, but it still doesn't find what it needs).

I'm super new to Ruby and rvm, but it seems like the extension isn't getting the right info from the rvm magic before it starts loading.

connorshea commented 5 years ago

Welcome to the Ruby community!

I vaguely remember hearing about a similar issue with it acting differently when opened via the UI vs the dock, but I can't remember the details and I can't find it. I'm also not seemingly able to reproduce it myself.

A few things to check/try:

Unfortunately, I use rbenv instead of rvm, so I'm not really sure what else it could be.

Out of curiosity, does the vscode-ruby extension work for you?

connorshea commented 5 years ago

Oh, I just noticed the ruby-2.6.2@mayhem thing. I think you're using RVM gemsets? That might be why it's working in strange ways. I'm not sure what to do about it, though. https://rvm.io/gemsets/basics

AnthonySuper commented 5 years ago

Are you using the RVM local dir ruby version thing? That seems like it might be the issue if it exists, since it will use whatever your default ruby is (I think, at least).

@connorshea how do you figure out what commands to run?

smrtsmrf commented 5 years ago

@connorshea

If I run the bundle exec rspec command from the integrated terminal, it works fine. But when the extension runs that command, that's when I get the error. The integrated terminal seems to be using the right path (2.6.2), but the extension seems to be looking in 2.6.3.

It may be useful to know that 2.6.3 is my default ruby version. But I even tried setting my default to 2.6.2 and I still had errors.

joaovbalmeida commented 5 years ago

Try installing the gems in your global gemset with:

rvm @global do gem install

That helped me a little bit

smrtsmrf commented 5 years ago

@joaovbalmeida, I'm new to ruby and rvm, but by doing that, it seems like it's just installing every gem both in the local project directory, as well as the global gemset. The problem would arise if/when different projects depend on different versions of the same gem.

connorshea commented 5 years ago

@smrtsmrf I'm fairly certain that Bundler handles that automatically using the Gemfile/Gemfile.lock, so it shouldn't matter if you have different versions of the same gem in separate projects. It'll only load the one specified in the Gemfile.lock. I don't think using gemsets should really be necessary unless you're doing something weird.

smrtsmrf commented 4 years ago

Well, as I mentioned, I'm new to ruby (and hence rvm as well). Just started at a new job and I followed the ruby setup they use. Unfortunately, they don't use VS Code though, so no help as far as this extension goes. :(

Now I've been getting mixed results though - sometimes opening Code with the terminal doesn't load the extension properly. But sometimes it does. It makes me think there's some kind of race condition going on with something. But I don't know enough about VS Code or ruby to make a call on that.

As of right now, I'm getting all failures rather than mixed results, and the extension isn't working at all. These are the errors I get (which are the same errors I was getting when I tried to open Code through the spotlight/UI)

Command failed: rspec --require /Users/<user>/.vscode/extensions/connorshea.vscode-ruby-test-adapter-0.6.0/custom_formatter.rb --format CustomFormatter --order defined --dry-run SimpleCov failed with exit 1

Ruby Test Explorer failed to find an RSpec test suite. Make sure RSpec is installed and your configured RSpec command is correct.

I figured out that I get those errors when I have a syntax error or something in my spec file. It sure would be nice if there was a way to indicate that was the problem, rather than the whole extension just not even loading when I close and open up Code again. So, I can still open and use Code and this extension via the terminal. Good news.

Unfortunately, the problem with opening from the spotlight/UI still persists, even when the syntax errors are taken care of, so something else is going on there.