I'm applying to AppAcademy and need to do some exercises so I downloaded the ZIP as required from https://github.com/appacademy/test-first-ruby
I saved the file to my desktop and ran bundle install while inside the folder like the. Then through the terminal I go to the spec folder where the exercises are located and run the following command:
bundle exec rspec spec/00_hello_spec.rb
I get the following error:
Macintosh-2:spec Michael$ bundle exec rspec spec/00_hello_spec.rb
/Users/Michael/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core 2.99.1/lib/rspec/core/configuration.rb:1065:in `load': cannot load such file -- /Users/Michael/Desktop/RubyCodes/test-first-ruby-master/spec/spec/00_hello_spec.rb (LoadError)
from /Users/Michael/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1065:in `block in load_spec_files'
from /Users/Michael/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1065:in `each'
from /Users/Michael/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1065:in `load_spec_files'
from /Users/Michael/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-2.99.1/lib/rspec/core/command_line.rb:18:in `run'
from /Users/Michael/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-2.99.1/lib/rspec/core/runner.rb:103:in `run'
from /Users/Michael/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rspec-core-2.99.1/lib/rspec/core/runner.rb:17:in `block in autorun'
I have ruby 2.1.3, bundler 1.7.9, and rspec 2.99.1.
What is causing this error and how can I fix it?
It looks like you may be running the command from the wrong directory. Consider your error message:
`load': cannot load such file -- /Users/Michael/Desktop/RubyCodes/test-first-ruby-master/spec/spec/00_hello_spec.rb (LoadError)
and notice that the spec directory appears twice in the error message's file path. This implies the existence of a spec directory within a spec directory. It's more likely that there is just one spec directory. Within your same terminal context, run the following command to bring you up one directory level:
cd ..
then try your command again:
bundle exec rspec spec/00_hello_spec.rb
You can think of cd as standing for "change directory" while .. represents one directory level above the current level (the current level is represented with a .).
Alternatively, you can run the following command from within the spec directory:
bundle exec rspec 00_hello_spec.rb
Related
Source code of the project for anyone interested: https://github.com/clockworkpc/verbalyser
Ruby version: ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]
From the root directory of this project ("verbalyser") I am trying to run the simple command:
bundle exec exe/verbalyser
But I keep on getting this error message:
bundler: failed to load command: exe/verbalyser (exe/verbalyser)
LoadError: cannot load such file -- verbalyser
exe/verbalyser:2:in `require'
exe/verbalyser:2:in `<top (required)>'
Here are the contents of the file verbalyser/exe/verbalyser, which has been made executable (chmod +x):
#!/usr/bin/env ruby
require "verbalyser"
Here are the contents of the Ruby file that this executable is trying to load:
require "verbalyser/version"
require "verbalyser/conjugation_scraper"
require "verbalyser/cooljugator_scraper"
require "verbalyser/endings_grouper"
require "verbalyser/lemma_matcher"
require "verbalyser/verb_shortlister"
Here is my directory structure:
I had a problem like this. I found the answer to my specific problem somewhere on stack overflow but I can't find the link so I'll repeat what I remember of it.
Basically, the file was recently created and did not exist in bundler's own internal git repository, so I had to add it, and once I did that it worked. I didn't even have to commit the file - just stage it.
I have some chef unit tests that I can run via the command : chef exec rspec
However, I am trying to run these from TeamCity and I am using a rakefile. When I try to execute the rakefile the require 'chefspec' line in the test file causes an error "cannot load such file -- chefspec (LoadError)"
I know chefspec is installed. I am new to Ruby, chefspec, rspec. I know there is mention of a gemspec file and I have tried to create one in the directory where I can run the command chef exec rspec to execute the test. However, when I try to run bundle install I get the error Could not locate Gemfile or .bundle/ directory. Is there a default location of a gemfile when you install ruby? I am pretty lost at this point.
C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire': cannot load such file -- chefspec (LoadErr
or)
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require'
from D:/../spec/octopus_tentacle_spec.rb:1:in'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:in load'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:inblock in load_
spec_files'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1325:in each'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1325:inload_spec_file
s'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:102:in setup'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:88:inrun'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:73:in run'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:41:ininvoke'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/exe/rspec:4:in <top (required)>'
from C:/Ruby22/bin/rspec:23:inload'
from C:/Ruby22/bin/rspec:23:in <main>'
The gemspec files are normally used when you are creating a Ruby gem, and contains the metadata about the Gem you are creating.
when you use bundle install it requires a Gemfile in the directory. The Gemfile works as a manifest file for the gems required for the project in the directory. It is possible that chef exec is looking for this file and will only work with gems specified here.
Try creating a Gemfile with the content
source 'https://rubygems.org'
gem 'rspec'
gem 'chefspec'
you should list other gems you are using in the file.
and then run bundle install
I'm trying to install a gem using Ruby. I keep getting a weird syntax error when I do. Using rvm, latest version, to install. The error message is:
/Users/george/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/psych.rb:370:in `parse': (<unknown>): mapping values are not allowed in this context at line 2 column 30 (Psych::SyntaxError)
from /Users/george/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/psych.rb:370:in `parse_stream'
from /Users/george/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/psych.rb:318:in `parse'
from /Users/george/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/psych.rb:245:in `load'
from /Users/george/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/config_file.rb:333:in `load_file'
from /Users/george/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/config_file.rb:198:in `initialize'
from /Users/george/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/gem_runner.rb:74:in `new'
from /Users/george/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/gem_runner.rb:74:in `do_configuration'
from /Users/george/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/gem_runner.rb:39:in `run'
from /Users/george/.rvm/rubies/ruby-2.1.5/bin/gem:21:in `<main>'
I also get this error when trying to set rvm to use a different ruby version.
There's an error in your rubygems config file. If you're not using a custom config file, look for a file .gemrc in your home folder. It seems there's incorrect content on line 2.
Psych is a YAML parser, so look for something that is incorrect YAML.
It looks like there was an issue in the .gemrc file as well as some other files created in the root folder that were affecting RVM from installing Ruby correctly.
Re-storing the files to the previous state and removing the junk files with rm -rf got everything working.
I am attempting to make a custom test runner using test/unit in ruby
and have followed a tutorial outlined here
http://endofline.wordpress.com/2008/02/11/a-custom-testrunner-to-scratch-an-itch/
however when i try to run on it using the
ruby -rfast_fail_runner example_test.rb --runner fastfail
however i get the error
C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- fast_fail_runner (LoadError)
from C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
You have a file in the current directory named fast_fail_runner.rb, right? Ruby is not finding it. You are following a very old tutorial and I suspect that old versions of Ruby had the current directory (.) on the load path or something like that.
Try replacing -rfast_fail_runner with -r./fast_fail_runner.
Help me understand why this project's tests run when executed directly but do not when run via rake. The error when run via a Rake TestTask:
** Execute test
/home/myockey/.rvm/rubies/ruby-1.9.2-p136/bin/ruby -I"lib:test" "/home/myockey/.rvm/gems/ruby-1.9.2-p136/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/unit/data_test.rb" "test/unit/station_test.rb" "test/unit/raw_test.rb" "test/unit/parser_test.rb" "test/unit/report_test.rb"
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- test/unit/../metar_test_helper.rb (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from test/unit/data_test.rb:4:in `<top (required)>'
from /home/myockey/.rvm/gems/ruby-1.9.2-p136/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `load'
from /home/myockey/.rvm/gems/ruby-1.9.2-p136/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `block in <main>'
from /home/myockey/.rvm/gems/ruby-1.9.2-p136/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `each'
from /home/myockey/.rvm/gems/ruby-1.9.2-p136/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `<main>'
rake aborted!
When I run the script directly I get the following:
myockey#myockey-K61IC:~/opt/joeyates-metar-parser-cdca19f/test/unit$ ruby data_test.rb
Loaded suite data_test
Started
...................................................
Finished in 0.084939 seconds.
51 tests, 121 assertions, 0 failures, 0 errors, 0 skips
The top of the ruby files looks like this:
#!/usr/bin/env ruby
# encoding: utf-8
require File.dirname(__FILE__) + '/../metar_test_helper'
class TestMetarData < Test::Unit::TestCase
Note that I tried adding the .rb file extension to metar_test_helper to no avail. Rest assured that a file named metar_test_helper.rb exists in the parent directory of the file and that it has sufficient permissions to be accessible.
Added a bounty. I know this must be a simple path issue, but I'd really appreciate some guidance solving it and helping me understand it.
Are you using Ruby 1.9.2 in both scenarios?
1.9.2 doesn't include "." in the path ($:), whereas pre-1.9.2 versions do.
To check what version of Ruby you're using, and what the path is, do
STDERR.puts "RUBY_VERSION is #{RUBY_VERSION}"
STDERR.puts "Path is #{$:}"
before the exception-inducing line
require File.dirname(__FILE__) + '/../metar_test_helper'
If that doesn't solve it, ask it what it's requiring, by doing
STDERR.puts "The file I'm requiring is #{File.dirname(__FILE__) + '/../metar_test_helper'}"
and see what it's like in both approaches.
You may want to see other tips on debugging in How do I debug Ruby scripts?
This is just a path issue that you need to resolve. When you are running the test manually you are in the test/unit directory which appears to have that file 1 level up. In the rake task you are at the parent of the test dir (assuming RAILS_HOME).