selective-ruby-rspec 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 357a3e88c5faad8cc7d188615b158094058f55b9342977bc999c14cfcdc82980
4
- data.tar.gz: 6afe356356bd83ae83cce8267a3d98446489621dee5960eda86772bd29861273
3
+ metadata.gz: 742c9d113ea3409cd38857cad3943deaf6bf8c660f8061e97c57957b35ff2d07
4
+ data.tar.gz: 420c8ea9dac4e9b21a0346c7eba4ee8a0430ee83225f8f2dc1254bd175b0d413
5
5
  SHA512:
6
- metadata.gz: 47046465fbc086af40e51f7bf74e8ffd65c4d2b5c92ba914eff1e6a567e8cc005abad6b4f8e5e08492f0e35d076afd2c1f1cb3faa50f05ced435c72e5a910518
7
- data.tar.gz: d7013aba148b15d7a9f7576cf8e99f7497cf1860610d32ad6d5a6d802903862152921fa3fe8b8104767320e7012606afb6d0f758ab887fd8ac59c26293c57f13
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
@@ -7,12 +7,13 @@ module Selective
7
7
  class RunnerWrapper
8
8
  class TestManifestError < StandardError; end
9
9
 
10
- attr_reader :rspec_runner, :config
10
+ attr_reader :rspec_runner, :config, :example_callback
11
11
 
12
12
  FRAMEWORK = "rspec"
13
13
  DEFAULT_SPEC_PATH = "./spec"
14
14
 
15
- def initialize(args)
15
+ def initialize(args, example_callback)
16
+ @example_callback = example_callback
16
17
  rspec_args, wrapper_config_hash = parse_args(args)
17
18
  Selective::Ruby::RSpec::Monkeypatches.apply(wrapper_config_hash)
18
19
  apply_rspec_configuration
@@ -22,6 +23,8 @@ module Selective
22
23
  config.options[:files_or_directories_to_run] = [DEFAULT_SPEC_PATH]
23
24
  end
24
25
 
26
+ Formatter.callback = method(:report_example)
27
+
25
28
  @rspec_runner = ::RSpec::Core::Runner.new(@config)
26
29
  @rspec_runner.setup($stderr, $stdout)
27
30
  end
@@ -59,12 +62,22 @@ module Selective
59
62
  raise_test_manifest_error(e.message)
60
63
  end
61
64
 
62
- def run_test_cases(test_case_ids, callback)
65
+ def run_test_cases(test_case_ids)
63
66
  ::RSpec.world.reporter.send(:start, nil)
64
67
  Selective::Ruby::Core::Controller.suppress_reporting!
65
- test_case_ids.flatten.each do |test_case_id|
66
- run_test_case(test_case_id, callback)
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]
67
78
  end
79
+
80
+ rspec_runner.run_specs(example_groups.to_a)
68
81
  end
69
82
 
70
83
  def exec
@@ -108,18 +121,6 @@ module Selective
108
121
 
109
122
  private
110
123
 
111
- def run_test_case(test_case_id, callback)
112
- ::RSpec.configuration.reset_filters
113
- ::RSpec.world.prepare_example_filtering
114
- config.options[:files_or_directories_to_run] = test_case_id
115
- rspec_runner.options = config
116
- rspec_runner.setup($stderr, $stdout)
117
-
118
- # $rspec_rerun_debug = true if test_case == './spec/selective_spec.rb[1:2]' && ::RSpec.world.reporter.examples.length == 5
119
- rspec_runner.run_specs([::RSpec.world.example_map[test_case_id]])
120
- callback.call(format_example(get_example_from_reporter(test_case_id)))
121
- end
122
-
123
124
  def get_example_from_reporter(test_case_id)
124
125
  ::RSpec.world.reporter.examples.detect { |e| e.id == test_case_id }
125
126
  end
@@ -151,6 +152,10 @@ module Selective
151
152
  }
152
153
  end
153
154
 
155
+ def report_example(example)
156
+ example_callback.call(format_example(example))
157
+ end
158
+
154
159
  def apply_rspec_configuration
155
160
  ::RSpec.configure do |config|
156
161
  config.backtrace_exclusion_patterns = config.backtrace_exclusion_patterns | [/lib\/selective/]
@@ -161,6 +166,13 @@ module Selective
161
166
  def raise_test_manifest_error(output)
162
167
  raise TestManifestError.new("Selective could not generate a test manifest. The output was:\n#{output}")
163
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
164
176
  end
165
177
  end
166
178
  end
@@ -3,7 +3,7 @@
3
3
  module Selective
4
4
  module Ruby
5
5
  module RSpec
6
- VERSION = "0.1.4"
6
+ VERSION = "0.1.5"
7
7
  end
8
8
  end
9
9
  end
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
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: 2024-01-04 00:00:00.000000000 Z
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: '0'
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: '0'
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