forked from NUBIC/surveyor
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Rakefile
109 lines (86 loc) · 2.98 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
$LOAD_PATH << File.expand_path('../lib', __FILE__)
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'cucumber/rake/task'
require 'ci/reporter/rake/rspec'
###### RSPEC
RSpec::Core::RakeTask.new(:spec)
RSpec::Core::RakeTask.new(:rcov) do |spec|
spec.rcov = true
end
task :default => :spec
###### CUCUMBER
namespace :cucumber do
Cucumber::Rake::Task.new(:ok, 'Run features that should pass') do |t|
t.profile = 'default'
end
Cucumber::Rake::Task.new(:wip, 'Run features that are being worked on') do |t|
t.profile = 'wip'
end
desc 'Run all features'
task :all => [:ok, :wip]
end
desc 'Alias for cucumber:ok'
task :cucumber => 'cucumber:ok'
###### TESTBED
desc 'Set up the rails app that the specs and features use'
task :testbed => 'testbed:rebuild'
namespace :testbed do
desc 'Generate a minimal surveyor-using rails app'
task :generate do
Tempfile.open('surveyor_Rakefile') do |f|
f.write("application \"config.time_zone='Rome'\"\n")
# SMELL add support for protected_attributes
f.write("application \"config.active_record.whitelist_attributes = true\"\n")
f.write("application \"config.active_record.mass_assignment_sanitizer = :strict\"\n")
f.flush
sh "bundle exec rails new testbed --skip-bundle -m #{f.path}" # don't run bundle install until the Gemfile modifications
end
chdir('testbed') do
gem_file_contents = File.read('Gemfile')
gem_file_contents.sub!(/^(gem 'rails'.*)$/, %Q{# \\1\nplugin_root = File.expand_path('../..', __FILE__)\neval(File.read File.join(plugin_root, 'Gemfile.rails_version'))\ngem 'surveyor', :path => plugin_root})
File.open('Gemfile', 'w'){|f| f.write(gem_file_contents) }
Bundler.with_clean_env do
sh 'bundle install' # run bundle install after Gemfile modifications
end
end
end
desc 'Prepare the databases for the testbed'
task :migrate do
chdir('testbed') do
Bundler.with_clean_env do
sh 'bundle exec rails generate surveyor:install'
sh 'bundle exec rake db:migrate db:test:prepare'
end
end
end
desc 'Remove the testbed entirely'
task :remove do
rm_rf 'testbed'
end
task :rebuild => [:remove, :generate, :migrate]
desc 'Load all the sample surveys into the testbed instance'
task :surveys do
cd('testbed') do
Dir[File.join('surveys', '*.rb')].each do |fn|
puts "Installing #{fn} into the testbed"
system("rake surveyor FILE='#{fn}'")
end
end
end
end
###### CI
namespace :ci do
task :all => ['rake:testbed', :spec, :cucumber, 'cucumber:wip']
task :env do
ENV['CI_REPORTS'] = 'reports/spec-xml'
ENV['SPEC_OPTS'] = "#{ENV['SPEC_OPTS']} --format nested"
end
Cucumber::Rake::Task.new(:cucumber, 'Run features using the CI profile') do |t|
t.profile = 'ci'
end
Cucumber::Rake::Task.new('cucumber:wip', 'Run WIP features using the CI profile') do |t|
t.profile = 'ci_wip'
end
task :spec => [:env, 'ci:setup:rspecbase', 'rake:spec']
end