Very new to Travis CI. Build failed with The command "bundle exec rake" exited with 1.
The build was passing before my latest changes which involved using Fileutils to write to gem directory so I'm assuming this is the culprit.
I found this : https://stackoverflow.com/a/40643667/9526393 but still no luck
Any ideas?
Build: https://travis-ci.org/AlphaDaniel/ruby_doc/builds/356485701?utm_source=github_status&utm_medium=notification
Repo: https://github.com/AlphaDaniel/ruby_doc
rake aborted!
Errno::ENOENT: No such file or directory # rb_sysopen - /home/travis/build/AlphaDaniel/ruby_doc/vendor/bundle/ruby/2.2.0/gems/ruby_doc-2.2.0/favs.txt
/home/travis/build/AlphaDaniel/ruby_doc/config/environment.rb:23:in `<top (required)>'
/home/travis/build/AlphaDaniel/ruby_doc/Rakefile:5:in `require_relative'
/home/travis/build/AlphaDaniel/ruby_doc/Rakefile:5:in `<top (required)>'
/home/travis/.rvm/rubies/ruby-2.2.3/bin/bundle:30:in `block in <main>'
/home/travis/.rvm/rubies/ruby-2.2.3/bin/bundle:22:in `<main>'
Errno::ENOENT: No such file or directory # utime_internal - /home/travis/build/AlphaDaniel/ruby_doc/vendor/bundle/ruby/2.2.0/gems/ruby_doc-2.2.0/favs.txt
/home/travis/build/AlphaDaniel/ruby_doc/config/environment.rb:23:in `<top (required)>'
/home/travis/build/AlphaDaniel/ruby_doc/Rakefile:5:in `require_relative'
/home/travis/build/AlphaDaniel/ruby_doc/Rakefile:5:in `<top (required)>'
/home/travis/.rvm/rubies/ruby-2.2.3/bin/bundle:30:in `block in <main>'
/home/travis/.rvm/rubies/ruby-2.2.3/bin/bundle:22:in `<main>'
(See full trace by running task with --trace)
The problem here becomes more clear if you read the error message and the stack trace. Errno::ENOENT: No such file or directory basically means that Ruby can not find a specific file or directory, in your case it's /home/travis/build/AlphaDaniel/ruby_doc/vendor/bundle/ruby/2.2.0/gems/ruby_doc-2.2.0/favs.txt. The last line of code that ran is a call to FileUtils.touch (in config/environment.rb:23).
You may have asked yourself "But shouldn't that create this file if it does not yet exist?". The answer to that is: yes, however only when the parent directories exist as well. When you gem install your gem, those directories will be created for you. This is not the case when you clone your repository and run rake (which is also what Travis automatically does for you when it sees a Ruby project).
To solve that, I recommend you to change the fav_dir method's body to something like this:
File.expand_path("../favs.txt", __dir__)
Looks a bit magic at first glance, but it isn't really: __dir__ is a Ruby method which returns the absolute path of the directory of the file from which this method is called. In this case this would be e.g. /usr/home/foo/dev/ruby_doc/config. Finally, File.expand_path allows us to resolve relative paths, in this case the final result will be /usr/home/foo/dev/ruby_doc/favs.txt.
This way you don't need to specify any absolute paths or make assumptions about a directory layout, and also ensure that the path exists (as the source file's directory and its parent always exist).
Related
I am trying to get test-first-ruby-master as instructed but I am getting multiple errors. This is the structure of the files/directory in test-first-ruby-master:
Gemfile Gemfile.lock README.md lib spec
lib contains ruby files and spec contains spec files.
I am trying to execute 00_hello_spec.rb file on my terminal but it doesn't work.
What I have tried
require "lib/00_hello.rb"
require_relative "lib/00_hello.rb"
Errors I get
supritkumars-MacBook-Pro:test-first-ruby-master supritkumarshah$ rspec spec/00_hello_spec.rb
/Users/supritkumarshah/Desktop/test-first-ruby-master/spec/00_hello_spec.rb:103:in `require': cannot load such file -- lib/00_hello.rb (LoadError)
from /Users/supritkumarshah/Desktop/test-first-ruby-master/spec/00_hello_spec.rb:103:in `<top (required)>'
from /Users/supritkumarshah/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1226:in `load'
from /Users/supritkumarshah/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1226:in `block in load_spec_files'
from /Users/supritkumarshah/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1224:in `each'
from /Users/supritkumarshah/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1224:in `load_spec_files'
from /Users/supritkumarshah/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:97:in `setup'
from /Users/supritkumarshah/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:85:in `run'
from /Users/supritkumarshah/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:70:in `run'
from /Users/supritkumarshah/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:38:in `invoke'
from /Users/supritkumarshah/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.2.3/exe/rspec:4:in `<top (required)>'
from /Users/supritkumarshah/.rvm/gems/ruby-2.3.0/bin/rspec:23:in `load'
from /Users/supritkumarshah/.rvm/gems/ruby-2.3.0/bin/rspec:23:in `<main>'
from /Users/supritkumarshah/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
from /Users/supritkumarshah/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'
Thank you
The require is failing because you're requiring a relative path, 'lib/00_hello.rb', but the directory it's relative to (the root of your project) is not in the list of directories that Ruby is looking in for files to require (the load path, $LOAD_PATH).
There are lots of ways to fix this. Here are some:
Tell rspec to add the root of your project to the load path. Since that's your current directory, you can use .:
rspec -I. spec/00_hello_spec.rb
Change your spec to require_relative '../lib/00_hello'. This works regardless of the current directory or load path — a good idea in command-line programs, although not so important for a learning project.
As B Seven answered, change your spec to require './lib/00_hello'. This requires you to run rspec in the root of your project.
You can even remove the require altogether! When you run rspec, if the current directory has subdirectories named lib and/or spec, rspec adds them to the load path. This also requires you to run rspec in the root of your project. This solution won't work if you need the require when running your program for real (not under rspec).
Note that including the .rb in the filename you required did not cause the problem, but it's not necessary.
Although Dave's answer is correct, I prefer to use:
require './lib/00_hello'
Did you tried adding require 'bundler/setup' at the top of your test helper file?
I'm using Ruby 2.1.5 and whenever I download code that uses require to include a file, I get errors. Changing require to require_relative fixes the problem. For example, if I use the example code from rspec, I get the following error output.
mario#crunchbang:~/projects/rspec_test$ rspec bowling_spec.rb
/home/mario/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- bowling (LoadError)
from /home/mario/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/mario/projects/rspec_test/bowling_spec.rb:2:in `<top (required)>'
from /home/mario/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `load'
from /home/mario/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `block in load_spec_files'
from /home/mario/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `each'
from /home/mario/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `load_spec_files'
from /home/mario/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:96:in `setup'
from /home/mario/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:84:in `run'
from /home/mario/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:69:in `run'
from /home/mario/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:37:in `invoke'
from /home/mario/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.1.7/exe/rspec:4:in `<top (required)>'
from /home/mario/.rvm/gems/ruby-2.1.5/bin/rspec:23:in `load'
from /home/mario/.rvm/gems/ruby-2.1.5/bin/rspec:23:in `<main>'
from /home/mario/.rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `eval'
from /home/mario/.rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `<main>'
Is there something wrong with my Ruby set up or can require no longer be used the way it was in earlier versions of Ruby?
require works exactly the same as it did before: it searches the $LOAD_PATH. What has changed is the default $LOAD_PATH: the current directory . was removed from it, for various maintenance and security reasons.
In almost all cases, you don't want to load a file relative to the current working directory anyway (after all, the CWD is controlled by the user, so you don't even know what it is, how could you then reliably load a file from there?), you want to load it relative to the current file … which is exactly what require_relative does.
By the way: this change was relased 7 years ago, made before that, and announced even before that, I don't know where you are getting that code from, but I would be highly suspicious of code that hasn't been maintained for such an extended period of time (almost 10 years).
Require only searches for files in Ruby's load path. Prior to 1.9, the current folder (.) was included in the load path. See Kernel#require
if you've been writing code with paths relative to the current directory it's normal that require doesn't work. You can either add . to the load path:
rspec -I . my_script.rb
Or as you have found, require_relative resolves the argument relative to the path to the file it is contained in. People also used to use __FILE__ to achieve this before require_relative was available.
You can also add the -I option to your .rspec file or setup your load paths in your spec_helper.rb
When you use require you need to pass the absolute path for the file.
require_relative is working as it depends on the relative path.
Edit the code part where you require the file to absolute file path and it should work well.
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.
I am attempting to take an interactive Ruby test to no avail.
I downloaded the zip file with no problems and followed the directions for
the terminal command line where I continue to get the following error. I
am using "Ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin10.8.0]".
If anyone can offer any help or suggestions thank you in advance.
INSTRUCTIONS:
Install RSpec
gem install rspec
Enter the course directory. (That's the same directory that this
index.html file is in.)
cd learn_ruby
Enter the 00_hello lab.
cd 00_hello
Open a terminal in this directory
cd 00_hello
This directory is the starting point for this exercise. It contains a
spec file and you'll be adding a ruby file to (eventually) make the
specs pass.
Run the test
rake
Watch it fail
You should see an error. Don't get scared! Try to read it and figure out
what the computer wants to tell you. Somewhere on the first line it
should say something like
no such file to load -- test-first-teaching/hello/hello (LoadError)
I do not get this error message, I get the one below:
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb,
Rakefile.rb)
/usr/local/rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in `eval'
/usr/local/rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in
`<main>'
(See full trace by running task with --trace)
When I run rake --trace I receive:
rake --trace
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb,
Rakefile.rb)
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:632:in
`raw_load_rakefile'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:94:in
`block in load_rakefile'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:165:in
`standard_exception_handling'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:93:in
`load_rakefile'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:77:in
`block in run'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:165:in
`standard_exception_handling'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:75:in
`run'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/bin/rake:33:in
`<top (required)>'
/usr/local/rvm/gems/ruby-1.9.3-p392/bin/rake:19:in `load'
/usr/local/rvm/gems/ruby-1.9.3-p392/bin/rake:19:in `<main>'
/usr/local/rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in `eval'
/usr/local/rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in
`<main>'
you have to cd into your project directory before you can run rake routes
every time i execute rspec, dosen't matter what I have done, if the code is wrong it tells:
nev3rkill#nev3rkill-virtual-machine ~/Documentos/ruby $ rspec
/home/nev3rkill/.rvm/gems/ruby-1.9.2-p318/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load': no such file to load -- /home/nev3rkill/Documentos/ruby/spec (LoadError)
from /home/nev3rkill/.rvm/gems/ruby-1.9.2-p318/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `block in load_spec_files'
from /home/nev3rkill/.rvm/gems/ruby-1.9.2-p318/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `map'
from /home/nev3rkill/.rvm/gems/ruby-1.9.2-p318/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load_spec_files'
from /home/nev3rkill/.rvm/gems/ruby-1.9.2-p318/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:22:in `run'
from /home/nev3rkill/.rvm/gems/ruby-1.9.2-p318/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in `run_in_process'
from /home/nev3rkill/.rvm/gems/ruby-1.9.2-p318/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in `run'
from /home/nev3rkill/.rvm/gems/ruby-1.9.2-p318/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10:in `block in autorun'
nev3rkill#nev3rkill-virtual-machine ~/Documentos/ruby $
I have tested with a lot of versions, with ruby 1.9.3,1.9.2 but i don't know. Is it normal?
Unless you're in a path with a spec directory (e.g. the root of your rails project), you also need to tell rspec which spec files to run, either by passing it a directory or file. e.g:
$ rspec path/to/specs/
Will run all the specs in the path/to/specs/ path (recursively), or:
$ rspec spec/your_specs.rb
will run the specs in the spec/your_specs.rb file.