Skip to content

Instantly share code, notes, and snippets.

@tompata
Created September 10, 2013 17:51
Show Gist options
  • Select an option

  • Save tompata/6513021 to your computer and use it in GitHub Desktop.

Select an option

Save tompata/6513021 to your computer and use it in GitHub Desktop.
A simple CI rake task for running instant and daily builds with Rspec and Cucumber
if [ :development, :test, :cucumber ].include?( Rails.env.to_sym )
# the 'require' calls are here on a purpose. On staging the rspec and cucumber gems are not
# present and since rake reads up the content of the .rake files, it will fail, because it
# will try to load things, which are not there
require 'rspec/core/rake_task'
require 'cucumber/rake/task'
namespace :ci do
namespace :build do
desc "Internal task for rspec execution, hence DO NOT CALL IT BY HAND!"
RSpec::Core::RakeTask.new(:rspec_internal) do |t|
t.rspec_opts = ["--format JUnit", '-o log/TEST-spec.xml']
end
# cucumber::rake::task does not like desc, it should be provided as a constructor argument
Cucumber::Rake::Task.new(:cucumber_internal, "Internal task for cucumber execution, hence DO NOT CALL IT BY HAND!") do |t|
t.cucumber_opts = "--profile cruisecontrol"
end
desc "Executes the rspec and cucumber tests on the latest version"
task :commit => :clean do
Rake::Task['db:migrate'].invoke
Rake::Task['db:test:load'].invoke
Rake::Task['db:test:purge'].invoke
Rake::Task['ci:build:rspec_internal'].invoke
Rake::Task['ci:build:cucumber_internal'].invoke
end
desc "Executes the test cases several times, generates coverage and metrics data and checks that the test data up/down is working"
task :daily => :clean do
Rake::Task['db:migrate'].invoke
Rake::Task['db:test:load'].invoke
Rake::Task['db:test:purge'].invoke
# make sure that we don't have a test cases which fails occasionally
4.times do
Rake::Task['ci:build:rspec_internal'].invoke
# without this, rake won't allow multiple calls on the task (http://codequietly.com/blog/2010/06/rake-tasks-101)
Rake::Task['ci:build:rspec_internal'].reenable
Rake::Task['ci:build:cucumber_internal'].invoke
Rake::Task['ci:build:cucumber_internal'].reenable
end
end
desc "deletes files from the log folder"
task :clean do
FileUtils.rm_rf(Dir.glob("log/*.sha1"))
FileUtils.rm_rf(Dir.glob("log/test.log"))
FileUtils.rm_rf(Dir.glob("log/*.html.log"))
FileUtils.rm_rf(Dir.glob("log/coverage*"))
FileUtils.rm_rf(Dir.glob("log/TEST-*.xml"))
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment