Testfirst.org - Learn ruby course - Rspec issue unresolved - ruby

I would like to do the testfirst.org exercises although can't seem to get to the starting line due to a version issue/lack of knowledge on my part as well..
At the begining you have to run the test $rake
i got following error..
(in /home/arno/learn_ruby)
rake aborted!
Gem::MissingSpecError: Could not find 'rspec' (~> 2) among 94 total
gem(s)
Checked in
'GEM_PATH=/home/arno/.gem/ruby/2.4.0:/home/arno/.rbenv/
versions/2.4.0/lib/ruby/gems/2.4.0', execute `gem env` for more
information
/home/arno/learn_ruby/Rakefile:2:in `<top (required)>'
(See full trace by running task with --trace)
I then tried to uninstall rspec. I then tried to install a version less than 3. That also did not work. Now I have version 2.9 and 3.2 installed but the same error persisted..
I then did bundle install and bundle update...something changed although still not working..
Here is the latest error when i run the test $rake..
(in /home/arno/learn_ruby)
rake aborted!
NoMethodError: undefined method `last_comment' for #
<Rake::Application:0x00564ff13bf4b0>
/home/arno/learn_ruby/Rakefile:8:in `new'
/home/arno/learn_ruby/Rakefile:8:in `<top (required)>'
(See full trace by running task with --trace)
Here is the rakefile..
# This Rakefile has all the right settings to run the tests inside
each lab
gem 'rspec', '~>2'
require 'rspec/core/rake_task'
task :default => :spec
desc "run tests for this lab"
RSpec::Core::RakeTask.new do |task|
lab = Rake.application.original_dir
task.pattern = "#{lab}/*_spec.rb"
task.rspec_opts = [ "-I#{lab}", "-I#{lab}/solution", '-f
documentation', '-r ./rspec_config']
task.verbose = false
end

After 2 days of searching i found a solution from The Odin Project.
They have a Test First - Rspec 3 edition..
If your having the same issue go to their repo https://github.com/TheOdinProject/learn_ruby.
Read through the readme file, fork that repo, clone your version of the repo, cd into it and bundle install..
All works fine now..

Related

travis failing to run rake with LoadError: cannot load such file -- rspec/core/rake_task

Let me preface this with this all runs locally and succeeds.
Source code repo
Travis log for job #4.1
Error:
$ rake
rake aborted!
LoadError: cannot load such file -- rspec/core/rake_task
/home/travis/build/alienfast/gulp-pipeline-rails/Rakefile:4:in `<top (required)>'
/home/travis/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `eval'
/home/travis/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `<main>'
(See full trace by running task with --trace)
.travis.yml
language: ruby
rvm:
- 2.2.2
- ruby-head
matrix:
allow_failures:
- rvm: ruby-head
cache: bundler
before_script:
# install Gulp 4 CLI tools globally from 4.0 GitHub branch
- npm install gulpjs/gulp-cli#4.0 -g
script: rake
Gemfile
gemspec
# travis-ci quirk?
group :development, :test do
gem 'rake'
gem 'rspec'
gem 'rspec-rails'
gem 'capybara'
gem 'capybara-webkit'
end
Fix attempts:
Locally, I have emptied my rvm gemset, deleted locks, and replicated the travis build - still works
I tried moving the necessary test gems from the gemspec to the Gemfile
So I'm pretty confused, I have other projects that don't have this problem and I don't see anything obvious. Is there any reason to get LoadError: cannot load such file -- rspec/core/rake_task?
Have you tried using bundle exec rake -t As noted here LoadError: cannot load such file -- rspec/core/rake_task

Travis CI is failing to run tests with **/*_test.rb pattern

My micro Ruby project tests works on my machine, on private VM, but fails on Travis CI bulid
Project uses both rspec (+rspec-given) and minitest
Full trace here: https://travis-ci.org/equivalent/code_katas/jobs/61321482
$ bundle exec rake
MiniTest::Unit::TestCase is now Minitest::Test. From /home/travis/.rvm/rubies/ruby
2.1.4/lib/ruby/2.1.0/test/unit/testcase.rb:8:in `<module:Unit>'
/home/travis/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/test/unit.rb:676:in `<class:Runner>': undefined method `_run_suite' for class `Test::Unit::Runner' (NameError)
from /home/travis/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/test/unit.rb:261:in `<module:Unit>'
from /home/travis/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/test/unit.rb:15:in `<module:Test>'
from /home/travis/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/test/unit.rb:7:in `<top (required)>'
from /home/travis/build/equivalent/code_katas/vendor/bundle/ruby/2.1.0/gems/sorcerer-1.0.2/test/sorcerer/resource_test.rb:3:in `require'
#...
The error is self-explanatory MiniTest::Unit::TestCase is now Minitest::Test. This is caused by rspec-given dependency sorcerer using test-unit (source) (My code is not referring to test-unit anywhere in the code)
So the thing I'm curious about is if anyone know how to get around this.
Like I said it works everywhere else except Travis CI
Problem was that Travis CI is cloning repository into /home/travis/build/username/projectname and then bundle install with
--deployment flag which install gems to vendor folder
/home/travis/build/username/projectname/verdor
my Rakefile was using test pattern **/*_test.rb therefore run tests in all folders, therefore it was loading verdor directory and all the tests from dependencies (external gems) some of which were TestUnit not compatible with MiniTest
solution was to load tests in Rakefile not with pattern but with:
Rake::TestTask.new(:test) do |t|
t.test_files = Dir['**/*_test.rb'].reject do |path|
path.include?('vendor') # tell travis CI to ignore vendor tests
end
end
similar apply for RSpec
RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = Dir.glob('**/*_spec.rb').reject do |path|
path.include?('vendor') # tell travis CI to ignore vendor tests
end
# t.rspec_opts = '--format documentation'
end

Problems running rspec 2.8.0.rc1 within rbenv defined ruby 1.9.2p290 environment

This works:
[rails31]$ ruby -S rspec ./spec/models/domain_spec.rb
*.
Pending:
Domain add some examples to (or delete) /home/keith/Code/elements2/spec/models/domain_spec.rb
# Not Yet Implemented
# ./spec/models/domain_spec.rb:4
Finished in 0.04241 seconds
2 examples, 0 failures, 1 pending
However I'm trying to run from guard, which executes the following command:
[rails31]$ /home/keith/.rbenv/versions/1.9.2-p290/bin/ruby -S rspec ./spec/models/domain_spec.rb
/home/keith/.rbenv/versions/1.9.2-p290/bin/ruby: no Ruby script found in input (LoadError)
Breaking that down enough to execute I get this:
[rails31]$ /home/keith/.rbenv/versions/1.9.2-p290/bin/ruby ./spec/models/domain_spec.rb
/home/keith/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rspec-core-2.8.0.rc1/lib/rspec/core/configuration.rb:335:in `rescue in debug=': (RuntimeError)
**************************************************
no such file to load -- ruby-debug
If you have it installed as a ruby gem, then you need to either require
'rubygems' or configure the RUBYOPT environment variable with the value
'rubygems'.
...
This is actually where I started in the first place - I know rspec respects the "dont require rubygems" rule, so maybe I need to run rake. The big problem I have with this error is that "ruby-debug" does NOT exist for ruby1.9 - it should be ruby-debug19 - so whats happening here?
So anyway, I tried with Rake:
[rails31]$ rake spec ./spec/models/domain_spec.rb
(in /home/keith/Code/elements2)
rake aborted!
uninitialized constant Rake::DSL
...
I've tried Googling the problem but nothing obvious is coming up, so really I'm stumped
UPDATE:
Well after reading this post I've managed to resolve the rake issue, however now when I run rake I get this:
[rails31]$ rake spec
(in /home/keith/Code/elements2)
/home/keith/.rbenv/versions/1.9.2-p290/bin/ruby -S rspec ./spec/models/domain_spec.rb
/home/keith/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rspec-core-2.8.0.rc1/lib/rspec/core/configuration.rb:335:in `rescue in debug=': (RuntimeError)
...

Does RVM "failover" to another ruby instance on error?

Have a strange problem in that I have a Rake task that seems to be using multiple versions of Ruby. When one fails, it seems to try another one.
Details
MacBook running 10.6.5
rvm 1.1.0
Rubies: 1.8.7-p302, ree-1.8.7-2010.02, ruby-1.9.2-p0
Rake 0.8.7
Gem 1.3.7
Veewee (provisioning Virtual Machines using Opcode.com, Vagrant and Chef)
I'm not entirely sure the specific details of the error matter, but since it might be an issue with Veewee itself. So, what I'm trying to do is build a new box base on a veewee definition. The command fails with an error about a missing method- but what's interesting is how it fails.
Errors
I managed to figure out that if I only have one Ruby installed with RVM, it just fails. If I have more than one Ruby install, it fails at the same place, but execution seems to continue in another interpreter.
Here are two different clipped console outputs. I've clipped them for size. The full outputs of each error are available as a gist.
One Ruby version installed
Here is the command run when I only have a single version of Ruby (1.8.7) available in RVM
boudica:veewee john$ rvm rake build['mettabox'] --trace
rvm 1.1.0 by Wayne E. Seguin (wayneeseguin#gmail.com) [http://rvm.beginrescueend.com/]
(in /Users/john/Work/veewee)
** Invoke build (first_time)
** Execute build
…
creating new harddrive
rake aborted!
undefined method `max_vdi_size' for #<VirtualBox::SystemProperties:0x102d6af80>
/Users/john/.rvm/gems/ruby-1.8.7-p302/gems/virtualbox-0.8.3/lib/virtualbox/abstract_model/dirty.rb:172:in `method_missing'
<------ stacktraces cut ---------->
/Users/john/.rvm/gems/ruby-1.8.7-p302/gems/rake-0.8.7/bin/rake:31
/Users/john/.rvm/gems/ruby-1.8.7-p302#global/bin/rake:19:in `load'
/Users/john/.rvm/gems/ruby-1.8.7-p302#global/bin/rake:19
Multiple Ruby Versions
Here is the same command run with three versions of Ruby available in RVM. Prior to doing this, I used "rvm use 1.8.7." Again, I don't know how important the details of the specific errors are- what's interesting to me is that there are three separate errors- each with it's own stacktrace- and each in a different Ruby interpreter. Look at the bottom of each stacktrace and you'll see that they are all sourced from different interpreter locations- First ree-1.8.7, then ruby-1.8.7, then ruby-1.9.2:
boudica:veewee john$ rvm rake build['mettabox'] --trace
rvm 1.1.0 by Wayne E. Seguin (wayneeseguin#gmail.com) [http://rvm.beginrescueend.com/]
(in /Users/john/Work/veewee)
** Invoke build (first_time)
** Execute build
…
creating new harddrive
rake aborted!
undefined method `max_vdi_size' for #<VirtualBox::SystemProperties:0x1059dd608>
/Users/john/.rvm/gems/ree-1.8.7-2010.02/gems/virtualbox-0.8.3/lib/virtualbox/abstract_model/dirty.rb:172:in `method_missing'
…
/Users/john/.rvm/gems/ree-1.8.7-2010.02/gems/rake-0.8.7/bin/rake:31
/Users/john/.rvm/gems/ree-1.8.7-2010.02#global/bin/rake:19:in `load'
/Users/john/.rvm/gems/ree-1.8.7-2010.02#global/bin/rake:19
(in /Users/john/Work/veewee)
** Invoke build (first_time)
** Execute build
isofile ubuntu-10.04.1-server-amd64.iso is available
["a1b857f92eecaf9f0a31ecfc39dee906", "30b5c6fdddbfe7b397fe506400be698d"]
[]
Last good state: -1
Current step: 0
last good state -1
destroying machine+disks
(re-)executing step 0-initial-a1b857f92eecaf9f0a31ecfc39dee906
VBoxManage: error: Machine settings file '/Users/john/VirtualBox VMs/mettabox/mettabox.vbox' already exists
VBoxManage: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component Machine, interface IMachine, callee nsISupports
Context: "CreateMachine(bstrSettingsFile.raw(), name.raw(), osTypeId.raw(), Guid(id).toUtf16().raw(), FALSE , machine.asOutParam())" at line 247 of file VBoxManageMisc.cpp
rake aborted!
undefined method `memory_size=' for nil:NilClass
/Users/john/Work/veewee/lib/veewee/session.rb:303:in `create_vm'
/Users/john/Work/veewee/lib/veewee/session.rb:166:in `build'
/Users/john/Work/veewee/lib/veewee/session.rb:560:in `transaction'
/Users/john/Work/veewee/lib/veewee/session.rb:163:in `build'
/Users/john/Work/veewee/Rakefile:87
/Users/john/.rvm/gems/ruby-1.8.7-p302/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/Users/john/.rvm/gems/ruby-1.8.7-p302/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/Users/john/.rvm/gems/ruby-1.8.7-p302/gems/rake-0.8.7/lib/rake.rb:631:in `each'
…
/Users/john/.rvm/gems/ruby-1.8.7-p302/gems/rake-0.8.7/bin/rake:31
/Users/john/.rvm/gems/ruby-1.8.7-p302#global/bin/rake:19:in `load'
/Users/john/.rvm/gems/ruby-1.8.7-p302#global/bin/rake:19
(in /Users/john/Work/veewee)
** Invoke build (first_time)
** Execute build
isofile ubuntu-10.04.1-server-amd64.iso is available
["a9c4ab3257e1da3479c984eae9905c2a", "30b5c6fdddbfe7b397fe506400be698d"]
[]
Last good state: -1
Current step: 0
last good state -1
(re-)executing step 0-initial-a9c4ab3257e1da3479c984eae9905c2a
VBoxManage: error: Machine settings file '/Users/john/VirtualBox VMs/mettabox/mettabox.vbox' already exists
VBoxManage: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component Machine, interface IMachine, callee nsISupports
Context: "CreateMachine(bstrSettingsFile.raw(), name.raw(), osTypeId.raw(), Guid(id).toUtf16().raw(), FALSE , machine.asOutParam())" at line 247 of file VBoxManageMisc.cpp
rake aborted!
undefined method `memory_size=' for nil:NilClass
/Users/john/Work/veewee/lib/veewee/session.rb:303:in `create_vm'
/Users/john/Work/veewee/lib/veewee/session.rb:166:in `block in build'
/Users/john/Work/veewee/lib/veewee/session.rb:560:in `transaction'
/Users/john/Work/veewee/lib/veewee/session.rb:163:in `build'
/Users/john/Work/veewee/Rakefile:87:in `block in <top (required)>'
/Users/john/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rake.rb:634:in `call'
/Users/john/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rake.rb:634:in `block in execute'
…
/Users/john/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rake.rb:2013:in `top_level'
/Users/john/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rake.rb:1992:in `run'
/Users/john/.rvm/rubies/ruby-1.9.2-p0/bin/rake:35:in `<main>'
It isn't until we reach the last installed version of Ruby that execution halts.
Discussion
Does anyone have any idea what's going on here? Has anyone seen this "failover"-like behavior before? It seems strange to me that the first exception would not halt execution as it did with one interpreter, but I wonder if there are things happening when RVM is installed that we Ruby developers are not considering.
Since rvm rake is SUPPOSED to run the rake task against all versions of Ruby under RVM's control I think it's doing what is expected: rvm help shows:
rake - runs a rake task against specified and/or all rubies
Specifically requesting help for rake shows:
$ rvm help rake
Rake
RVM allows you to run rake tasks across multiple ruby versions, for example:
∴ rvm 1.8.6,1.9.1 rake spec
JSON Summary
Adding a --json flag prior to the word 'rake' and a JSON summary will be printed out at the end of the run.
YAML Summary
Adding a --yaml flag prior to the word 'rake' and a YAML summary will be printed out at the end of the run.
If you are trying to run a rake task, you do not have to involve RVM. Set your desired Ruby version with RVM first, then run the task:
rvm 1.9.2
rake some_task
the error you are mentioning is not a problem of different ruby vms.
Could it be you have upgrade to Virtualbox 4.X because the new vagrant needs it?
Some functions of the virtualbox on which veewee is dependent are (not yet) ported to Virtualbox 4.x
I'm working around this now by execing the virtualbox commands directly. Funny that while implementing the update, I hit the exact same error.
Patrick (veewee inspirator)

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