Making rspec work in RubyMine - ruby

I've just installed RubyMine, as long as Ruby + gem + rspec + rspec-rails.
I'm trying to make run the mini-tutorial shown on http://rspec.info/ but I'm having problems.
First, I had to modify the shown
require 'bowling'
to
require_relative 'bowling'
as I was getting a
`require': no such file to load -- bowling.
Now, even after doing this I am getting a
`<top (required)>': undefined method `describe' for main:Object (NoMethodError)
How to make rspec work in RubyMine?

rspec.info is for RSpec version 1.x. Documentation for 2.x, which is what you will have installed if you simply did gem install rspec can be found at http://relishapp.com/rspec. You may want to take a look at their tutorial there.
I use RSpec and RubyMine together every day, so I expect that version mismatch is your biggest problem.
Also, if you are willing to purchase a book to learn RSpec, I'd highly recommend http://pragprog.com/book/achbd/the-rspec-book from Pragmatic Programmers.

Well, it seems to be a known issue:
http://youtrack.jetbrains.net/issue/RUBY-8603?projectKey=RUBY
EDIT: it did indeed seem to work.

Related

Padrino Project Generator Fails - Undefined Method `add_builtin_type'

I'm new to both Ruby and Sinatra/Padrino so I apologize if I'm missing something really simple.
I have Sinatra working fine, as I can build a very simple "hello" app and see it work.
I wanted to move on and generate a new Padrino project, but when I do this:
$ padrino g project foobar
I get this:
/Users/dave/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.0/lib/active_support/ordered_hash.rb:3:in `<top (required)>': undefined method `add_builtin_type' for Psych:Module (NoMethodError)
from /Users/dave/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121:in `require'
from /Users/dave/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:121:in `require'
from /Users/dave/.rvm/gems/ruby-2.1.5/gems/padrino-gen-0.12.4/lib/padrino-gen.rb:3:in `<top (required)>'
from /Users/dave/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/dave/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/dave/.rvm/gems/ruby-2.1.5/gems/padrino-gen-0.12.4/bin/padrino-gen:12:in `<main>'
I have tried installing the Psych gem but this didn't change anything. I have no idea what to try next, or how to really interpret the error message. Any nudges in the right direction you can give me?
Bug reports show this may be an RVM issue.
I suggest changing from RVM to "ruby-install" and "chruby" because IMHO these are simpler, easier, and better at installing dependencies including psych and its libraries.
As joelparkerhenderson noted, the error message shows problems with gem files in the .rvm directory, suggesting some issue or conflict with rvm. Switching to system ruby solved the problem for me. I don't really need to use a specific version of ruby on this project, so that's a fine workaround for me.
I had this problem while using Ruby 2.1.5. After reading comments on here I realized it's not a RVM problem, but a ruby problem. I switched to 2.0.0-p576 and everything works. Psych must not be compatible with the new ruby versions.
However I don't understand how a different ruby version would cause this method to go missing. If anyone could explain that I would be grateful!
I ran into this using rbenv and padrino 0.13.0. Tried many versions of Ruby, including the system Ruby on OS X El Capitan, but found that that made no difference, so I'm now running the latest stable one (2.2.4).
Eventually I tried each version of the psych gem and found I could only get padrino g to work with an older version of the gem. Psych version 2.0.8 worked, while every newer version (up to the current 2.0.16) failed.
So: gem install psych -v=2.0.8 && gem uninstall psych -v '>= 2.0.9'
With me, after a lot of googling and reading various thread on S.O., it was only my rvm that was the problem. I was getting the rvm 'WARNING!' that rvm wasn't first in $PATH. You can check this with echo $PATH. Check out your ~/.bashrc see if there is anything like heroku toolbelt or linuxbrew, or whatever, loading themselves into your PATH at the FRONT i.e. PRE-PENDING your path, rather than APPENDING. This is indicated by something like export PATH="/usr/local/heroku/bin:$PATH". That sets heroku at the beginning of your PATH. Simply change it to export PATH="$PATH:/usr/local/heroku/bin".
I was trying to start a padrino project with activesupport, and this was causing problems. Changing to an earlier version of Ruby, as suggested in another thread, didn't cut it, because activesupport requires 2.2.0 or up.
Fixing my PATH, ensuring that rvm was initialized at the very beginning of the PATH, fixed my Padrino problem, and was able to initialize a project with the following command:
padrino g project sample_blog -t shoulda -e haml -c sass -s jquery -d activerecord -b
I know that's all a little off-tangent, but I think it's bound to help one or two people out there!
PS I'm using ruby 2.2.2p95 in this project folder.

RSPEC Setup Help - Mountain Lion Ruby 1.9.3

Setting up my first developing environment, so bear with me. Running Mountain Lion, Ruby 1.9.3, Gems 1.8.25 and RVM 1.19.1.
Trying to get RSPEC up and running, but I keep getting an error. I think it has to do with my PATH, as most questions about this refer to the fact that their shell (Bash?) is looking in the wrong place.
Using this wonderful tutorial: http://blog.davidchelimsky.net/2007/05/14/an-introduction-to-rspec-part-i/
I've tried running the simplest rspec files and get an error, so I tried just typing "spec" (no quotes) in the command-line. That gives me the error "-bash: spec: command not found" (no quotes).
Looked around stackoverflow and saw that the command was updated to "rspec" instead of "spec"? So when I type "rspec" (no quotes) into the command line I get this nonsense:
Evans-MacBook-Pro:~ Evan$ rspec
/Users/Evan/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load': cannot load such file -- /Users/Evan/spec (LoadError)
from /Users/Evan/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
from /Users/Evan/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
from /Users/Evan/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
from /Users/Evan/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
from /Users/Evan/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
from /Users/Evan/.rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'
Regarding previous answers I found to this question: my attempts to alter the .bashrc just left me confused about what the heck I was doing, and I don't think I got the syntax right (also it didn't work).
Any thoughts? Much appreciated!
Evan
Rspec assumes your specs in a spec/ directory which cannot be found. Try running
rspec spec_tutorial
Btw. this tutorial is pretty outdated. Try using rspec.info instead for example.

Undefined method 'request_uri'

I am working with the Shopsense Ruby Gem however I am unable to use the gem. Making requests exactly as in the test I receive the following error:
/Users/rudolph9/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:455:in `block in get_response': undefined method `request_uri' for #<URI::Generic:0x007fd5b3a66810> (NoMethodError)
from /Users/rudolph9/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:745:in `start'
from /Users/rudolph9/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:454:in `get_response'
from /Users/rudolph9/.rvm/gems/ruby-1.9.3-p0/gems/Shopsense-0.1.1/lib/Shopsense.rb:76:in `do_search'
from test_shopsense.rb:10:in `<main>'
However, the test works fine if I clone the repository, modify the test and require the source directly as follows:
1 #!/usr/bin/env ruby¬
2 require 'rubygems'¬
3 #require 'Shopsense'¬
4 require '../lib/shopsense.rb'¬
.
.
.
What is the issue when using the gem it self??
Do you have an older version of the gem installed, or another gem which is named Shopsense?
With the error you're getting, I suspect the issue would be related ruby trying to automatically find the gem when you do require 'Shopsense' and finding something other than what you want. When you do require '../lib/shopsense.rb' it defines a specific path to the gem, so you always get the gem you want.
I don't have any experience with Shopsense, but the link you supplied looks like its a version 0.1.0, while the ruby interpreter found a Shopsense-0.1.1. I suspect the issue has to do with that. In fact, the source for Shopsense you linked to, line 76 (where the error is in your output) is a blank line.

Error in JSON Ruby Gem - Ubuntu 11.04

Hello the clever people of Stackoverflow.
I am trying to right a little JSON script. But the JSON Gem does not seem to be working. Just by having the code:
require 'rubygems'
require 'json'
I get the error:
./json.rb:5: undefined method `search' for nil:NilClass (NoMethodError)
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from places.rb:2
I don't have any other code in the file. I have unistalled the gem and reinstalled. But the same error, I can't find what the problem is?
I feel like all I do on this site is ask for help, but I do only come here as a last resort, and if there is anything I can do please let me know in return
Thanks
Charlie
Do you have a json.rb in the same directory as the places.rb? Try renaming that to something else.
I upgraded to the last Ruby 1.9.2 using RVM and re-installed Gems and its working fine, if anyone runs into the same problem would recommend doing this!

IronRuby doesn't recognize 'rake' - I'm getting undefined method `rake' for main:Object, how to fix?

Just installed IronRuby 1.1. I'm trying to take a look at rake and albacore. After installing ironruby, I am able to hit a command prompt by typing ir, and I am able to do simple puts, but when I try to run rake, I get the error
undefined method `rake' for main:Object
How do I resolve this? Any ideas?
Thanks,
~ck in San Diego
rake is an executable Ruby script that you call from the Windows command line, not a Ruby method that you call from IRb.

Resources