From ae0014f2c274909f5bc88cf593a46b65b9676ed2 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Mon, 27 Oct 2014 15:46:20 -0200 Subject: [PATCH] Add ci:smoke Rake task for CI environments --- lib/tasks/ci.rake | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+), 0 deletions(-) create mode 100644 lib/tasks/ci.rake diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake new file mode 100644 index 0000000..d7a5668 --- /dev/null +++ b/lib/tasks/ci.rake @@ -0,0 +1,30 @@ +namespace :ci do + + desc 'Continuous integration smoke test' + task :smoke do + if ENV['HEAD'] && ENV['PREV_HEAD'] + from = ENV['PREV_HEAD'] + to = ENV['HEAD'] + changed_files = `git diff --name-only #{from}..#{to}`.split + + # explicitly changed tests + tests = changed_files.select { |f| f =~ /test\/.*_test\.rb$/ } + features = changed_files.select { |f| f =~ /\.feature$/ } + + # match changed code files to their respective tests + changed_files.each do |f| + if f =~ /^(app|lib)\// + basename = File.basename(f, '.rb') + Dir.glob("test/**/#{basename}_test.rb").each do |t| + tests << t unless tests.include?(t) + end + end + end + + sh 'testrb', *tests unless tests.empty? + sh 'cucumber', *features unless features.empty? + sh 'cucumber', '-p', 'selenium', *features unless features.empty? + end + end + +end -- libgit2 0.21.2