-
-
Notifications
You must be signed in to change notification settings - Fork 631
/
Copy pathrun_rspec.rake
84 lines (69 loc) · 2.75 KB
/
run_rspec.rake
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
require "coveralls/rake/task"
require "pathname"
require_relative "task_helpers"
require_relative "example_type"
include ReactOnRails::TaskHelpers
namespace :run_rspec do
desc "Run RSpec for top level only"
task :gem do
run_tests_in("", rspec_args: File.join("spec", "react_on_rails"))
end
desc "Runs dummy rspec with turbolinks"
task dummy: ["dummy_apps:dummy_app"] do
run_tests_in(File.join("spec", "dummy"), env_vars: "DRIVER=selenium_firefox")
end
desc "Runs dummy rspec without turbolinks"
task dummy_no_turbolinks: ["dummy_apps:dummy_app_no_turbolinks"] do
run_tests_in(File.join("spec", "dummy"),
env_vars: "DRIVER=selenium_firefox DISABLE_TURBOLINKS=TRUE",
command_name: "dummy_no_turbolinks")
dummy_app_dir = File.join(gem_root, "spec/dummy")
bundle_install_in(dummy_app_dir)
end
# Dynamically define Rake tasks for each example app found in the examples directory
ExampleType.all.each do |example_type|
desc "Runs RSpec for #{example_type.name_pretty} only"
task example_type.rspec_task_name_short => example_type.prepare_task_name do
run_tests_in(File.join(examples_dir, example_type.name)) # have to use relative path
end
end
desc "Runs Rspec for example apps only"
task examples: "examples:prepare_all" do
ExampleType.all.each { |example_type| Rake::Task[example_type.rspec_task_name].invoke }
end
desc "(HACK) Run RSpec on spec/empty_spec in order to have SimpleCov generate a coverage report from cache"
task :empty do
sh %(COVERAGE=true rspec spec/empty_spec.rb)
end
Coveralls::RakeTask.new
desc "run all tests"
task run_rspec: [:gem, :dummy, :dummy_no_turbolinks, :examples, :empty, :js_tests] do
puts "Completed all RSpec tests"
end
end
desc "js tests (same as 'npm run test')"
task :js_tests do
sh "npm run test"
end
desc "Runs all tests. Run `rake -D run_rspec` to see all available test options"
task run_rspec: ["run_rspec:run_rspec"]
private
# Runs rspec in the given directory.
# If string is passed and it's not absolute, it's converted relative to root of the gem.
# TEST_ENV_COMMAND_NAME is used to make SimpleCov.command_name unique in order to
# prevent a name collision. Defaults to the given directory's name.
def run_tests_in(dir, options = {})
if dir.is_a?(String)
path = if dir.start_with?(File::SEPARATOR)
Pathname.new(dir)
else
Pathname.new(File.join(gem_root, dir))
end
else
path = dir
end
command_name = options.fetch(:command_name, path.basename)
rspec_args = options.fetch(:rspec_args, "")
env_vars = %(#{options.fetch(:env_vars, '')} COVERAGE=true TEST_ENV_COMMAND_NAME="#{command_name}")
sh_in_dir(path.realpath, "#{env_vars} bundle exec rspec #{rspec_args}")
end