Rspec rake task gem no longer importing - ruby

Pulling my hair out on this. I'm running some rspec specs through rake using rspec's rake task. Its been working fine until I started getting this error message:
rake aborted!
LoadError: cannot load such file -- rspec/core/rake_task
Here is the results of gem list | grep rspec
rspec (3.1.0)
rspec-core (3.1.7)
rspec-expectations (3.1.2)
rspec-mocks (3.1.3)
rspec-support (3.1.2)
and here is the line I'm using to include the rake task in my Rakefile
require 'rspec/core/rake_task'
I uninstalled all rspec gems and re-installed. Same error. As I mentioned I've been running these tests for a few months now without issue. There have been no changes to the environment and it runs in a VM so I can ensure it wasn't a coworker. What am I missing?
EDIT
I double checked my Gemfile.lock file all the gem versions are matching with the one in the upstream repo.

First off, I recommend running your specs through the rspec command. It's far more flexible than running specs through rake and has less overhead. Running the specs through rake is still useful as part of a build pipeline (the kind of thing rake is good at).
You haven't provided sufficient information to definitely answer your question, but I can provide some suggestions:
Are you running rake via bundle exec rake? Bundler is designed to manage the load path at runtime after it installs your gems, and should ensure that the installed rspec-core/lib is on your load path.
You can add puts $LOAD_PATH.join("\n") to the top of your Rakefile to see what the load path is. Is rspec-core in the list anywhere? (I suspect it's not). If it's not, then require 'rspec/core/rake_task' is not going to work unless rspec-core is installed as a system gem. Use gem which rspec-core to see if it's installed that way.

Related

Old version of minitest used when running unit tests through rake

I have some classes with unit tests and I have a rake task to run these unit tests. However, I'm running into a problem where when the tests are run via rake an old version of minitest is being used. How can I get rake to use the newer version?
If I use the Minitest::Test subclass it runs fine when the tests are directly run through the ruby
command-line. However, if I use the following rake task:
require 'rake/testtask'
Rake::TestTask.new do |t|
t.pattern = 'tests/**/*_test.rb'
end
When I check the minitest version using puts MiniTest::Unit::VERSION it prints 5.5.0 when run with ruby, but prints 4.3.2 when run with rake. (When using gem list minitest -d version 4.3.2 is listed as the default.)
The reason I want to use the newer version of minitest is that when I directly run the unit tests using Ruby 2.0 I get the following warning:
MiniTest::Unit::TestCase is now Minitest::Test.
However, if I change MiniTest::Unit::TestCase to Minitest::Test I get the following error when I run the tests using rake.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rake/ext/module.rb:36:in `const_missing': uninitialized constant MiniTest::Test (NameError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/minitest/unit.rb:28:in `const_missing'
I want to avoid requiring any changes to the system configuration, because I want these tests to run on the default OS X ruby installation.
Using gem 'minitest', '=5.5.0' does not change the version of minitest that gets used.
Possibility #1: Run Rake with bundle exec to force it to use the version of Minitest managed by Bundler:
bundle exec rake test
Possibility #2: Create a binstub for Rake for your project that will load your bundle automatically:
bundle binstub rake
After that, you should be able to run Rake without bundle exec to get the same result.
Caveat: This has worked for the Ruby environment managers I've used recently, but you might need to Google around for a solution if it doesn't work for you.
Ruby is having a hard time loading minitest from the gem instead of the standard library, so we need to give it a little help. Add the following to your helper or rake task:
gem "minitest"
That will tell ruby to use the gem version. Just be sure to add that before minitest is required.

Create gem locally and skip rake install

I'm creating a ruby gem using Bundler for a simple rackup app (not Rails). It's a real pain to run rake install and then restart the webserver everytime. For most part it's ok because I test everything using rspec but not design. My gem contains a whole lot of design and everytime I update my gem I have to go threw the same procedure.
Is it possible to build gems locally without having to run rake install and then restart my rack server every single time?
If you're using Bundler to manage the gems in your application, you can use Bundler's path directive to use a gem that's currently in development.
In your Gemfile:
# My awesome gem that I'm developing
gem 'some-awesome-gem', :path => '~/Projects/some_awesome_gem'
Essentially, just point the path at the directory where your gem resides and you won't have to package new versions of the gem while you're actively developing it.
See the Bundler homepage and Gemfile Manual for more details.

rake aborts, don't know how to build task 'jobs:work'

I'm trying to get going on my first Ruby (v1.9.3p194) project. I'm hosting on Heroku, and using Sinatra along with ActiveRecord. I'm trying to integrate delayed_job into my project, and running into trouble getting rake to recognize jobs:work. (Yes, I know delayed_job typically works with rails, but as I understand it can work without it.)
So far, I've installed the delayed_job (3.0.3) and delayed_job_active_record (0.3.2) gems using my gemfile/bundler. Because I don't have rails, I created my own migration file from the delayed_job readme, and migrated it. I don't think any of this should be causing my issue.
From all the docs I've seen, installing the gems should do the trick. I've tried uninstalling and reinstalling them, to no avail. I'm not sure what else to try - perhaps there's something I need to explicitly include in my rakefile, but I haven't seen any docs that indicate that.
Any help greatly appreciated.
Maybe I have an actual answer for you.
I made a simple project to get jobs:work to show up with rake -T:
Gemfile
source :rubygems
gem 'delayed_job'
Rakefile
require 'rake'
require 'bundler'
require Bundler.load.gems.find{|i| i.name == 'delayed_job'}.gem_dir + "/lib/delayed/tasks"
run: $ bundle install
Result:
$ rake -T
rake jobs:clear # Clear the delayed_job queue.
rake jobs:work # Start a delayed_job worker.

How to activate test-unit for RubyMine when developing a library (gem)?

I'm developing a library (a gem) using Ruby 1.9.2. My Gemspec looks like the usual for a gem:
source "http://rubygems.org"
# Specify your gem's dependencies in table_builder.gemspec
gemspec
while in my gemspec I have this line:
s.add_development_dependency "test-unit"
I can see it's being installed and my Gemfile.lock includes it:
PATH
remote: .
specs:
foobar (0.0.1)
GEM
remote: http://rubygems.org/
specs:
test-unit (2.4.5)
PLATFORMS
ruby
DEPENDENCIES
foobar!
test-unit
In my Rakefile I load it with:
require "rubygems"
require "test/unit"
as well as in my test_helper.rb:
require "rubygems"
require "test/unit"
In the command line the tests run and pass, but in RubyMine, whether I run tests or the test rake task, I get this message:
MiniTest framework was detected. It is a limited version of original
Test::Unit framework. RubyMine/IDEA Ruby plugin test runner requires
full-featured version of the framework, otherwise default console
tests reporter will be used instead. Please install 'test-unit' gem
and activate it on runtime.
I'm using RVM, so I checked the SDK is the one I'm using on the command line and test-unit is listed in the list of installed gems.
So, how I activate test-unit in a way that RubyMine likes?
Please refer to help. You need Gemfile with the used gems listed in it for RubyMine to recognize the dependencies.
RubyMine 4.0 (in RC2 at the time of this writing) supports minitest and managed to run the tests out of the box. Way to go JetBrains!

RVM, Merb, Rake and RSpec

I am currently running ruby-1.9.1 installed via RVM. I have been looking at using Merb, but when I try and run it I get this error:
sam#shiny-dev:~/Projects/mojo$ rake db:migrate
(in /home/sam/Projects/mojo)
Merb root at: /home/sam/Projects/mojo
/home/sam/.rvm/gems/ruby-1.9.1-p378#merb/gems/dm-validations-1.0.0/lib/dm-validations.rb:33: warning: already initialized constant OrderedHash
Loading init file from ./config/init.rb
Loading ./config/environments/development.rb
rake aborted!
no such file to load -- spec/rake/spectask
/home/sam/Projects/mojo/Rakefile:24:in `require'
(See full trace by running task with --trace)
I have installed rspec, but even in IRB I cannot require 'spec/rake/spectask' unless I also install rspec-rails (which I have now done).
Any ideas where I could even start?
Cheers,
Sam
I had the same problem with this on Rails 2.3.5. I ended up having to uninstall RSpec 2.0 and install RSpec 1.3.0 instead.
After 2 weeks I finally figured it out!
Edit your Gemfile and add the line:
gem "rspec", :require => "spec"
and you're away!

Resources