Terminal error using Test First Ruby - ruby

I'm just starting Test First Ruby & I'm having trouble running rakes to start solving problems.
I think it's either my version of RSpec or my version of Ruby that's causing the error.
Here's the error,
AT MacBook-Pro:01_temperature AT$ rake
(in /Users/AT/Desktop/learn_ruby)
/Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- temperature (LoadError)
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/AT/Desktop/learn_ruby/01_temperature/temperature_spec.rb:18:in `<top (required)>'
from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `load'
from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `block in load_spec_files'
from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `each'
from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `load_spec_files'
from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.1.2/lib/rspec/core/runner.rb:96:in `setup'
from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.1.2/lib/rspec/core/runner.rb:84:in `run'
from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.1.2/lib/rspec/core/runner.rb:69:in `run'
from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.1.2/lib/rspec/core/runner.rb:37:in `invoke'
from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.1.2/exe/rspec:4:in `<top (required)>'
from /usr/bin/rspec:23:in `load'
from /usr/bin/rspec:23:in `<main>'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -S rspec /Users/AT/Desktop/learn_ruby/01_temperature/temperature_spec.rb -I/Users/AT/Desktop/learn_ruby/01_temperature -I/Users/AT/Desktop/learn_ruby/01_temperature/solution -f documentation -r ./rspec_config failed
I had a similar problem a few minutes ago but fixed by uninstalling RSpec v-3, and installing v-2.14.
Any help would be appreciated!

Your file temperature_spec is requiring what I presume is the source for the class under test, temperature - but the RSpec loader is not able to resolve the path for this file.
It would be helpful for you to post both the source of your rspec file and your class under test.

Related

I'm trying to run a rake test ruby / sinatra and its telling me rake aborted! I'm not sure what to do

Here is the what my terminal is showing me..
user#Users-MacBook-Pro palindrome_app % bundle exec rake test
/Users/user/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/mustermann-1.1.1/lib/mustermann.rb:73:in `new': Hash can't be coerced into Mustermann::Pattern (TypeError)
from /Users/user/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/mustermann-1.1.1/lib/mustermann.rb:70:in `block in new'
from /Users/user/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/mustermann-1.1.1/lib/mustermann.rb:70:in `map'
from /Users/user/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/mustermann-1.1.1/lib/mustermann.rb:70:in `new'
from /Users/user/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.0.3/lib/sinatra/base.rb:1641:in `compile'
from /Users/user/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.0.3/lib/sinatra/base.rb:1629:in `compile!'
from /Users/user/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.0.3/lib/sinatra/base.rb:1271:in `error'
from /Users/user/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.0.3/lib/sinatra/base.rb:1839:in `<class:Base>'
from /Users/user/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.0.3/lib/sinatra/base.rb:894:in `<module:Sinatra>'
from /Users/user/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.0.3/lib/sinatra/base.rb:22:in `<top (required)>'
from /Users/user/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.0.3/lib/sinatra/main.rb:1:in `require'
from /Users/user/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.0.3/lib/sinatra/main.rb:1:in `<top (required)>'
from /Users/user/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.0.3/lib/sinatra.rb:1:in `require'
from /Users/user/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/sinatra-2.0.3/lib/sinatra.rb:1:in `<top (required)>'
from /Users/user/Desktop/repos/palindrome_app/app.rb:1:in `require'
from /Users/user/Desktop/repos/palindrome_app/app.rb:1:in `<top (required)>'
from /Users/user/Desktop/repos/palindrome_app/test/test_helper.rb:3:in `require_relative'
from /Users/user/Desktop/repos/palindrome_app/test/test_helper.rb:3:in `<top (required)>'
from /Users/user/Desktop/repos/palindrome_app/test/site_pages_test.rb:1:in `require_relative'
from /Users/user/Desktop/repos/palindrome_app/test/site_pages_test.rb:1:in `<top (required)>'
from /Users/user/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rake-13.0.3/lib/rake/rake_test_loader.rb:17:in `require'
from /Users/user/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rake-13.0.3/lib/rake/rake_test_loader.rb:17:in `block in <main>'
from /Users/user/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rake-13.0.3/lib/rake/rake_test_loader.rb:5:in `select'
from /Users/user/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rake-13.0.3/lib/rake/rake_test_loader.rb:5:in `<main>'
rake aborted!
Command failed with status (1)
/Users/user/.rbenv/versions/3.0.0/bin/bundle:23:in `load'
/Users/user/.rbenv/versions/3.0.0/bin/bundle:23:in `<main>'
Tasks: TOP => test
(See full trace by running task with --trace)
tl;dr: Upgrade sinatra to version 2.1.0. (Or, downgrade ruby to v2.7.)
You are running old gem versions (in particular, sinatra v2.0.3), with the latest version of ruby (v3.0.0). You may run into various compatibility problems by doing that, because you could be missing crucial ruby 3.0 compatibility updates from those libraries.
There are various mentions of ruby 2.7+ keyword deprecation fixes in the sinatra changelog.
Specifically, this error:
gems/3.0.0/gems/sinatra-2.0.3/lib/sinatra/base.rb:1629:in `compile!'
Was fixed by this change in this PR, which shipped as part of sinatra v2.0.8. Also, additional fixes were added as part of the v2.1.0 release.

rspec gets "undefined method `build_rb_world_factory' for nil"

I'm updating a Rails 3.2 app to Ruby 2.2.2. I've pulled the Rails version up to 3.2.22, which is necessary for Ruby 2.2.2. That went relatively well but prompted a Cucumber update, from 1.2.1 to 1.3.20. (I don't recall the details, because that was several failed efforts ago, but I think my features were passing but then exiting false before I did this.)
Now Cucumber features run fine (albeit with a ton of unrelated Ruby 2.2.2 warnings), but rspec does not. Specifically, when I run rake spec I get this error:
/path/to/gems/cucumber-1.3.20/lib/cucumber/rb_support/rb_dsl.rb:15:in `build_rb_world_factory': undefined method `build_rb_world_factory' for nil:NilClass (NoMethodError)
The stack trace leads through Capybara (2.4.4, pinned for other reasons), ActiveSupport, and Bundler back up to rspec-core.
All my searches trying to find similar issues just lead to the code, because it seems like the only place this method name exists is in code.
Why am I getting this error from Capybara/Cucumber when running rspec? How can I fix it?
ETA: Stack trace, with paths condensed a bit:
/path/to/gems/cucumber-1.3.20/lib/cucumber/rb_support/rb_dsl.rb:15:in `build_rb_world_factory': undefined method `build_rb_world_factory' for nil:NilClass (NoMethodError)
from /path/to/gems/cucumber-1.3.20/lib/cucumber/rb_support/rb_dsl.rb:50:in `World'
from /path/to/gems/capybara-2.4.4/lib/capybara/cucumber.rb:4:in `<top (required)>'
from /path/to/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:251:in `require'
from /path/to/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:251:in `block in require'
from /path/to/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:236:in `load_dependency'
from /path/to/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:251:in `require'
from /path/to/gems/capybara-screenshot-0.2.2/lib/capybara-screenshot.rb:96:in `<top (required)>'
from /path/to/gems/bundler-1.10.6/lib/bundler/runtime.rb:76:in `require'
from /path/to/gems/bundler-1.10.6/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /path/to/gems/bundler-1.10.6/lib/bundler/runtime.rb:72:in `each'
from /path/to/gems/bundler-1.10.6/lib/bundler/runtime.rb:72:in `block in require'
from /path/to/gems/bundler-1.10.6/lib/bundler/runtime.rb:61:in `each'
from /path/to/gems/bundler-1.10.6/lib/bundler/runtime.rb:61:in `require'
from /path/to/gems/bundler-1.10.6/lib/bundler.rb:134:in `require'
from /path/to/app/config/application.rb:13:in `<top (required)>'
from /path/to/app/config/environment.rb:2:in `require'
from /path/to/app/config/environment.rb:2:in `<top (required)>'
from /path/to/app/spec/spec_helper.rb:10:in `require'
from /path/to/app/spec/spec_helper.rb:10:in `<top (required)>'
from /path/to/app/spec/controllers/academic_years_controller_spec.rb:1:in `require'
from /path/to/app/spec/controllers/academic_years_controller_spec.rb:1:in `<top (required)>'
from /path/to/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1226:in `load'
from /path/to/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1226:in `block in load_spec_files'
from /path/to/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1224:in `each'
from /path/to/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1224:in `load_spec_files'
from /path/to/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:97:in `setup'
from /path/to/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:85:in `run'
from /path/to/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:70:in `run'
from /path/to/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:38:in `invoke'
from /path/to/gems/rspec-core-3.2.3/exe/rspec:4:in `<main>'
/path/to/ruby/ruby-2.2.2/bin/ruby -I/path/to/gems/rspec-core-3.2.3/lib:/path/to/gems/rspec-support-3.2.2/lib /path/to/gems/rspec-core-3.2.3/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb failed
My hunch is that there's a configuration file which needs to be rebuilt somewhere.
From your stacktrace - the capybara-screenshot gem is requiring capybara/cucumber even though you're running specs which aren't using cucumber. This means World is called from capybara/cucumber against a non-initialized cucumber, and gives the error. The version of capybara-screenshot you're using is really old, and the code that required capybara/cucumber has since been removed so you should probably update the version of capybara-screenshot you're using, and add
require 'capybara/cucumber'
require 'capybara-screenshot/cucumber'
to your env.rb or other cucumber support file

problem with running ruby application

I am using RubyMine on windows so I can run a given ruby on rails application. When I click run I get the following error:
C:\Ruby192\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) "F:/Aurora Zoo Project/zooniverse-Juggernaut-a46b0ba558f0cbeb8e9b581513691566d7f19c2f/script/rails" server -b 127.0.0.1 -p 3000 -e development
C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql-2.8.1-x86-mingw32/lib/mysql.rb:7:in `require': 126: The specified module could not be found. - C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql-2.8.1-x86-mingw32/lib/1.9/mysql_api.so (LoadError)
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql-2.8.1-x86-mingw32/lib/mysql.rb:7:in `rescue in <top (required)>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql-2.8.1-x86-mingw32/lib/mysql.rb:2:in `<top (required)>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.18/lib/bundler/runtime.rb:68:in `require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.18/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.18/lib/bundler/runtime.rb:66:in `each'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.18/lib/bundler/runtime.rb:66:in `block in require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.18/lib/bundler/runtime.rb:55:in `each'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.18/lib/bundler/runtime.rb:55:in `require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.18/lib/bundler.rb:120:in `require'
from F:/Aurora Zoo Project/zooniverse-Juggernaut-a46b0ba558f0cbeb8e9b581513691566d7f19c2f/config/application.rb:7:in `<top (required)>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.5/lib/rails/commands.rb:28:in `require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.5/lib/rails/commands.rb:28:in `block in <top (required)>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.5/lib/rails/commands.rb:27:in `tap'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.5/lib/rails/commands.rb:27:in `<top (required)>'
from F:/Aurora Zoo Project/zooniverse-Juggernaut-a46b0ba558f0cbeb8e9b581513691566d7f19c2f/script/rails:9:in `require'
from F:/Aurora Zoo Project/zooniverse-Juggernaut-a46b0ba558f0cbeb8e9b581513691566d7f19c2f/script/rails:9:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
Process finished with exit code 1
I am not really familiar with ruby, but it says something about "mysql" which I have installed and added to the PATH variable.
Any help? Thx
The mysql gem that you installed expect an specific version of MySQL libmysql.dll be available in your system (when you gem install mysql it display the proper legend in the console).
mysql_api.so is failing to load and thus, generating the error you're seeing.
I've blogged about an alternate approach to install and compile the MySQL component independently of the version of MySQL you have installed.
http://blog.mmediasys.com/2011/07/07/installing-mysql-on-windows-7-x64-and-using-ruby-with-it/
Hope that helps.
This is probably version problem. I do had a same issue when i used old mysql version with new mysql gem.
Kindly find the correctly gem required for you mysql server.

How to get Ruby to work (on .gitbook)?

I'm trying to get Ruby to run so that I can draft a contribution to the Git Community Book.
I'm on windows XP. I've downloaded Ruby 1.9.2 and the dev kit. I've downloaded the gitbook and its files .gitbook
I'm now at the situation where it tells me it can't find the script files, and after trying updating the windows Path variable, and moving the .gitbook folder to various locations I still can't make any progress..
The trace option gave the following (sorry it doesn't format properly!). It still looks like some silly path error but help is needed...
D:\Ruby192\bin\gitbook>rake html --trace
(in D:/Ruby192/bin/gitbook)
rake aborted!
no such file to load -- script/merge
<internal:lib/rubygems/custom_require>:29:in `require'
<internal:lib/rubygems/custom_require>:29:in `require'
D:/Ruby192/bin/gitbook/Rakefile:1:in `<top (required)>'
D:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2383:in `load'
D:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2383:in `raw_load_rakefile'
D:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2017:in `block in load_rakefile'
D:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
D:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2016:in `load_rakefile'
D:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2000:in `block in run'
D:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
D:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
D:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/bin/rake:31:in `<top (required)>'
D:/Ruby192/bin/rake:19:in `load'
D:/Ruby192/bin/rake:19:in `<main>'
Any advice welcome.
Rakefile in github is like,
require 'script/merge'
to make it work in ruby 1.9.x edit as follows
require './script/merge'

Problem using require command

I am simply requiring a file present in the same folder as the testfile however I am getting this wierd message again and again...
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- a.rb (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from C:/dummyFirefox/test_a.rb:1:in `<top (required)>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `block in load_spec_files'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `map'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load_spec_files'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:18:in `run'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:55:in `run_in_process'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:46:in `run'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:10:in `block in autorun'
the code that I write in my testfile test_a.rb is simply:
require 'a.rb'
and when I issue the command : rspec test_a.rb the message is the above mentioned error.
I am using ruby-1.9.2 for development.
Hope I don't miss any details.
Thanks in advance.
In Ruby 1.9.2 the current working directory is no longer part of the load path ($LOAD_PATH or $:). You have to add it manually using:
$LOAD_PATH.unshift '.'
or
$:.unshift '.'
Or you can require the file explicitly:
require './test_a.rb'

Resources