forked from browsermedia/browsercms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
171 lines (142 loc) · 6.11 KB
/
Copy pathRakefile
File metadata and controls
171 lines (142 loc) · 6.11 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env rake
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
begin
require 'rdoc/task'
rescue LoadError
require 'rdoc/rdoc'
require 'rake/rdoctask'
RDoc::Task = Rake::RDocTask
end
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
load 'rails/tasks/engine.rake'
Bundler::GemHelper.install_tasks
require 'rake/testtask'
require 'single_test/tasks'
# Each suite runs in its own process and merges into coverage/.resultset.json
# under a name SimpleCov otherwise *guesses*. Two suites that guess alike
# overwrite each other, so name them explicitly. Returns a task name suitable
# for use as a prerequisite; the test subprocess inherits the environment.
def coverage_suite(name)
suite_task = "coverage:suite:#{name.downcase.tr(' ', '_')}"
task(suite_task) { ENV['COVERAGE_SUITE'] = name }
suite_task
end
Rake::TestTask.new('units' => coverage_suite('Unit Tests')) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/unit/**/*_test.rb'
t.verbose = false
t.warning = false
end
Rake::TestTask.new('spec' => coverage_suite('RSpec')) do |t|
t.libs << 'lib'
t.libs << 'spec'
t.pattern = 'spec/**/*_spec.rb'
t.warning = false
end
Rake::TestTask.new('test:functionals' => ['project:ensure_db_exists', 'app:test:prepare', coverage_suite('Functional Tests')]) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/functional/**/*_test.rb'
t.verbose = false
t.warning = false
end
# test/*_test.rb, test/helpers/** and the dummy app's own tests under
# test/dummy/test/** are matched by none of the patterns above, so until this
# task existed they were in the repo but never run. `rake app:test` looks like
# the answer and is not -- it exits 0 having run nothing, because Rails 4.2
# hands it the literal top-level task name ("app:test") and matches no sub-task.
Rake::TestTask.new('test:orphans' => ['project:ensure_db_exists', 'app:test:prepare', coverage_suite('Orphan Tests')]) do |t|
t.libs << 'lib'
t.libs << 'test' # so the dummy app's `require "test_helper"` finds the engine's
t.test_files = FileList[
'test/*_test.rb',
'test/helpers/**/*_test.rb',
'test/dummy/test/**/*_test.rb'
]
t.verbose = false
t.warning = false
end
require 'cucumber'
require 'cucumber/rake/task'
Cucumber::Rake::Task.new({:features => coverage_suite('Cucumber Features')}, "Run all (fast) scenarios without known bugs or missing features") do |t|
t.cucumber_opts = "launch_on_failure=false features --format progress --tags ~@cli -t ~@missing-feature -t ~@known-bug"
end
Cucumber::Rake::Task.new({'features:all' => coverage_suite('Cucumber Features (all)')}, 'Runs all scenarios (including slow/missing/etc') do |t|
t.cucumber_opts = "launch_on_failure=false features --format progress"
end
# @cli scenarios shell out through aruba, so their coverage is collected in a
# child process SimpleCov cannot see. Named anyway, so the entry is distinct
# rather than overwriting the in-process cucumber result with an empty one.
Cucumber::Rake::Task.new('features:cli' => ['project:ensure_db_exists', 'app:test:prepare', coverage_suite('Cucumber CLI Features')]) do |t|
t.cucumber_opts = "features --format progress --tags @cli"
end
Cucumber::Rake::Task.new('features:wip', 'Run all (fast) scenarios without known bugs/features.') do |t|
t.cucumber_opts = "features --format progress --tags ~@cli -t ~@known-bug -t ~@missing-feature"
end
Cucumber::Rake::Task.new('features:wip:all', 'Run all scenarios (including slow) without known bugs/missing features.') do |t|
t.cucumber_opts = "features --format progress -t ~@known-bug -t ~@missing-feature"
end
Cucumber::Rake::Task.new('features:known-bugs', 'Run all scenarios with known bugs.') do |t|
# The tags and format live in the `known_bugs` profile in config/cucumber.yml,
# not here. Naming a profile is what stops cucumber auto-applying `default`,
# and `default` carries --strict -- see the note on that profile.
t.profile = 'known_bugs'
end
#Rake::Task['features:wip'].enhance ['project:ensure_db_exists', 'app:test:prepare']
desc "Run everything but the command line (slow) tests"
task 'test:fast' => %w{app:test:prepare test:units test:functionals features}
desc "Runs all unit level tests"
task 'test:units' => ['app:test:prepare'] do
run_tests ["units", "spec"]
end
desc 'Runs all the tests, specs and scenarios.'
task :test => ['project:ensure_db_exists', 'app:test:prepare'] do
tests_to_run = %w(test:units spec test:functionals test:orphans features)
run_tests(tests_to_run)
end
def run_tests(tests_to_run)
errors = tests_to_run.collect do |task|
begin
Rake::Task[task].invoke
nil
rescue => e
{:task => task, :exception => e}
end
end.compact
if errors.any?
errors.each { |e| $stderr.puts "FAILED: #{e[:task]} -- #{e[:exception].message}" }
raise "Test failures in: #{errors.collect { |e| e[:task] }.join(', ')}"
end
end
# Build and run against Postgres.
task 'ci:test' => ['db:drop', 'db:create:all', 'db:install', 'test']
# Checked once, after the chain, rather than through SimpleCov's own
# minimum_coverage -- that is enforced in every test process's at_exit, so the
# first suite would fail the build for not meeting the whole chain's threshold
# on its own. `test` raises on failure, so a red suite short-circuits this,
# which is the right order: coverage from a failing run means nothing.
Rake::Task['ci:test'].enhance { Rake::Task['coverage:check'].invoke }
task :default => 'ci:test'
require 'yard'
YARD::Rake::YardocTask.new do |t|
t.options = ['--output-dir', 'doc/api/']
end
# Load all tasks files
#Dir.glob('lib/tasks/*.rake').each { |r| import r }
# Load just this one task file instead (the previous rake files can probably be simplified)
import 'lib/tasks/core_tasks.rake'
begin
require 'cucumber/rake/task'
namespace :cucumber do
Cucumber::Rake::Task.new({:launch => 'db:test:prepare'}, 'Run features opening failures in the browser') do |t|
t.fork = true # You may get faster startup if you set this to false
t.profile = 'default'
t.cucumber_opts = ["-f", "Debug::Formatter"]
end
end
end