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

chruby support with zsh #16

Closed
turboladen opened this issue Jul 16, 2014 · 10 comments
Closed

chruby support with zsh #16

turboladen opened this issue Jul 16, 2014 · 10 comments

Comments

@turboladen
Copy link

For reference: https://github.com/postmodern/chruby. I installed on OSX using Homebrew, FWIW.

I setup my test/rspec commands to use bin/rspec --tty (etc.). When I run any of the tests (cmd-ctrl-r, for example), I get output in the console saying that it can't find bundler--but the ruby path that's in the backtrace is for the system ruby. (As an aside, and I don't know if this is on you or Atom, it'd be nice to be able to copy the output from the console so I can paste in here. I'm not able to select anything in there). I've tried changing the commands to look like:

  • bin/rsepc --tty spec
  • bundle exec rspec --tty spec
  • source /usr/local/opt/chruby/share/chruby/chruby.sh; cd .; bundle exec rspec --tty spec

Atom version: 0.115.0
Ruby test: 0.7.0

@moxley
Copy link
Owner

moxley commented Jul 16, 2014

Works for me. I'm not a chruby user, but I tried it out, removing rbenv first. Check out the steps I took and see if there is anything you might be doing differently:

  1. Remove rbenv files:

    rm -rf ~/.rbenv
    
  2. Remove these lines from ~/.bash_profile:

    export PATH="$HOME/.rbenv/bin:$PATH"
    eval "$(rbenv init -)"
    
  3. Close and reopen shell.

  4. Verify the system Ruby:

    ~ $ which ruby
    /usr/bin/ruby
    ~ $ ruby --version
    ruby 2.0.0p451 (2014-02-24 revision 45167) [universal.x86_64-darwin13]
    
  5. Install chruby with Homebrew:

    brew update
    brew install chruby
    
  6. Add the following line to ~/.bash_profile:

    source /usr/local/opt/chruby/share/chruby/chruby.sh
    
  7. Install Ruby MRI 2.1.2:

    brew install gdbm libffi libyaml openssl readline wget
    wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.bz2
    tar -xjvf ruby-2.1.2.tar.bz2
    cd ruby-2.1.2
    ./configure --prefix="$HOME/.rubies/ruby-2.1.2" --with-opt-dir="$(brew --prefix openssl):$(brew --prefix readline):$(brew --prefix libyaml):$(brew --prefix gdbm):$(brew --prefix libffi)"
    make
    sudo make install
    
  8. Add the following line to ~/.bash_profile:

    chruby ruby-2.1.2
    
  9. Restart shell.

  10. Verify Ruby:

    ~ $ ruby --version
    ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
    ~ $ which ruby
    /Users/moxley/.rubies/ruby-2.1.2/bin/ruby
    
  11. Install bundler:

    gem install bundler
    
  12. Install project gems:

    cd ~/projects/bands
    bundle
    
  13. Verify rspec:

    ~/projects/bands git:master(0) $ which rspec
    /Users/moxley/.gem/ruby/2.1.2/bin/rspec
    
  14. Quit and restart Atom

  15. Run test tests for a given test file: Cmd+Ctrl+T

@turboladen
Copy link
Author

Hmm... I'll try when I get in front of a computer ASAP. Could it be due to me using zshell instead of bash?

On Jul 16, 2014, at 15:23, Moxley Stratton [email protected] wrote:

Works for me. I'm not a chruby user, but I tried it out, removing rbenv first. Check out the steps I took and see if there is anything you might be doing differently:

Remove rbenv files:

rm -rf ~/.rbenv
Remove these lines from ~/.bash_profile:

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
Close and reopen shell.

Verify the system Ruby:

~ $ which ruby
/usr/bin/ruby
~ $ ruby --version
ruby 2.0.0p451 (2014-02-24 revision 45167) [universal.x86_64-darwin13]
Install chruby with Homebrew:

brew update
brew install chruby
Add the following line to ~/.bash_profile:

source /usr/local/opt/chruby/share/chruby/chruby.sh
Install Ruby MRI 2.1.2:

brew install gdbm libffi libyaml openssl readline wget
wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.bz2
tar -xjvf ruby-2.1.2.tar.bz2
cd ruby-2.1.2
./configure --prefix="$HOME/.rubies/ruby-2.1.2" --with-opt-dir="$(brew --prefix openssl):$(brew --prefix readline):$(brew --prefix libyaml):$(brew --prefix gdbm):$(brew --prefix libffi)"
make
sudo make install
Add the following line to ~/.bash_profile:

chruby ruby-2.1.2
Restart shell.

Verify Ruby:

~ $ ruby --version
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
~ $ which ruby
/Users/moxley/.rubies/ruby-2.1.2/bin/ruby
Install bundler:

gem install bundler
Install project gems:

cd ~/projects/bands
bundle
Verify rspec:

~/projects/bands git:master(0) $ which rspec
/Users/moxley/.gem/ruby/2.1.2/bin/rspec
Quit and restart Atom

Run test tests for a given test file: Ctrl+T

Reply to this email directly or view it on GitHub.

@moxley
Copy link
Owner

moxley commented Jul 17, 2014

Yeah, zshell isn't supported yet.

@moxley moxley changed the title chruby support zshell support Jul 17, 2014
@moxley moxley changed the title zshell support chruby support Jul 17, 2014
@moxley moxley changed the title chruby support chruby support with zsh Aug 12, 2014
@moxley
Copy link
Owner

moxley commented Aug 24, 2014

Everybody who is interested in this feature, can you please test #22 and provide feedback on the PR?

@moxley
Copy link
Owner

moxley commented Aug 29, 2014

This should work in version 0.9.0. Feel free to post comments on this issue if it doesn't.

@moxley moxley closed this as completed Aug 29, 2014
@turboladen
Copy link
Author

Sorry for no comments on this while you were trying to fix it--had project deadlines so I switched back to RubyMine so I could be productive again. :)

I'm still seeing issues here, running 0.9.1. I set the Shell option to /bin/zsh, reverted all settings back to default, restarted Atom, go to run a specific test and am seeing:

Running tests: rspec --tty /spec/controllers/things_controller_spec.rb:104
---
zsh:1 command not found: rspec

Amongst other things, I have this in my .zshrc:

# chruby
source /usr/local/opt/chruby/share/chruby/chruby.sh
chruby 2.1.2

I then realized that I'm using bundler to install gems to vendor/bundle, so I just gem installed rspec, restarted Atom, and am still getting the same error as posted above.

Next, I tried changing default settings to use bin/rspec instead of rspec, and that fails with the same error that I reported initially (sure would be nice to be able to copy text from the console, atom... grr). That makes it seem like it's still not loading my .zshrc.

So next, I prefaced the commands with source ~/.zshrc and that got me using the right ruby, but got cannot load such file -- [the wrong path to my spec file] (LoadError) . The path for the spec that it was looking for was /Users/sloveless/Development/spec/controllers/things_controller_spec.rb, when it really should have been /Users/sloveless/Development/projects/my_project/spec/controllers/things_controller_spec.rb. I then noticed that there's an Atom "Project Home" setting, which was set to /Users/sloveless/Development, so I changed that to /Users/sloveless/Development/projects/my_project, reran the test and got the same error (with the wrong path). I then restarted Atom, just in case, ran again, and it's still looking in the wrong directory.

Next, I tried not sourcing my .zshrc (just in case that was doing some PATH) stuff, and changed my commands to look like:

source /usr/local/opt/chruby/share/chruby/chruby.sh && chruby 2.1.2 && rspec --tty {relative_path}

New error from bundler: "You have already activated rspec-support 3.1.0, but your Gemfile requires rspec-support 3.0.4 [etc...]". So now I'm working out of the correct path for my project, but the commands aren't using bundler.

I got it working using commands like:

source /usr/local/opt/chruby/share/chruby/chruby.sh && chruby 2.1.2 && bin/rspec --tty {relative_path}

Using bin/rspec instead of just rspec seems like something reasonable for me to have to do (instead of being this plugin's default), but it'd be nice to not have to do the chruby stuff.

Suggestions:

  • Give an option for a "run before tests shell script" or something. That way, I could just write a small shell script to do things for me--or just source the chruby.sh like I'm doing--to get around problems I'm having. Not sure if this is opening the door for bad hackery though.
  • It doesn't seem like the plugin is picking up on the .ruby-version file in my project's root dir, which would be nice.

@OleMchls
Copy link

Hey,

I also just stumbled upon this, and have the same issues. That's why I'd love to see this issue reopened. A little thing I found is that calling chruby_auto right before the test at least helps picking up the .ruby-version file so my commands look like chruby_auto && ruby -I test {relative_path}

Maybe something like a shell setup block or such would help :)

@yock
Copy link

yock commented Jul 16, 2015

@Nesquick When I prefix my command with chruby_auto the results window says the command is not found. How are you getting Atom and/or ruby-test to load chruby in the first place?

@yock
Copy link

yock commented Jul 16, 2015

source ~/.zshrc && chruby_auto && bin/rspec --tty spec

This works, but initializing my shell every time is quite time consuming. I'd imagine I could probably load chruby this way and exclude most of the irrelevant ZSH pieces, but this still incurs a big startup cost. I wonder if there's a way to initialize this into the Atom environment itself.

@OleMchls
Copy link

@yock I created the .zprofile file as mentioned in a similar issue #60

λ  ~  cat ~/.zprofile
source ~/.zshrc

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

No branches or pull requests

4 participants