Comments (17)
Just sent a pull request with my workaround in it. The key to getting vim-rspec
to work if you have autochdir
set is to add the cwd to rspec's include path:
let g:rspec_command = "!bundle exec rspec -I . {rspec}"
HTH,
Andrew
Edit: fixed typo
from vim-rspec.
@spinlock99 It looks like vim
thinks you're in /Users/spinlock/rails/hoplu/spec/controllers
when running rspec
. Can you make sure :pwd
command within vim
prints out ``/Users/spinlock/rails/hoplu` before triggering the spec run.
from vim-rspec.
@gylaz that's exactly right. I modified a configuration file so that, when I open nerdtree, it opens in the current directory. Any ideas on updating the g:rspec_command
to work around that? I've currently got:
let g:rspec_command = "!bundle exec rspec -f d -c {spec}"
I've also noticed that rake spec SPEC...
will work so I'm thinking of changing g:rspec_command
to use rake but I ran into the same problem of the directory not being correct.
from vim-rspec.
Any ideas on updating the g:rspec_command to work around that?
I don't have much experience with nerdtree, unfortunately. The only thing that comes to mind is to set some variable as the root directory of the project. Something along the lines of:
let g:rspec_command = "bundle exec rspec -f d -c -I$ROOT_DIR/spec $ROOT_DIR/**/user_spec.rb"
from vim-rspec.
Running into the same issue. I change my current directory in vimrc for the default NERDtree directory and when I run rspec-vim, the path to the test is one directory too high. @spinlock99 did you ever figure this out?
from vim-rspec.
One option to fix this issue would be to run specs using the full path to the spec. If we change uses of @%
with expand("%:p")
, it will run rspec /full/path/to/project/spec/whatever_spec.rb
instead of just rspec spec/whatever_spec.rb
. The command looks a little uglier, but seems to work fine from any directory.
from vim-rspec.
@dlynam I'm making progress but no luck getting this working yet.
@jferris That seems to be working to find the spec but the paths to spec_helper
are still not right so it fails to find any files that you require
in your spec. Any ideas?
Thanks!
from vim-rspec.
I think this is beginning to make sense to me. If I run a single spec or single file, I'm failing with this error:
1:in `require': cannot load such file -- spec_helper (LoadError)
I can recreate this by cd'ing into spec/
and running rspec my_spec.rb
. So, this isn't related to how vim-rspec is running the specs but because rspec
doesn't have the current directory in it's load path. Changing require 'spec_helper'
to require './spec_helper'
fixes this issue.
If I try to run all of the specs, however, I fail with this error:
lib/rspec/core/configuration.rb:896:in `load': cannot load such file -- /<path-to-specs>/spec/spec (LoadError)
This one is related to how vim-rspec is calling the specs:
function! RunAllSpecs()
let l:spec = "spec"
call SetLastSpecCommand(l:spec)
call RunSpecs(l:spec)
endfunction
So, changing let l:spec = "spec"
to let l:spec = "."
gets all of the specs to run (i.e. we need to run rspec .
because we're already in spec/
.
from vim-rspec.
The first issue ("cannot load such file -- spec_helper") is because rspec expects you to run specs from the project root. If you want to run them from anywhere else, you'll need to expand the path.
If we expand the path to the actual spec within Vim, that will allow you to run specs regardless of cwd
for Vim, but the working directory for the terminal where you run specs will need to be the project root.
from vim-rspec.
@jferris I managed to get the first problem fixed by editing my g:rspec_command
in my .vimrc:
let g:rspec_command = "!bundle exec rspec -I . -f d -c {spec}"
-I .
adds the current directory to rsepcs include path.
from vim-rspec.
Cool. I think that would be harmless to include in the defaults, since rspec attempts to do that itself from the project root anyway. So:
- We can run specs by their full path instead of assuming the relative path from the project root will work.
- We can default to telling rspec to look in
{project_root}/spec
forspec_helper.rb
.
This will make it so that you can run specs regardless of your working directory.
@gylaz thoughts?
from vim-rspec.
Sounds good. I'll take a crack at adding this.
from vim-rspec.
I'm closing this. If rspec
is ran anywhere other than the root directory there will need to be proper path's added to RSpec's load path. We don't feel it should be vim-rspec
's concern to solve that.
from vim-rspec.
I have my models living in an engine outside Rails.root
When running my tests via vim-rspec, it thinks Rails.root is the engine root understandably since the file lives in there. I've changed the path manually and ensured :pwd returns the actual root of the project but no luck. Also I've done the above, and no luck. I'll post my findings When I get a fix (if)
Let me know if you have any pointers.
L
from vim-rspec.
Actually, I think I've found it. It was actually working correctly and the complains were due to bundle exec not being present.
This worked
let g:rspec_command = "!bundle exec rspec -I . {rspec}"
Thanks @spinlock99 (fixed the typo in this command "g:rsepc_command")
from vim-rspec.
For anyone that is wanting to run specs from anywhere in your project (not dependant on your cwd
being in the root, I'm using this with success. Obviously depends on git to get to the project root.
let g:rspec_command = "SPEC="$PWD/{spec}" && (cd `git rev-parse --show-toplevel` && bundle exec rspec "$SPEC" && unset SPEC)"
It uses a subshell to move to the appropriate directory before running the specs, this does not effect your cwd
in vim.
from vim-rspec.
I ended up with this command that searches for the root spec/
folder and then runs from it's parent.
let g:rspec_command = "!clear; ( cd $(find `( SPEC='{spec}'; CP=${SPEC\\%/*}; while [ -n \"$CP\" ] ; do echo $CP; CP=${CP\\%/*}; done; echo / ) ` -mindepth 1 -maxdepth 1 -type d -name spec)/..; bin/rspec {spec})"
Credit to 'Zarick Lau' for the parent search method
http://stackoverflow.com/a/7614803/76456
from vim-rspec.
Related Issues (20)
- Not sending commands to iTerm or Terminal in El Capitan HOT 3
- Not getting full file path of spec in terminal HOT 6
- RSpec 3.4 (?) breaks the quickfix list output HOT 2
- Run corresponding tests
- Line number and shared examples HOT 3
- Is it possible to send pkill process before running test ? HOT 2
- iTerm2 Version 3 Support HOT 3
- How to use with Projectionist HOT 1
- With spring the quick fix window always opens HOT 2
- Pass along flag to rspec HOT 3
- Can't run specs from MacVim HOT 1
- Can't run commands from MacVim HOT 2
- Escape whitespace in full file path HOT 1
- Buffer bleeding through run output using Vim 8.0 HOT 2
- change g:rspec_command HOT 3
- Easily run specs for all open files? HOT 2
- How to get the rails console HOT 1
- Native terminal in MacVim
- Run rspec with current line number
- Archive Project HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vim-rspec.