selective-ruby-rspec 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.semaphore/semaphore.yml +19 -0
- data/lib/selective/ruby/rspec/formatter.rb +25 -0
- data/lib/selective/ruby/rspec/monkeypatches.rb +23 -5
- data/lib/selective/ruby/rspec/runner_wrapper.rb +60 -20
- data/lib/selective/ruby/rspec/version.rb +1 -1
- data/lib/selective-ruby-rspec.rb +1 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 742c9d113ea3409cd38857cad3943deaf6bf8c660f8061e97c57957b35ff2d07
|
4
|
+
data.tar.gz: 420c8ea9dac4e9b21a0346c7eba4ee8a0430ee83225f8f2dc1254bd175b0d413
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e8e31650ee078e7f0cabf43120c99b06f3a500b463b3c04fbe49dd9723db2a97ced3565c82729956f1f13a8c3fc0d0442d4eac96e8f228a7a02b2e3e483592e
|
7
|
+
data.tar.gz: 269a44800fb7a24bf58f32552d7313d54ddf6cb033eb252f1cebc220f2364b92fe67ee822d25cce1db731d1175266a85bf7d58931f770f1054409c32cfcff1d4
|
@@ -0,0 +1,19 @@
|
|
1
|
+
version: v1.0
|
2
|
+
name: Ruby
|
3
|
+
agent:
|
4
|
+
machine:
|
5
|
+
type: e1-standard-2
|
6
|
+
os_image: ubuntu2004
|
7
|
+
blocks:
|
8
|
+
- name: Run RSpec tests
|
9
|
+
task:
|
10
|
+
jobs:
|
11
|
+
- name: Run RSpec tests
|
12
|
+
parallelism: 2
|
13
|
+
commands:
|
14
|
+
- sem-version ruby 3.3.0
|
15
|
+
- checkout
|
16
|
+
- bundle install
|
17
|
+
- bundle exec selective rspec
|
18
|
+
secrets:
|
19
|
+
- name: Selective
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Selective
|
2
|
+
module Ruby
|
3
|
+
module RSpec
|
4
|
+
class Formatter
|
5
|
+
::RSpec::Core::Formatters.register self, :example_passed, :example_failed, :example_pending
|
6
|
+
|
7
|
+
def initialize(...); end
|
8
|
+
|
9
|
+
def self.callback=(callback)
|
10
|
+
@callback = callback
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.callback
|
14
|
+
@callback
|
15
|
+
end
|
16
|
+
|
17
|
+
%i(example_passed example_failed example_pending).each do |method|
|
18
|
+
define_method(method) do |notification|
|
19
|
+
self.class.callback.call(notification.example)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -139,10 +139,10 @@ module Selective
|
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
|
-
module Hooks
|
143
|
-
hooks = %i(before prepend_before after append_after)
|
144
142
|
|
145
|
-
|
143
|
+
HOOKS = %i(before prepend_before after append_after)
|
144
|
+
module Hooks
|
145
|
+
HOOKS.each do |hook|
|
146
146
|
define_method(hook) do |*args, &block|
|
147
147
|
args = args.map { |a| a == :all ? :each : a }
|
148
148
|
super(*args, &block)
|
@@ -150,7 +150,21 @@ module Selective
|
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
153
|
-
|
153
|
+
module RequireEachHooks
|
154
|
+
HOOKS.each do |hook|
|
155
|
+
define_method(hook) do |*args, &block|
|
156
|
+
if args.none? { |a| a == :all}
|
157
|
+
super(*args, &block)
|
158
|
+
else
|
159
|
+
super(*args) do
|
160
|
+
raise "Before :all hooks are not supported when using --require-each-hooks. Please use before(:each) instead."
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def self.apply(config)
|
154
168
|
::RSpec::Support.require_rspec_core("formatters/base_text_formatter")
|
155
169
|
|
156
170
|
MAP.each do |module_name, _methods|
|
@@ -163,7 +177,11 @@ module Selective
|
|
163
177
|
# a bug in < Ruby 3.0 that prevents us from doing so. Instead,
|
164
178
|
# we extend the ExampleGroup class which is where the Hooks module
|
165
179
|
# is included.
|
166
|
-
|
180
|
+
if config[:require_each_hooks]
|
181
|
+
::RSpec::Core::ExampleGroup.extend(RequireEachHooks)
|
182
|
+
else
|
183
|
+
::RSpec::Core::ExampleGroup.extend(Hooks)
|
184
|
+
end
|
167
185
|
|
168
186
|
::RSpec.singleton_class.prepend(RSpec)
|
169
187
|
::RSpec::Core::Reporter.prepend(Reporter)
|
@@ -7,26 +7,45 @@ module Selective
|
|
7
7
|
class RunnerWrapper
|
8
8
|
class TestManifestError < StandardError; end
|
9
9
|
|
10
|
-
attr_reader :
|
10
|
+
attr_reader :rspec_runner, :config, :example_callback
|
11
11
|
|
12
|
+
FRAMEWORK = "rspec"
|
12
13
|
DEFAULT_SPEC_PATH = "./spec"
|
13
14
|
|
14
|
-
def initialize(args)
|
15
|
-
|
15
|
+
def initialize(args, example_callback)
|
16
|
+
@example_callback = example_callback
|
17
|
+
rspec_args, wrapper_config_hash = parse_args(args)
|
18
|
+
Selective::Ruby::RSpec::Monkeypatches.apply(wrapper_config_hash)
|
16
19
|
apply_rspec_configuration
|
17
20
|
|
18
|
-
|
19
|
-
@args = args
|
20
|
-
|
21
|
-
@config = ::RSpec::Core::ConfigurationOptions.new(args)
|
21
|
+
@config = ::RSpec::Core::ConfigurationOptions.new(rspec_args)
|
22
22
|
if config.options[:files_or_directories_to_run].empty?
|
23
23
|
config.options[:files_or_directories_to_run] = [DEFAULT_SPEC_PATH]
|
24
24
|
end
|
25
25
|
|
26
|
+
Formatter.callback = method(:report_example)
|
27
|
+
|
26
28
|
@rspec_runner = ::RSpec::Core::Runner.new(@config)
|
27
29
|
@rspec_runner.setup($stderr, $stdout)
|
28
30
|
end
|
29
31
|
|
32
|
+
def parse_args(args)
|
33
|
+
supported_wrapper_args = %w[--require-each-hooks]
|
34
|
+
wrapper_args, rspec_args = args.partition do |arg|
|
35
|
+
supported_wrapper_args.any? do |p|
|
36
|
+
arg.start_with?(p)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
wrapper_config_hash = wrapper_args.each_with_object({}) do |arg, hash|
|
41
|
+
key = arg.sub('--', '').tr('-', '_').to_sym
|
42
|
+
hash[key] = true
|
43
|
+
end
|
44
|
+
|
45
|
+
rspec_args << "--format=progress" unless args.any? { |e| e.start_with?("--format") }
|
46
|
+
[rspec_args, wrapper_config_hash]
|
47
|
+
end
|
48
|
+
|
30
49
|
def manifest
|
31
50
|
output = nil
|
32
51
|
Tempfile.create("selective-rspec-dry-run") do |f|
|
@@ -43,12 +62,22 @@ module Selective
|
|
43
62
|
raise_test_manifest_error(e.message)
|
44
63
|
end
|
45
64
|
|
46
|
-
def run_test_cases(test_case_ids
|
65
|
+
def run_test_cases(test_case_ids)
|
47
66
|
::RSpec.world.reporter.send(:start, nil)
|
48
67
|
Selective::Ruby::Core::Controller.suppress_reporting!
|
49
|
-
|
50
|
-
|
68
|
+
|
69
|
+
::RSpec.configuration.reset_filters
|
70
|
+
::RSpec.world.prepare_example_filtering
|
71
|
+
config.options[:files_or_directories_to_run] = test_case_ids
|
72
|
+
ensure_formatter
|
73
|
+
|
74
|
+
rspec_runner.setup($stderr, $stdout)
|
75
|
+
|
76
|
+
example_groups = test_case_ids.each_with_object(Set.new) do |test_case_id, set|
|
77
|
+
set << ::RSpec.world.example_map[test_case_id]
|
51
78
|
end
|
79
|
+
|
80
|
+
rspec_runner.run_specs(example_groups.to_a)
|
52
81
|
end
|
53
82
|
|
54
83
|
def exec
|
@@ -78,20 +107,20 @@ module Selective
|
|
78
107
|
::RSpec.world.reporter.finish
|
79
108
|
end
|
80
109
|
|
81
|
-
|
110
|
+
def framework
|
111
|
+
RunnerWrapper::FRAMEWORK
|
112
|
+
end
|
82
113
|
|
83
|
-
def
|
84
|
-
::RSpec
|
85
|
-
|
86
|
-
config.options[:files_or_directories_to_run] = test_case_id
|
87
|
-
rspec_runner.options = config
|
88
|
-
rspec_runner.setup($stderr, $stdout)
|
114
|
+
def framework_version
|
115
|
+
::RSpec::Core::Version::STRING
|
116
|
+
end
|
89
117
|
|
90
|
-
|
91
|
-
|
92
|
-
callback.call(format_example(get_example_from_reporter(test_case_id)))
|
118
|
+
def wrapper_version
|
119
|
+
RSpec::VERSION
|
93
120
|
end
|
94
121
|
|
122
|
+
private
|
123
|
+
|
95
124
|
def get_example_from_reporter(test_case_id)
|
96
125
|
::RSpec.world.reporter.examples.detect { |e| e.id == test_case_id }
|
97
126
|
end
|
@@ -123,6 +152,10 @@ module Selective
|
|
123
152
|
}
|
124
153
|
end
|
125
154
|
|
155
|
+
def report_example(example)
|
156
|
+
example_callback.call(format_example(example))
|
157
|
+
end
|
158
|
+
|
126
159
|
def apply_rspec_configuration
|
127
160
|
::RSpec.configure do |config|
|
128
161
|
config.backtrace_exclusion_patterns = config.backtrace_exclusion_patterns | [/lib\/selective/]
|
@@ -133,6 +166,13 @@ module Selective
|
|
133
166
|
def raise_test_manifest_error(output)
|
134
167
|
raise TestManifestError.new("Selective could not generate a test manifest. The output was:\n#{output}")
|
135
168
|
end
|
169
|
+
|
170
|
+
def ensure_formatter
|
171
|
+
formatter = [Selective::Ruby::RSpec::Formatter.to_s]
|
172
|
+
return if config.options[:formatters].include?(formatter)
|
173
|
+
|
174
|
+
config.options[:formatters] << formatter
|
175
|
+
end
|
136
176
|
end
|
137
177
|
end
|
138
178
|
end
|
data/lib/selective-ruby-rspec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: selective-ruby-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Wood
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-01-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: zeitwerk
|
@@ -31,14 +31,14 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: 0.2.2
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
41
|
+
version: 0.2.2
|
42
42
|
description: Selective is an intelligent test runner for your current CI provider.
|
43
43
|
Get real-time test results, intelligent ordering based on code changes, shorter
|
44
44
|
run times, automatic flake detection, the ability to re-enqueue failed tests, and
|
@@ -50,9 +50,11 @@ executables: []
|
|
50
50
|
extensions: []
|
51
51
|
extra_rdoc_files: []
|
52
52
|
files:
|
53
|
+
- ".semaphore/semaphore.yml"
|
53
54
|
- LICENSE
|
54
55
|
- Rakefile
|
55
56
|
- lib/selective-ruby-rspec.rb
|
57
|
+
- lib/selective/ruby/rspec/formatter.rb
|
56
58
|
- lib/selective/ruby/rspec/monkeypatches.rb
|
57
59
|
- lib/selective/ruby/rspec/runner_wrapper.rb
|
58
60
|
- lib/selective/ruby/rspec/version.rb
|