travis.ci keeps on failing when running "bundle exec rake" - ruby

I am trying to get automated testing sorted out with Travis.ci. However, at the moment the build keeps on failing when trying to execute bundle exec rake.
This is what I see...
$ bundle exec rake
rake aborted!
Don't know how to build task 'default'
/home/travis/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `eval'
/home/travis/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `<main>'
(See full trace by running task with --trace)
The command "bundle exec rake" exited with 1.
Done. Your build exited with 1.
My unit tests are in the test folder in the main directory and is named test_np_search.rb. I understand that I am somehow supposed to point travis to this location in order to run the unit tests but I have no idea how to do this.
I have read the ruby related documentation on travis.ci a number of times and have looked online for tutorials, however I have been unable to get this to work.
The whole github repository in question is here: https://github.com/IsmailM/NeuroPeptideSearch
The Travis.CI link is here: https://travis-ci.org/IsmailM/NeuroPeptideSearch
I have been trying to get this sorted for over a week now with any success and so would be highly grateful if anyone could help me.
Many Thank

if you want to execute bundle exec rake on travis, you will have to make sure, that it runs on your local machine!
if you call rake without providing a task-name, it will assume that you want to run the default-task.
if you want to run your minitest testsuite as a default-task, you have to do this:
require "rake/testtask"
Rake::TestTask.new do |t|
t.pattern = "test/**/*_test.rb"
end
task default: :test

Related

Rake aborted with zero failed test cases

For my product I use rake for the test-case-execution based on Watir and Selenium. The execution is handled by Jenkins.
In the last two runs my test-suite has ran successful (0 errors/failures) anyway in the end of the log I can see, that rake throws and error anyway which leads to a negative run on jenkins because rake has not ended with RC0. Even if the rake message is "Rake aborted" the test-results are written and found by jenkins successfully.
Output:
96 tests, 3992 assertions, 0 failures, 0 errors, 0 skips
Writing XML reports to /home/test/admin/jenkins/system/workspace/projectname/Tests/results
rake aborted!
Version
> gem list rake
rake (12.0.0)
Updating rake to a new version is not possible at the moment because it is a company-wide used machine and for some reason this problem only occures for us.
Nothing more is printed out by rake.
Any ideas what could cause the problem or where to find more informations?

Ruby: run rake task to execute ruby scripts

I have a bunch of Ruby scripts and I'd like to start them with a Rake task.
A simplified version to illustrate my issue:
export_stats.rake:
desc 'Export statistics'
task :export_stats do
puts "executing: export_stats.rb #{START_MONTH} #{END_MONTH} #{OUTPUT} #{ENVIRONMENT}"
ruby "export_stats.rb #{START_MONTH} #{END_MONTH} #{OUTPUT} #{ENVIRONMENT}"
end
rake aborted! elk-stack/export_stats.rake Don't know how to build task
'export_stats'
the export_stats.rb file is in same directory with export_stats.rake
the rake gem is installed and if I run
rake export_stats
I get an error:
rake aborted!
Don't know how to build task 'export_stats'
What am I missing?
If I understand you correctly you have a folder with some ruby scripts and you are trying to run a rake task that is located in the same folder. I assume you are not using any application framework like Rails (because you did tag the question only with "Ruby").
Do you have a Rakefile in same directory? If so does it contain a statement to load the specific files to run?
# Rakefile
#!/usr/bin/env rake
load 'export_stats.rake'
You have a typo.
The code says export_stats, and the error says exports_stats.
There's an extra s.
Read the error message carefully! ;)

How do I run Rails/Rake from another directory?

Without cd-ing into the root directory of my Rails application, how can I execute a Rails or Rake command for that application.
I tried:
bundle exec rake my_tasks:do_stuff BUNDLE_GEMFILE=/PATH/TO/RAILS_APP/Gemfile
among other combinations, to no avail.
[Update]
The issue is actually two-fold, bundle doesn't know where the gemfile is and rake doesn't know what to run.
To use Bundler:
BUNDLE_GEMFILE=/PATH/TO/RAILS_APP/Gemfile bundle exec ...
Note that BUNDLE_GEMFILE has to go before 'bundle exec'.
To use Rake:
rake -f /PATH/TO/RAILS_APP/Rakefile my_task:do_stuff
To use Rails console:
????
Have yet to figure out how to enter the Rails console from another directory. Looking at the source, I think it may not be possible, because it eventually does File.join('script','rails') to kick off the rails process.
Without you showing the error message you are getting, I'm assuming it has less to do with Bundler than it does Rake. When the rake command is run, it searches for a Rakefile starting in the current directory and traversing up the tree until it finds one. You can override this behavior by explicitly specifying a Rakefile in the options to the rake command. This is done using the -f <RAKEFILE> option.
eg.
bundle exec rake -f /PATH/TO/RAILS_APP/Rakefile my_task:do_stuff
Bear in mind that your Rake tasks have to be "CWD agnostic". Most tasks and scripts are as they tend to get the project directory based on a path relative to a known file in the directory tree. You probably already understand that, but it's worth mentioning in case the tasks are expecting the current working directory to actually be the rails root. That would be a case where running them from outside the project could potentially be dangerous.

On Travis how do I modify tests to use minitest instead of rspec?

The link for ask question on Travis dot com sent me here. My tests fail because I'm using minitest in my gem but travis uses rspec. Is there a way to get travis to do that also? Of course I can always modify my tests to use rspec but I'm not sure how to get tests or spec from my structure of my tests. They all have assert_equal which is not recognized by respec as a valid method. Is there a common way to make either test work with the same *_spec.rb files?
This is another option to run your test in your .travis.yml:
script:
- bin/rails test
Remeber to install the gems before run the scripts.
I found in the docs that it is possible to define custom commands for running tests (rather than the default bundle exec rake test) by placing these lines in .travis.yml
script:
- bundle exec rake build
- bundle exec rake builddoc

Execute tests for another app from a rake file

I'm trying to execute cucumber tests for a project within a rake file in another project.
Currently I am trying this:
system "cd /path/to/project;rvm use --create 1.9.2-p290#test; cucumber features/test.feature"
This works for the cd, and the rvm seems to work if I run which ruby after the rvm use... but the problem is that the cucumber gem seems to be called from the current folder (not the app to test folder).
The error I get is:
cucumber is not part of the bundle. Add it to Gemfile. (Gem::LoadError)
It seems to be using the local gemset version of cucumber rather than the #test gemset.
Any thoughts on this?
Or is there a better way to run cucumber tests for another project that relies on rvm & a different bundle?
I've also been trying to do exactly the same thing; run an application's tests (or any rake task) from inside another 'control' application.
Reason: (just so I don't get served with a "why on earth?")
I am trying to build an application (rather like cruisecontrol.rb ) which can monitor, schedule and review the specs for a set of apps.
After some digging around in cruisecontrol's source I found that Bundler provides a solution;
Bundler.with_clean_env do
system "rake spec"
end
see line56 of https://github.com/thoughtworks/cruisecontrol.rb/blob/master/lib/platform.rb
That steps out of the bundle and the command is run without the control app's gems.
BUT as is most likely, the command uses bundle exec then this stops working.
Bundler.with_clean_env { system "bundle exec rake spec" }
And you are right back to the exact same problem. This is caused by some bundler variables still existing and being inherited by the sub-shell. Full (very good) explanation here.
The solution is to change the with_clean_env method on bundler like this;
BUNDLER_VARS = %w(BUNDLE_GEMFILE RUBYOPT BUNDLE_BIN_PATH)
module Bundler
def self.with_clean_env &blk
bundled_env = ENV.to_hash
BUNDLER_VARS.each{ |var| ENV.delete(var) }
yield
ensure
ENV.replace(bundled_env.to_hash)
end
end
above code from here
I put that in the environment.rb of my control application (it should probably be in a initializer?) and now I can run the specs of another app from within the control app.
#in control app
result = nil
Dir.chdir(test_app_path) #move into test app
Bundler.with_clean_env { result = `bundle exec rake spec` } #run test apps specs
puts result #display result inside control app
Changing the ; in your script to && seems to work.

Resources