Class: Selective::Ruby::RSpec::RunnerWrapper
- Inherits:
-
Object
- Object
- Selective::Ruby::RSpec::RunnerWrapper
show all
- Defined in:
- lib/selective/ruby/rspec/runner_wrapper.rb
Defined Under Namespace
Classes: TestManifestError
Constant Summary
collapse
- FRAMEWORK =
"rspec"
- DEFAULT_SPEC_PATH =
"./spec"
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(args, example_callback) ⇒ RunnerWrapper
Returns a new instance of RunnerWrapper.
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/selective/ruby/rspec/runner_wrapper.rb', line 16
def initialize(args, example_callback)
@example_callback = example_callback
rspec_args, wrapper_config_hash = parse_args(args)
Selective::Ruby::RSpec::Monkeypatches.apply(wrapper_config_hash)
apply_rspec_configuration
@config = ::RSpec::Core::ConfigurationOptions.new(rspec_args)
if config.options[:files_or_directories_to_run].empty?
config.options[:files_or_directories_to_run] = [DEFAULT_SPEC_PATH]
end
Formatter.runner_wrapper = self
@rspec_runner = ::RSpec::Core::Runner.new(@config)
@rspec_runner.setup($stderr, $stdout)
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
10
11
12
|
# File 'lib/selective/ruby/rspec/runner_wrapper.rb', line 10
def config
@config
end
|
#connection_lost ⇒ Object
Returns the value of attribute connection_lost.
11
12
13
|
# File 'lib/selective/ruby/rspec/runner_wrapper.rb', line 11
def connection_lost
@connection_lost
end
|
#example_callback ⇒ Object
Returns the value of attribute example_callback.
10
11
12
|
# File 'lib/selective/ruby/rspec/runner_wrapper.rb', line 10
def example_callback
@example_callback
end
|
#rspec_runner ⇒ Object
Returns the value of attribute rspec_runner.
10
11
12
|
# File 'lib/selective/ruby/rspec/runner_wrapper.rb', line 10
def rspec_runner
@rspec_runner
end
|
Instance Method Details
#base_test_path ⇒ Object
72
73
74
75
|
# File 'lib/selective/ruby/rspec/runner_wrapper.rb', line 72
def base_test_path
file = config.options[:files_or_directories_to_run].first
Pathname(normalize_path(file)).each_filename.first
end
|
#exec ⇒ Object
59
60
61
|
# File 'lib/selective/ruby/rspec/runner_wrapper.rb', line 59
def exec
rspec_runner.run($stderr, $stdout)
end
|
#exit_status ⇒ Object
77
78
79
80
81
82
83
84
85
|
# File 'lib/selective/ruby/rspec/runner_wrapper.rb', line 77
def exit_status
if Gem::Version.new(::RSpec::Core::Version::STRING) >= Gem::Version.new("3.10")
rspec_runner.exit_code(::RSpec.world.reporter.failed_examples.none?)
else
return ::RSpec.world.reporter.exit_early(rspec_runner.configuration.failure_exit_code) if ::RSpec.world.wants_to_quit
::RSpec.world.reporter.failed_examples.any? ? 1 : 0
end
end
|
#finish ⇒ Object
87
88
89
90
|
# File 'lib/selective/ruby/rspec/runner_wrapper.rb', line 87
def finish
rspec_runner.configuration.after_suite_hooks
::RSpec.world.reporter.finish
end
|
#framework ⇒ Object
92
93
94
|
# File 'lib/selective/ruby/rspec/runner_wrapper.rb', line 92
def framework
RunnerWrapper::FRAMEWORK
end
|
#framework_version ⇒ Object
96
97
98
|
# File 'lib/selective/ruby/rspec/runner_wrapper.rb', line 96
def framework_version
::RSpec::Core::Version::STRING
end
|
#manifest ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/selective/ruby/rspec/runner_wrapper.rb', line 33
def manifest
output = nil
Tempfile.create("selective-rspec-dry-run") do |f|
quoted_paths = config.options[:files_or_directories_to_run].map { |path| "'#{path}'" }.join(" ")
output = `bundle exec selective exec rspec #{quoted_paths} --format=json --out=#{f.path} --dry-run`
JSON.parse(f.read).tap do |content|
if content["examples"].empty?
message = content["messages"]&.first
raise_test_manifest_error(message || "No examples found")
end
end
end
rescue JSON::ParserError => e
raise_test_manifest_error(e.message)
end
|
#remove_test_case_result(test_case_id) ⇒ Object
63
64
65
66
67
68
69
70
|
# File 'lib/selective/ruby/rspec/runner_wrapper.rb', line 63
def remove_test_case_result(test_case_id)
failure = ::RSpec.world.reporter.failed_examples.detect { |e| e.id == test_case_id }
if (failed_example_index = ::RSpec.world.reporter.failed_examples.index(failure))
::RSpec.world.reporter.failed_examples.delete_at(failed_example_index)
end
example = get_example_from_reporter(test_case_id)
::RSpec.world.reporter.examples.delete_at(::RSpec.world.reporter.examples.index(example))
end
|
#report_example(example) ⇒ Object
104
105
106
|
# File 'lib/selective/ruby/rspec/runner_wrapper.rb', line 104
def report_example(example)
example_callback.call(format_example(example))
end
|
#run_test_cases(test_case_ids) ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'lib/selective/ruby/rspec/runner_wrapper.rb', line 49
def run_test_cases(test_case_ids)
ensure_test_phase
configure(test_case_ids)
rspec_runner.run_specs(optimize_test_filtering(test_case_ids).to_a)
if connection_lost
self.connection_lost = false
raise Selective::Ruby::Core::ConnectionLostError
end
end
|
#wrapper_version ⇒ Object
100
101
102
|
# File 'lib/selective/ruby/rspec/runner_wrapper.rb', line 100
def wrapper_version
RSpec::VERSION
end
|