GithubHelp home page GithubHelp logo

Comments (17)

spinlock99 avatar spinlock99 commented on August 10, 2024 1

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.

gylaz avatar gylaz commented on August 10, 2024

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

spinlock99 avatar spinlock99 commented on August 10, 2024

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

gylaz avatar gylaz commented on August 10, 2024

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.

dlynam avatar dlynam commented on August 10, 2024

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.

jferris avatar jferris commented on August 10, 2024

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.

spinlock99 avatar spinlock99 commented on August 10, 2024

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

spinlock99 avatar spinlock99 commented on August 10, 2024

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.

jferris avatar jferris commented on August 10, 2024

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.

spinlock99 avatar spinlock99 commented on August 10, 2024

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

jferris avatar jferris commented on August 10, 2024

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 for spec_helper.rb.

This will make it so that you can run specs regardless of your working directory.

@gylaz thoughts?

from vim-rspec.

gylaz avatar gylaz commented on August 10, 2024

Sounds good. I'll take a crack at adding this.

from vim-rspec.

gylaz avatar gylaz commented on August 10, 2024

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.

lsaffie avatar lsaffie commented on August 10, 2024

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.

lsaffie avatar lsaffie commented on August 10, 2024

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.

jondavidjohn avatar jondavidjohn commented on August 10, 2024

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.

phallguy avatar phallguy commented on August 10, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.