failed to run rspec on ruby - ruby

do you know how to fix this? I was trying to run rspec on Ruby but it shows like this..
LoadError:
cannot load such file -- rspec/expectations
# ./spec/spec_helper.rb:20:in `block in <top (required)>'
# ./spec/spec_helper.rb:16:in `<top (required)>'
No examples found.
No examples found.
Finished in 0.01334 seconds (files took 1.46 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples
Finished in 0.01334 seconds (files took 1.46 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples

I was experiencing a similar issue (cucumber),I had two different versions of rspec-expectations gem installed, and the newer one was causing a conflict. I checked my Gemlist, discovered I had the required version and a newer one, so I simply uninstalled the newer version and I was able to run my cucumber tests. Moreover, there are many more solutions referenced here .

Related

RubyMine unable to recognize rake gem

I can’t get rubymine to run my tests even though they work fine on the command line. The problems seem to have started after upgrading some gems. When I hit ctrl+shft+F10 I get this:
/Users/williamjeffries/.rbenv/shims/bundle exec /Users/williamjeffries/.rbenv/versions/2.2.3/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Users/williamjeffries/code/myr-admin/bin/spring rspec /Users/williamjeffries/code/myr-admin/spec/controllers/orders_controller_spec.rb --require teamcity/spec/runner/formatter/teamcity/formatter --format Spec::Runner::Formatter::TeamcityFormatter --example "OrdersController a single order a credit card order captured order"
Testing started at 6:08 PM ...
/Users/williamjeffries/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.13.1/lib/bundler/definition.rb:181:in `rescue in specs': Your bundle is locked to rake (12.0.0), but that version could not be found in any of the sources listed in your Gemfile. If you haven't changed sources, that means the author of rake (12.0.0) has removed it. You'll need to update your bundle to a different version of rake (12.0.0) that hasn't been removed in order to install. (Bundler::GemNotFound)
from /Users/williamjeffries/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.13.1/lib/bundler/definition.rb:175:in `specs'
from /Users/williamjeffries/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.13.1/lib/bundler/definition.rb:235:in `specs_for'
from /Users/williamjeffries/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.13.1/lib/bundler/definition.rb:224:in `requested_specs'
from /Users/williamjeffries/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.13.1/lib/bundler/runtime.rb:118:in `block in definition_method'
from /Users/williamjeffries/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.13.1/lib/bundler/runtime.rb:19:in `setup'
from /Users/williamjeffries/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.13.1/lib/bundler.rb:99:in `setup'
from /Users/williamjeffries/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.13.1/lib/bundler/setup.rb:20:in `<top (required)>'
from /Users/williamjeffries/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/williamjeffries/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
Process finished with exit code 1
It seems to think I don’t have rake 12.0.0 but a gem list rake reveals that I do:
$ gem list rake
*** LOCAL GEMS ***
rake (12.0.0, 11.2.2, 10.4.2)
I double checked and at time of posting, 12.0.0 is in fact both a valid version and the most recent stable build for rake: https://github.com/ruby/rake/releases
Any ideas why this might be failing and how to get RubyMine to run my tests successfully again?
The solution was to restart RubyMine.

Cannot run rspec anymore

I had ruby 2.0 with rspec 3.0. I uninstalled all rspec 3.0 gems and replaced them with 2.0. I did this to get rid of deprecation warnings. Now, my specs are not working. I am getting the error below. What does the error tell me and how do i fix it ? None of the stack overflow posts on this were helpful.
/zombie/spec/spec_helper.rb:29:in `block (2 levels) in <top (required)>': undefined method `include_chain_clauses_in_custom_matcher_descriptions=' for #<RSpec::Matchers::Configuration:0x00000001a73928> (NoMethodError)
from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:398:in `expect_with'
from /home/lsusr/Code/Rspec/zombie/spec/spec_helper.rb:21:in `block in <top (required)>'
from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core.rb:92:in `configure'
from /home/lsusr/Code/Rspec/zombie/spec/spec_helper.rb:17:in `<top (required)>'
from /home/lsusr/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/lsusr/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:434:in `block in requires='
from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:434:in `map'
from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:434:in `requires='
from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/configuration_options.rb:20:in `block in configure'
from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/configuration_options.rb:19:in `each'
from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/configuration_options.rb:19:in `configure'
from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:21:in `run'
from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:in `run'
from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `block in autorun'
Okay, I found a fix.
I just removed all the unnecessary gems using
for i in `gem list --no-versions`; do gem uninstall -aIx $i; done
Then, I just reinstalled rspec using gem install rspec which gave me rspec 3.0 and fixed all the problems. But, i get the deprecation warnings again.
Please tell me why the error occurred. The tutorial author said that it should work with rspec 2.10.0 or higher.
The tutorial author said that it should work with rspec 2.10.0 or higher.
Likely the author meant 2.10 or higher, within the 2.x range. RSpec 3.x has breaking changes.
Try uninstalling the gems like you did before, then this:
gem install rspec '>=2.10', '<3'
Then run your code.
The deprecation warnings that happen when you use RSpec 3 are not bad; they are coaching to tell you that the RSpec methods that you are calling are going to be phased out. These kinds of warnings are typical and fine when moving an entire version number e.g. 2.x to 3.x.
The errors you get when you use RSpec 2.0 are because that's a very old version, and the method you're calling didn't exist in 2.0. This is probably why the tutorial author said to use 2.10 or higher.
Most likely the tutorial is out of date, so the best solution is to wrote the tutorial author and let him/her know to update it.
If you're curious about how RSpec does its version numbers, here's a link to Semantic Versioning.

Failing to run RSpec (uninitialized constant User (NameError)

Trying to run bundle exec rspec spec/models/user_spec.rb but failing to execute (see error below).
Contents of user_spec.rb:
require 'rails_helper'
describe User do
pending "add some examples to (or delete) #{__FILE__}"
end
If I remove the last 3 lines, then it complete with 0 examples and 0 failures. However, when the last 3 lines are present, it generates an error
/spec/models/user_spec.rb:4:in `<top (required)>': uninitialized constant User (NameError)
from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/configuration.rb:1057:in `load'
from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/configuration.rb:1057:in `block in load_spec_files'
from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/configuration.rb:1057:in `each'
from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/configuration.rb:1057:in `load_spec_files'
from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/runner.rb:97:in `setup'
from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/runner.rb:85:in `run'
from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/runner.rb:70:in `run'
from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/runner.rb:38:in `invoke'
from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/exe/rspec:4:in `<top (required)>'
from /usr/local/bin/rspec:23:in `load'
from /usr/local/bin/rspec:23:in `<main>'
It seems it doesn't know what User is and treats it as a constant, when this is infact a model. I have verified in the ruby sandbox that I can create new Users in the database. Any ideas?
Answer:
After removing --warnings from .rspec (thank you kirti), current error was about capybara version being too low (requires 2.2). After installing the latest version (modifying gemfile and bundle install), rspec appears to be executing correctly. Thank you to all for your comments.
I had the same issue, this was due to rspec/rails_helper.rb not being called anywhere.
I added it to the .rspec file, so my file look like this
--color
--require spec_helper
--require rails_helper
This and adding warnings to false in the spec/spec_helper.rb solved it for me !
config.warnings = false
After removing --warnings from .rspec (thank you kirti), current error was about capybara version being too low (requires 2.2). After installing the latest version (modifying gemfile and bundle install), rspec appears to be executing correctly. Thank you to all for your comments.
For me, the issue was that the name of the class was not being correctly called due to it being in another namespace. For example, I had:
RSpec.describe User do
# ... some tests
end
where I should have had
RSpec.describe MyModule::User do
# ... some tests
end
because the user class was defined with the MyModule module.

Ruby gamebox can't find the file gosu.for_1_9.so even though it's right there

Preface: I'm on a Windows 8 box, running Ruby 2.0.0.
I recently installed the gamebox gem for Ruby. During the installation of all its dependencies, a few files, among them the file $RUBYHOME/lib/ruby/gems/2.0.0/gems/gosu-0.7.50-x86-mingw32/lib/gosu.for_1_9.so, did not build properly because of some ASCII/Unicode issues in rdoc, and were thus "skipped". I hadn't payed much attention to it initially, but when I tried to run gamebox test_game to setup a new gamebox game, it spat the following message at me:
C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:118:in `require': 126: The specified module could not be found. - C:/Ruby200/lib/ruby/gems/2.0.0/gems/gosu-0.7.50-x86-mingw32/lib/gosu.for_1_9.so (LoadError)
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:118:in `rescue in require'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:124:in `require'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/gosu-0.7.50-x86-mingw32/lib/gosu.rb:11:in `<top (required)>'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:114:in `require'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:114:in `require'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/gamebox-0.5.0/lib/gamebox.rb:5:in `<top (required)>'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:66:in `require'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:66:in `require'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/gamebox-0.5.0/bin/gamebox:4:in `<top (required)>'
from C:/Ruby200/bin/gamebox:23:in `load'
from C:/Ruby200/bin/gamebox:23:in `<main>'
The important bit there is The specified module could not be found. - C:/Ruby200/lib/ruby/gems/2.0.0/gems/gosu-0.7.50-x86-mingw32/lib/gosu.for_1_9.so
I then went back and realized the whole Unicode thing, updated rdoc to the newest version as per this guy, and ran gem uninstall gosu followed by gem install gosu. Everything seemed to build just fine, and I saw that the needed file, .../gosu.for_1_9.so, was right where it needed to be.
However, I am still getting exactly the same error about not being able to find gosu.for_1_9.so!
I've been able to find exactly two Google results where someone else had this issue. In one situation the problem was peripheral because the guy was hacking on his gosu installation a bit; in the other, the solution was "Ruby 2 is bad and you should use Ruby 1.9", which is really not my preferred option.
Any ideas?
Ken,
The file is being found, but is not compatible to load in Ruby 2.0.0.
This is a bug / missing feature of Gosu. It does not work with Ruby 2.0.0 on Windows. The author of the gem has plans to work this out, but has not yet tackled it. You can follow up on the issue on Github here: https://github.com/jlnr/gosu/issues/163
The author can be found on freenode IRC in #gosu. I'm sure they could use some help with their windows support. Unfortunately, the answer to using Gamebox on Windows is to downgrade to Ruby 1.9.3. I will add this to the Gamebox wiki.
I agree with #Shawn42
But probably the best way is to install beforehand a ruby version manager.
RVM with Pik is what I use on Windows.
That way you can install the older 1.9.3 version of ruby and call pik to use that version whenever you want to use gamebox. You'll still have ruby 2.0.0 installed and ready to be used for your other projects.
http://www.ruby-on-rails-outsourcing.com/articles/2010/07/28/ruby-version-manager-for-windows/
Cheers

What does "<top (required)>" mean in a Ruby stack trace?

In Ruby 1.9.2 stack trace I frequently see the method given as <top (required)>, as in this section of stack below. What does this mean? Is my Ruby install subtly broken?
Could not find abstract-1.0.0 in any of the sources
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/spec_set.rb:87:in `block in materialize'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/spec_set.rb:81:in `map!'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/spec_set.rb:81:in `materialize'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/definition.rb:90:in `specs'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/definition.rb:135:in `specs_for'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/definition.rb:124:in `requested_specs'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/environment.rb:23:in `requested_specs'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/runtime.rb:11:in `setup'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler.rb:107:in `setup'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/setup.rb:14:in `<top (required)>'
<internal:lib/rubygems/custom_require>:33:in `require'
<internal:lib/rubygems/custom_require>:33:in `rescue in require'
<internal:lib/rubygems/custom_require>:29:in `require'
It's the top level of a file i.e. whatever gets run when the file is required.
So if something fails during the setup of a library (for example some required file isn't found) it will show up in the stacktrace like that.
If everything you required is correct, it could mean that you're trying to create a class with a name that already exists for a module. For example the following file :
class Test
end
Will raise :
<top (required)>': Test is not a class (TypeError)
Because Test is implicitely a module.
I ran into this error of <top (required)> when I was doing the tutorial in the book "Jump Start Sinatra."
I got rid of the error by making sure that I ran sudo gem install <GEM_IN_YOUR_FILE>. So in my case I had a main.rb and in that file I had this
require 'sinatra'
require 'sinatra-contrib'
So I went back into the root of my project and ran sudo gem install sinatra and sudo gem install sinatra-contrib and then my project worked fine.
Your errors will vary, but because this is what I found when I searched on Google, I know others will come here for similar reasons. And I offer this solution to at least get you thinking in the right direction since this worked for me.
I had the same problem. Solved it by converting .rb files encoding to UTF-8-BOM using Notepad++.
Ninto's answer makes total sense. It's a stack trace that you get one things fail. I was running my tests by doing:
bundle exec rspec spec
and what I got was:
An error occurred while loading ./spec/foodie_spec.rb.
Failure/Error: require 'foodie/food'
SyntaxError:
/Users/honey/Dev/foodie/funnex/lib/funnex/food.rb:17: syntax error, unexpected end-of-input, expecting end
# ./lib/foodie.rb:4:in `require'
# ./lib/foodie.rb:4:in `<top (required)>'
# ./spec/foodie_spec.rb:1:in `require'
# ./spec/foodie_spec.rb:1:in `<top (required)>'
No examples found.
Finished in 0.00002 seconds (files took 0.07998 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples
All I was doing wrong in my case was that I was missing and end.
But to understand the stack trace more, start from bottom of the commented out lines ie this line:
# ./spec/foodie_spec.rb:1:in `<top (required)>'
At line 1 of foodie_spec I had require 'foodie'
At line 4 of foodie.rb I had require 'foodie/food'
I errored out at line 17 of foodie/food
Stack traces in Ruby are also named backtraces or stack traceback

Resources