kassio / neoterm

Wrapper of some vim/neovim's :terminal functions.
Other
1.3k stars 117 forks source link

Running RSpec doesn't work unless `bundle exec rspec` is from root directory #20

Closed kevinjalbert closed 9 years ago

kevinjalbert commented 9 years ago

I noticed an odd issue, when trying neoterm (in addition to #7). This doesn't really seem to be neoterm's fault, although I guess neoterm could try to accommodate for it.

With RSpec, bundle exec rspec must be ran from the Rails root directory, otherwise the command won't work as expected. I had tried this on an existing and new rails project (as I thought I had some odd absolute path hardcoded). I even had a another friend try it out with similar results. I could still be wrong, if there is a better way to have bundle exec rspec work from any sub-directory in a rails project. I'm curious on how other have gotten this to work for their own rails projects?


To set up a new Rails project to reproduce this:

ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin14]
bundle Rails 4.2.0
Bundler version 1.9.6

Create new Rails application with no TestUnit rails new my_awesome_app -T

Change Directory to Rails application cd my_awesome_app

Add RSpec to Gemfile gem 'rspec-rails'

Update gems (to include new RSpec gem) bundle install

Setup/Install RSpec rails g rspec:install

Create simple spec under touch ./spec/test_spec.rb

RSpec.describe "test" do
  it { expect(1).to eq(1) }
end

Run bundle exec rspec from Rails application root directory 1 example, 0 failures

Run bundle exec rspec from ./spec directory 0 examples, 0 failures

kassio commented 9 years ago

I asked for some of my friends, and none of them use their editor in another folder than the project root. Neither me.

What you can do is use binstubs on your rails project, and then change your g:neoterm_rspec_lib_cmd to something like g:neoterm_rspec_lib_cmd="$MY_PROJECT_PATH/bin/rspec", and it should work.

kevinjalbert commented 9 years ago

@kassio so I figured out that when using vim-startify if I immediately select a file directly even if I'm in the root of the project, it'll change my working directory to that of the file regardless. This is where I was seeing issues on how neoterm was always running from the file's location.

Knowing that issue, I can work around it so that my working directory is always the root (which is normally where I start my editor session.

Just curious, but I see that you are suggesting the use of the $MY_PROJECT_PATH ENV variable. I'm curious on how you would set that for each different project dynamically?

kassio commented 9 years ago

@kevinjalbert actually I wouldn't. :smile: But if you want, you can override cd function, for example, and set the variable on every cd. Or use something like $PROMPT_COMMAND on bash.