Commit ae0014f2c274909f5bc88cf593a46b65b9676ed2
1 parent
8fbadc47
Exists in
master
and in
29 other branches
Add ci:smoke Rake task for CI environments
Assumes the CI environment will export the sha1 of the head commit into HEAD, and the sha1 of the previous head commit in PREV_HEAD.
Showing
1 changed file
with
30 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,30 @@ |
1 | +namespace :ci do | |
2 | + | |
3 | + desc 'Continuous integration smoke test' | |
4 | + task :smoke do | |
5 | + if ENV['HEAD'] && ENV['PREV_HEAD'] | |
6 | + from = ENV['PREV_HEAD'] | |
7 | + to = ENV['HEAD'] | |
8 | + changed_files = `git diff --name-only #{from}..#{to}`.split | |
9 | + | |
10 | + # explicitly changed tests | |
11 | + tests = changed_files.select { |f| f =~ /test\/.*_test\.rb$/ } | |
12 | + features = changed_files.select { |f| f =~ /\.feature$/ } | |
13 | + | |
14 | + # match changed code files to their respective tests | |
15 | + changed_files.each do |f| | |
16 | + if f =~ /^(app|lib)\// | |
17 | + basename = File.basename(f, '.rb') | |
18 | + Dir.glob("test/**/#{basename}_test.rb").each do |t| | |
19 | + tests << t unless tests.include?(t) | |
20 | + end | |
21 | + end | |
22 | + end | |
23 | + | |
24 | + sh 'testrb', *tests unless tests.empty? | |
25 | + sh 'cucumber', *features unless features.empty? | |
26 | + sh 'cucumber', '-p', 'selenium', *features unless features.empty? | |
27 | + end | |
28 | + end | |
29 | + | |
30 | +end | ... | ... |