Rails 3 -- Rspec - windows

in my rails3 app I have installed rspec. But when I run the rspec command in my console it gives the following error.
C:\myapp>rspec spec
'rspec' is not recognized as an internal or external command,
operable program or batch file.
Please Help.
Thanks in Advance.

You can try
bundle exec rspec spec
It doesnt solve the root problem, but is a quick work-around
EDIT: Did a bit of googling for you, have you tried this? http://getsatisfaction.com/railstutorial/topics/rspec_command_not_found#reply_4313182

You need to add the ruby gems directory to your PATH environment variable.
For me this is "C:\Program Files\Ruby192\lib\ruby\gems", but this will vary depending on version and install directory. You can add it to your PATH variable by going to Computer > System Properties > Advanced System Settings > Environment Variable > Path > Edit. Make sure you don't wipe the existing contents. Instead, add a semi-colon and paste the gems path in.
Good luck.

I did this and it worked
C:\OSS\InSpects>PATH=C:\Ruby192\lib\ruby\gems\1.9.1\bin;C:\Ruby192\bin

Related

Rubymine (Ruby): Why can't I run rspec from within the IDE?

If I run the following command from the terminal I am able to run the rspec test cases successfully.
bundle exec rspec spec/requests/api/contacts/v3_get_tags_spec.rb
However if I am in the Rubymine IDE and do:
1- Right click on the file
2- Select "Run"
Then i get the following error message.
"in `require': cannot load such file -- spec_helper (LoadError)"
Also i am seeing a lot of errors related to gems not found, i feel link Rubymine is not configured correctly. What am i missing?
Note: Both the terminal and the IDE are running in the same root directory. I am pretty sure there is a problem with the configuration of the IDE. I checked the preference setting and it is using the same version of ruby as the one I am running in the termina.
Any help on the issue would be greatly appreciated.

Netbeans - installing SASS

I have had a few attempts at installing SASS on netbeans. I have followed the following tutorial:
http://kgagliardo.com/blog/netbeans-sass-windows-7
I get the below error when creating and trying to save the SASS file and no CSS file is created.
""C:\Ruby193\bin\sass.bat" "--cache-location"
"C:\Users\Leanne\AppData\Local\NetBeans\Cache\7.4\sass-compiler"
"C:\Users\Leanne\Documents\work\freelance\sites\fws_templates\gamer\scss\store.scss"
"C:\Users\Leanne\Documents\work\freelance\sites\fws_templates\gamer\css\store.css"
'"ruby.exe"' is not recognized as an internal or external command,
operable program or batch file. Done."
I've been stuck on this all morning, please help...
UPDATE
I've tried to follow the instructions provided below and it still does not work, although I did get a slightly different error message:
"C:\Ruby193\bin\sass.bat" "--cache-location"
"C:\Users\Leanne\AppData\Local\NetBeans\Cache\7.4\sass-compiler"
"C:\Users\Leanne\Documents\work\freelance\sites\fws_templates\gamer\scss\store.scss"
"C:\Users\Leanne\Documents\work\freelance\sites\fws_templates\gamer\css\store.css"
Syntax error: File to import not found or unreadable:
foundation/components/accordion.
Load path: C:/Users/Leanne/Documents/work/freelance/sites/fws_templates
(DEPRECATED)
on line 10 of C:\Users\Leanne\Documents\work\freelance\sites\fws_templates\gamer\scss\foundation\foundation.scss
from line 11 of C:\Users\Leanne\Documents\work\freelance\sites\fws_templates\gamer\scss\store.scss
Use --trace for backtrace. Done.
However Now I simply get the original error message again. No idea what to do. See image below showing that I have done everything according to the instructions (I think).
http://i.stack.imgur.com/Eekyt.png
Your path environment variable points to the wrong folder
Your Path to ruby is C:\Ruby193\bin
Go back and edit your path environment variable to point to C:\Ruby193\bin . At the moment you have C:\Ruby\192\bin
EDIT
And Now remove the backslash between Ruby and 193.
Your Path is set to : C:\Ruby\193\bin :-) !
your .bat is in Folder : C:\Ruby193\bin
TIP
Go to Options
Miscellaneous --> CSS Preprocessors
check : Generate extra information (debug)
You don't have path to ruby.exe which is c:\Ruby\192\bin in you PATH variable.
In Windows 7:
Right click on My computer and select Properties -> Go to
Advanced Tab -> Click on the Environmental Variables button
In the Environmental Variables window highlight PATH variable in
System variables section and click Edit
Append ;c:\Ruby\192\bin to the end (the semicolon is intentional)
Restart command prompt
You don't have path to ruby.exe
As simple, reinstall ruby, use ruby installer for windows.
When you go through the installation wizard, you’ll come to this options screen:
From what I can tell, the only option that you need to check on that one is the middle option, which helps your command-line instructions recognize where to find (as it says) “Ruby executables”. Otherwise, you’ll get the error message “ruby is not recognized as an internal or external command” when you try to install Sass in the command prompt.
Go to Options
Miscellaneous --> CSS Preprocessors
check : Generate extra information (debug)
For more information go to Setting Up Sass on Windows
They are all right in the above message. The problem is that Netbeans is not designed to pick up these changes instantaneously. Once you make the changes above, you have to RESTART Netbeans, so that the changes will be applied. This worked for me. Let me know if it works for you.
Thanks

Is it possible Ruby installation by copying the ruby folder?

This is a very silly question...
I have a doubt regarding the ruby installation. Will the ruby be installed in a windows server if we copy the Ruby187 folder from another server and add that in the PATH of the environment variable?
Or Do we need to install the Ruby from the installer always, in order to install it ?
Thanks in advance
I actually did something similar to this yesterday at work. A fellow co-worker, who does not have Ruby installed on their system, needs the ability to run my scripts while I am on vacation. So, I copied the entire Ruby folder from my C: to a shared network drive.
You will not only have to add the path to the Ruby folder to your PATH variable but you also may want to associate the Ruby extension .rb with Ruby. Not needed but just a thought.
One issue I ran into was here at work we don't have permission to alter our PATH variable manually. So, in order for my co-worker to launch the scripts I needed ran, I wrote a small C++ app that merely run a command line call to the Ruby interpreter and then to the script to run.
So, in short, yes, it is possible. =)
EDIT: In regards to why you would add the path to the Ruby installation to the PATH variable, it is so you can call Ruby from the command line with simply C:\>ruby some_script.rb. Without that added to your PATH, you'd need to type the entire path every time like C:\>C:\ruby192\bin\ruby some_script.rb. However, you'd still need to type "ruby" first.
In regards to the association of ".rb" files to the Ruby Interpreter, it is an option while installing Ruby on Windows using the installer provided at ruby-lang.org. With that, you would not need to type "ruby" before the script name on the command line. C:\>some_script.rb would work. I don't know exactly how to do this with a network version of Ruby but one way might be to right-click on a ".rb" file, choose "Open with..." and locate the Ruby.exe file in \ruby192\bin\ruby.exe.
I hope that explains what you were asking about in the comments.

Building and Testing Command Line Gem on TeamCity

I'm having some trouble testing a command line gem in a TeamCity build environment.
I'm working on a gem for building various types of manifest files, elf_manifesto. It runs from the command line and I've successfully tested it with Cucumber, and the really useful Aruba gem. Locally I'm working on a Lion MBP, using RVM, ruby 1.9.2. Everything's hunky dory.
The problem's arisen when moving the build process to the TeamCity environment at work. The TeamCity agent is running on a windows box and the problem seems to be that when triggering the command line executable from Aruba the script isn't found in the path environment on the windows box. Here's a snippet of Cucumber output from the build log.
[13:46:37]: [Scenario: Start manifesto with no parameters] When I run `manifesto`
[13:46:37]: [When I run `manifesto`] ChildProcess::LaunchError: The system cannot find the file specified. (2)
The Aruba gem is meant to take care of adding the executable (which is in the bin dir) to the path when running the tests. This works fine on my local set up, but fails on Windows. I've tried adding a RUBYPATH environment variable to the build parameters in TeamCity, but so far no luck.
Does anyone have any pointers?
Thanks in advance.
In my experience, Aruba does not add your gem from bin/ into the path. Even on UNIX-based projects, I've had to do it myself:
In env.rb:
PROJECT_ROOT = File.join(File.dirname(__FILE__),'..','..')
ENV['PATH'] = "#{File.join(PROJECT_ROOT,'bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
That being said, I have never gotten Aruba to work on Windows the same way as it did on UNIX.
To help diagnose, make use of the #announce tag on your features (which causes stderr and stdout to be printed), and possibly even drop in your own log statements in your custom steps.
In Windows, only if file with some extension like .COM,.EXE (and others) is executable.
You can change manifesto to ruby manifesto like with correct path to manifesto, it should work on windows.
If you want to work in Unix platform also, you need to change in support\env.rb for Aruba like below
require 'aruba/cucumber'
module ArubaOverrides
def detect_ruby(cmd)
processor, platform, *rest = RUBY_PLATFORM.split("-")
#puts platform
if platform =~ /w32$/ && cmd =~ /^manifesto /
"ruby -I../../lib -S ../../bin/#{cmd}"
else
"#{cmd}"
end
end
end
World(ArubaOverrides)
Hope it helps
You should be aware that Aruba runs the application it tests and creates all local output in its own working directory (awd). The awd defaults to tmp/aruba and is purged and created by Aruba at the beginning of every Scenario. However, the contents created by the last Scenario are left in the awd for your inspection.
Solution #1
Aruba will automatically add the bin directory of your project to the PATH environment variable for the duration of each Cucumber scenario.
You can create a bin dir under your project root, and copy you binaries there
Solution #2
You can use aruba-jbb, which provide a #no-aruba-tmpdir tag to handle this case.

RubyTest in Sublime Text 2

I am trying to get RubyTest to work in Sublime Text 2. I followed the Instruction on the Github Readme and get the following error. Does anyone know how I could fix this?
/bin/sh: rspec: command not found
To get this to work you only need to change one setting in the RubyTest package in sb2.
If you are using rvm, your rspec gem is installed through rvm and is not found in /bin/sh
So you need to set the RubyTest package for Sublime Text 2 to automatically check for your rvm environment variables.
What to change:
1) In Sublime Text 2, go to Preferences|Browse Packages. This will open up your packages directory.
2) Open the 'RubyTest' directory and look for the file 'RubyTest.sublime-settings'.
3) find the line that says:
"check_for_rvm": false,
and change it to:
"check_for_rvm": true,
save the change.
4) That's it. It should now work.
Good Luck
This worked for me:
If you're using RVM, open a project with command line from the project's folder:
subl .
Then, it'll hook the ruby version and gems.
This is most likely due to using RVM. What is the output of
which rspec
on your command line?
Also of note, just because you've included rspec-rails in a Gemfile, does not mean that 'rspec' is an executable program that your system knows about.
You can edit the RubyTest.sublime.settings to refer to your particular path to the rspec executable and it should work.
Unfortunately, this has the nasty side effect of being tied to one particular version of Ruby. If you're using RVM to switch between versions, you'll have to update your sublime.settings.
One work around, is to run Sublime from the command line.
Running Sublime Text 2(2165) with RubyTest plugin. Ruby and Gems managed with rbenv (0.3.0).
First attempt to use RubyTest gave the following error:
/bin/sh: rspec: command not found
From the command line I ran
which rspec
and it returned no results.
After some digging, I read that bundle install does not put the executables in your $PATH.
Alternative executable paths not picked up by shims sometimes
In order to use the executible outside the app, I had to delete the gem installed by bundler and then install it manually.
gem uninstall rspec
gem install rspec
followed by
rbenv rehash (Note you will need to run bundle inside your app so it updates the location of the gem)
This had to be performed for each version of ruby I have under rbenv control.
Now when I run
which rspec
it is found in the path and RubyTest is able to grab it without any problems.
fwiw, I had to repeat the steps for cucumber as well. To use all of RubyTests' features, ruby, cucumber and rspec executables need to be in your $PATH (for rbenv it is ~/.rbenv/shims/).
Try change the path to usr/local/bin/
I wrote a post on Sublime Text Build Scripts which should show you how to do this.
http://wesbos.com/sublime-text-build-scripts/
Same issue for me. With rspec 1.3.2 what I just did to fix it is to edit the RubyTest.sublime.settings file in the plugin folder, changing the "ruby_rspec_exec" key from:
"ruby_rspec_exec": "rspec"
to
"ruby_rspec_exec": "spec"
It really depends on the location where you have your rspec executable file...
I had the same problem after installing RubyTest by cloning from the repo. I simply uninstalled and reinstalled the package inside Sublime using Package Control, then everything worked fine.
You can see a summary of this issue here: https://github.com/maltize/sublime-text-2-ruby-tests/issues/36
Essentially, what Jim said was correct, you're running RVM or some other ruby vm manager that similarly monkeys with your PATH. Following the directions from this issue I did the following:
Install the binaries in my project
bundle install --binstubs
Add the path to my .bashrc and source it
echo 'export PATH="./bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
Open the sublime project from the command line (so that PATH is available in Sublime Text 2)
subl .
The following steps worked for me (I encountered the same error as OP):
Install the RubyTest plugin through the package control manager.
Note* If you don't have the package manager installed - I highly recommend it for managing sublime plugins - more info here.
Be sure to add the code here to your RubyTest.sublime-settings file.
This file can be found at (from the menu): Preferences -> Package settings -> RubyTest -> Settings User
Save file, close Sublime and restart Sublime from the terminal in your project's folder using (so PATH is available in Sublime): subl .
No, you don't need to change paths, run sublime from command line etc.
If you are using RVM, you only have to do this:
Go to Sublime Text 2, go to
preferances-> package settings -> RubyTests
and pick settings-user or settings-default (depending what you are using) and change line:
"run_rspec_command": "rspec {relative_path}"
to
"run_rspec_command": "bundle exec rspec {relative_path}"
And so forth - add bundle exec to all commands
I spent many hours struggling with this same problem! I could not get rspec to run within Sublime Text 2, using the Michael Hartl "Ruby on Rails Tutorial." It kept saying:
/bin/sh: rspec: command not found
I finally realized that the RubyTest package (https://github.com/maltize/sublime-text-2-ruby-tests) was looking in the WRONG PLACE for my RVM!
On my Mac, the path for RubyTest is /Library/Application Support/Sublime Text 2/Packages/Ruby Test
First, to make RubyTest seek the RVM, I changed the parameter in RubyTest.sublime-settings from
"check_for_rvm": false, to "check_for_rvm": true,
Then I dug into the Python code of run_ruby_test.py: https://github.com/maltize/sublime-text-2-ruby-tests/blob/master/run_ruby_test.py
At line 151, inside class BaseRubyTask, it had the wrong path for my RVM:
rvm_cmd = os.path.expanduser('~/.rvm/bin/rvm-auto-ruby')
I changed it to the full correct path: rvm_cmd = os.path.expanduser('/usr/local/rvm/bin/rvm-auto-ruby')
If this is not your path, find the correct path by typing
$ which rvm-auto-ruby and substitute that instead.
After saving run_ruby_test.py, I went to Terminal, cd to my Rails application directory, and ran spork
Finally, I opened static_pages_spec.rb in Sublime Text 2. Now all the tests work from it!
I'm using rbenv and found that adding the following to my .bashrc did the trick
/Users/user/.rbenv/shims/rspec

Resources