selective-ruby-rspec 0.1.2 → 0.1.4

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: a52be67f13b3bf3813e3cc0957691927ed27e5e80648d1956c09ad41484c4f52
4
- data.tar.gz: d32e9422fd5d88e8a0b7ce4431e42efbd59fad050689e163b88f91e6a08fc9e2
3
+ metadata.gz: 357a3e88c5faad8cc7d188615b158094058f55b9342977bc999c14cfcdc82980
4
+ data.tar.gz: 6afe356356bd83ae83cce8267a3d98446489621dee5960eda86772bd29861273
5
5
  SHA512:
6
- metadata.gz: 4ad06bc5a9b33456299db63400c2c4ced95cbe9697af8bd637289419be5c4d59edd6f7264a8b29f96005694b4163bb01c669c9dc1f33eb69b798321a0174b564
7
- data.tar.gz: fa656253c173a3d7363f7ad3d97d5f4af8297404b8ee4dd820a4736a8c0035a751063452fb9ffbd6d781f61b75532c386398aaf0edf35ea7c452c92274690031
6
+ metadata.gz: 47046465fbc086af40e51f7bf74e8ffd65c4d2b5c92ba914eff1e6a567e8cc005abad6b4f8e5e08492f0e35d076afd2c1f1cb3faa50f05ced435c72e5a910518
7
+ data.tar.gz: d7013aba148b15d7a9f7576cf8e99f7497cf1860610d32ad6d5a6d802903862152921fa3fe8b8104767320e7012606afb6d0f758ab887fd8ac59c26293c57f13
@@ -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
- hooks.each do |hook|
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
- def self.apply
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
- ::RSpec::Core::ExampleGroup.extend(Hooks)
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,20 +7,17 @@ module Selective
7
7
  class RunnerWrapper
8
8
  class TestManifestError < StandardError; end
9
9
 
10
- attr_reader :args, :rspec_runner, :config
10
+ attr_reader :rspec_runner, :config
11
11
 
12
+ FRAMEWORK = "rspec"
12
13
  DEFAULT_SPEC_PATH = "./spec"
13
14
 
14
15
  def initialize(args)
15
- require "rspec/core"
16
-
17
- Selective::Ruby::RSpec::Monkeypatches.apply
16
+ rspec_args, wrapper_config_hash = parse_args(args)
17
+ Selective::Ruby::RSpec::Monkeypatches.apply(wrapper_config_hash)
18
18
  apply_rspec_configuration
19
19
 
20
- args << "--format=progress" unless args.any? { |e| e.start_with?("--format") }
21
- @args = args
22
-
23
- @config = ::RSpec::Core::ConfigurationOptions.new(args)
20
+ @config = ::RSpec::Core::ConfigurationOptions.new(rspec_args)
24
21
  if config.options[:files_or_directories_to_run].empty?
25
22
  config.options[:files_or_directories_to_run] = [DEFAULT_SPEC_PATH]
26
23
  end
@@ -29,6 +26,23 @@ module Selective
29
26
  @rspec_runner.setup($stderr, $stdout)
30
27
  end
31
28
 
29
+ def parse_args(args)
30
+ supported_wrapper_args = %w[--require-each-hooks]
31
+ wrapper_args, rspec_args = args.partition do |arg|
32
+ supported_wrapper_args.any? do |p|
33
+ arg.start_with?(p)
34
+ end
35
+ end
36
+
37
+ wrapper_config_hash = wrapper_args.each_with_object({}) do |arg, hash|
38
+ key = arg.sub('--', '').tr('-', '_').to_sym
39
+ hash[key] = true
40
+ end
41
+
42
+ rspec_args << "--format=progress" unless args.any? { |e| e.start_with?("--format") }
43
+ [rspec_args, wrapper_config_hash]
44
+ end
45
+
32
46
  def manifest
33
47
  output = nil
34
48
  Tempfile.create("selective-rspec-dry-run") do |f|
@@ -80,6 +94,18 @@ module Selective
80
94
  ::RSpec.world.reporter.finish
81
95
  end
82
96
 
97
+ def framework
98
+ RunnerWrapper::FRAMEWORK
99
+ end
100
+
101
+ def framework_version
102
+ ::RSpec::Core::Version::STRING
103
+ end
104
+
105
+ def wrapper_version
106
+ RSpec::VERSION
107
+ end
108
+
83
109
  private
84
110
 
85
111
  def run_test_case(test_case_id, callback)
@@ -3,7 +3,7 @@
3
3
  module Selective
4
4
  module Ruby
5
5
  module RSpec
6
- VERSION = "0.1.2"
6
+ VERSION = "0.1.4"
7
7
  end
8
8
  end
9
9
  end
@@ -1,10 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "zeitwerk"
4
+ require "rspec/core"
5
+ require "#{__dir__}/selective/ruby/rspec/version"
4
6
 
5
7
  loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false)
6
8
  loader.inflector.inflect("rspec" => "RSpec")
7
9
  loader.ignore("#{__dir__}/selective-ruby-rspec.rb")
10
+ loader.ignore("#{__dir__}/selective/ruby/rspec/version.rb")
8
11
  loader.setup
9
12
 
10
13
  require "selective-ruby-core"
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.2
4
+ version: 0.1.4
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: 2023-12-06 00:00:00.000000000 Z
12
+ date: 2024-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: zeitwerk