Skip to content

Commit 6e986d5

Browse files
committed
[sentry-rails] add support for isolated specs
1 parent eeaeb2a commit 6e986d5

File tree

3 files changed

+76
-37
lines changed

3 files changed

+76
-37
lines changed

lib/sentry/test/rake_tasks.rb

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# frozen_string_literal: true
2+
3+
require "rake/clean"
4+
require "rspec/core/rake_task"
5+
6+
module Sentry
7+
module Test
8+
module RakeTasks
9+
extend Rake::DSL
10+
11+
def self.define_spec_tasks(options = {})
12+
opts = {
13+
isolated_specs_pattern: "spec/isolated/**/*_spec.rb",
14+
spec_pattern: nil,
15+
spec_exclude_pattern: nil,
16+
spec_rspec_opts: nil,
17+
isolated_rspec_opts: nil
18+
}.merge(options)
19+
20+
RSpec::Core::RakeTask.new(:spec).tap do |task|
21+
task.pattern = opts[:spec_pattern] if opts[:spec_pattern]
22+
task.exclude_pattern = opts[:spec_exclude_pattern] if opts[:spec_exclude_pattern]
23+
task.rspec_opts = opts[:spec_rspec_opts] if opts[:spec_rspec_opts]
24+
end
25+
26+
namespace :spec do
27+
RSpec::Core::RakeTask.new(:isolated).tap do |task|
28+
task.pattern = opts[:isolated_specs_pattern]
29+
task.rspec_opts = opts[:isolated_rspec_opts] if opts[:isolated_rspec_opts]
30+
end
31+
end
32+
end
33+
34+
# Define versioned specs task (sentry-rails specific)
35+
def self.define_versioned_specs_task(options = {})
36+
opts = {
37+
rspec_opts: "--order rand"
38+
}.merge(options)
39+
40+
namespace :spec do
41+
RSpec::Core::RakeTask.new(:versioned).tap do |task|
42+
ruby_ver_dir = RUBY_VERSION.split(".")[0..1].join(".")
43+
matching_dir = Dir["spec/versioned/*"].detect { |dir| File.basename(dir) <= ruby_ver_dir }
44+
45+
unless matching_dir
46+
puts "No versioned specs found for ruby #{RUBY_VERSION}"
47+
exit 0
48+
end
49+
50+
puts "Running versioned specs from #{matching_dir} for ruby #{RUBY_VERSION}"
51+
52+
task.rspec_opts = opts[:rspec_opts]
53+
task.pattern = "#{matching_dir}/**/*_spec.rb"
54+
end
55+
end
56+
end
57+
end
58+
end
59+
end

sentry-rails/Rakefile

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,17 @@
11
# frozen_string_literal: true
22

33
require "bundler/gem_tasks"
4-
require "rspec/core/rake_task"
4+
require_relative "../lib/sentry/test/rake_tasks"
55

6-
RSpec::Core::RakeTask.new(:spec).tap do |task|
7-
task.rspec_opts = "--order rand"
8-
task.pattern = "spec/sentry/**/*_spec.rb"
9-
end
6+
Sentry::Test::RakeTasks.define_spec_tasks(
7+
spec_pattern: "spec/sentry/**/*_spec.rb",
8+
spec_rspec_opts: "--order rand --format progress",
9+
isolated_specs_pattern: "spec/isolated/**/*_spec.rb",
10+
isolated_rspec_opts: "--format progress"
11+
)
1012

11-
namespace :spec do
12-
RSpec::Core::RakeTask.new(:versioned).tap do |task|
13-
ruby_ver_dir = RUBY_VERSION.split(".")[0..1].join(".")
14-
matching_dir = Dir["spec/versioned/*"].detect { |dir| File.basename(dir) <= ruby_ver_dir }
13+
Sentry::Test::RakeTasks.define_versioned_specs_task(
14+
rspec_opts: "--order rand --format progress"
15+
)
1516

16-
unless matching_dir
17-
puts "No versioned specs found for ruby #{RUBY_VERSION}"
18-
exit 0
19-
end
20-
21-
puts "Running versioned specs from #{matching_dir} for ruby #{RUBY_VERSION}"
22-
23-
task.rspec_opts = "--order rand"
24-
task.pattern = "#{matching_dir}/**/*_spec.rb"
25-
end
26-
end
27-
28-
task :isolated_specs do
29-
Dir["spec/isolated/*"].each do |file|
30-
sh "bundle exec ruby #{file}"
31-
end
32-
end
33-
34-
task default: [:spec, :"spec:versioned", :isolated_specs]
17+
task default: [:spec, :"spec:versioned", :"spec:isolated"]

sentry-ruby/Rakefile

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@ CLOBBER.include "pkg"
66
require "bundler/gem_helper"
77
Bundler::GemHelper.install_tasks(name: "sentry-ruby")
88

9-
require "rspec/core/rake_task"
9+
require_relative "../lib/sentry/test/rake_tasks"
1010

1111
ISOLATED_SPECS = "spec/isolated/**/*_spec.rb"
1212

13-
RSpec::Core::RakeTask.new(:spec).tap do |task|
14-
task.exclude_pattern = ISOLATED_SPECS
15-
end
13+
Sentry::Test::RakeTasks.define_spec_tasks(
14+
isolated_specs_pattern: ISOLATED_SPECS,
15+
spec_exclude_pattern: ISOLATED_SPECS
16+
)
1617

17-
RSpec::Core::RakeTask.new(:isolated_specs).tap do |task|
18-
task.pattern = ISOLATED_SPECS
19-
end
20-
21-
task default: [:spec, :isolated_specs]
18+
task default: [:spec, :"spec:isolated"]

0 commit comments

Comments
 (0)