Class: KnapsackPro::Adapters::RSpecAdapter
Constant Summary
collapse
- TEST_DIR_PATTERN =
'spec/**{,/*/**}/*_spec.rb'
- REGEX =
/\A(.*?)(?:\[([\d\s:,]+)\])?\z/.freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BaseAdapter
adapter_bind_method_called_file, bind, #bind, #bind_queue_mode, verify_bind_method_called
Class Method Details
.calculate_slow_id_paths ⇒ Object
.concat_paths(test_files, id_paths) ⇒ Object
89
90
91
92
93
|
# File 'lib/knapsack_pro/adapters/rspec_adapter.rb', line 89
def self.concat_paths(test_files, id_paths)
paths = KnapsackPro::TestFilePresenter.paths(test_files)
file_paths = id_paths.map { |id_path| parse_file_path(id_path) }
paths + id_paths - file_paths
end
|
.concat_test_files(test_files, id_paths) ⇒ Object
84
85
86
87
|
# File 'lib/knapsack_pro/adapters/rspec_adapter.rb', line 84
def self.concat_test_files(test_files, id_paths)
paths = concat_paths(test_files, id_paths)
KnapsackPro::TestFilePresenter.test_files(paths)
end
|
.file_path_for(example) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/knapsack_pro/adapters/rspec_adapter.rb', line 59
def self.file_path_for(example)
[
-> { parse_file_path(example.id) },
-> { example.metadata[:file_path] },
-> { example.metadata[:example_group][:file_path] },
-> { top_level_group(example)[:file_path] },
]
.each do |path|
p = path.call
return p if p.include?('_spec.rb') || p.include?('.feature')
end
return ''
end
|
36
37
38
|
# File 'lib/knapsack_pro/adapters/rspec_adapter.rb', line 36
def self.has_format_option?(cli_args)
!!parsed_options(cli_args)&.[](:formatters)
end
|
.has_require_rails_helper_option?(cli_args) ⇒ Boolean
40
41
42
|
# File 'lib/knapsack_pro/adapters/rspec_adapter.rb', line 40
def self.has_require_rails_helper_option?(cli_args)
(parsed_options(cli_args)&.[](:requires) || []).include?("rails_helper")
end
|
.id_path?(path) ⇒ Boolean
79
80
81
82
|
# File 'lib/knapsack_pro/adapters/rspec_adapter.rb', line 79
def self.id_path?(path)
_file, id = path.match(REGEX).captures
!id.nil?
end
|
.order_option(cli_args) ⇒ Object
44
45
46
|
# File 'lib/knapsack_pro/adapters/rspec_adapter.rb', line 44
def self.order_option(cli_args)
parsed_options(cli_args)&.[](:order)
end
|
.parse_file_path(path) ⇒ Object
74
75
76
77
|
# File 'lib/knapsack_pro/adapters/rspec_adapter.rb', line 74
def self.parse_file_path(path)
file, _id = path.match(REGEX).captures
file
end
|
.parsed_options(cli_args) ⇒ Object
187
188
189
190
191
|
# File 'lib/knapsack_pro/adapters/rspec_adapter.rb', line 187
def self.parsed_options(cli_args)
::RSpec::Core::Parser.parse(cli_args)
rescue SystemExit
nil
end
|
.rails_helper_exists?(test_dir) ⇒ Boolean
95
96
97
|
# File 'lib/knapsack_pro/adapters/rspec_adapter.rb', line 95
def self.rails_helper_exists?(test_dir)
File.exist?("#{test_dir}/rails_helper.rb")
end
|
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/knapsack_pro/adapters/rspec_adapter.rb', line 48
def self.remove_formatters(cli_args)
formatter_options = ['-f', '--format', '-o', '--out']
cli_args.dup.each_with_index do |arg, index|
if formatter_options.include?(arg)
cli_args[index] = nil
cli_args[index + 1] = nil
end
end
cli_args.compact
end
|
.rspec_configuration ⇒ Object
Hide RSpec configuration so that we could mock it in the spec. Mocking existing RSpec configuration could impact test’s runtime.
179
180
181
|
# File 'lib/knapsack_pro/adapters/rspec_adapter.rb', line 179
def self.rspec_configuration
::RSpec.configuration
end
|
.scheduled_paths ⇒ Object
183
184
185
|
# File 'lib/knapsack_pro/adapters/rspec_adapter.rb', line 183
def self.scheduled_paths
rspec_configuration.instance_variable_get(:@files_or_directories_to_run) || []
end
|
.split_by_test_cases_enabled? ⇒ Boolean
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/knapsack_pro/adapters/rspec_adapter.rb', line 12
def self.split_by_test_cases_enabled?
return false unless KnapsackPro::Config::Env.rspec_split_by_test_examples?
require 'rspec/core/version'
unless Gem::Version.new(::RSpec::Core::Version::STRING) >= Gem::Version.new('3.3.0')
raise "RSpec >= 3.3.0 is required to split test files by test examples. Learn more: #{KnapsackPro::Urls::SPLIT_BY_TEST_EXAMPLES}"
end
true
end
|
.top_level_group(example) ⇒ Object
100
101
102
103
104
105
106
|
# File 'lib/knapsack_pro/adapters/rspec_adapter.rb', line 100
def self.top_level_group(example)
group = example.metadata[:example_group]
until group[:parent_example_group].nil?
group = group[:parent_example_group]
end
group
end
|
Instance Method Details
#bind_after_queue_hook ⇒ Object
167
168
169
170
171
172
173
|
# File 'lib/knapsack_pro/adapters/rspec_adapter.rb', line 167
def bind_after_queue_hook
::RSpec.configure do |config|
config.after(:suite) do
KnapsackPro::Hooks::Queue.call_after_queue
end
end
end
|
#bind_before_queue_hook ⇒ Object
159
160
161
162
163
164
165
|
# File 'lib/knapsack_pro/adapters/rspec_adapter.rb', line 159
def bind_before_queue_hook
::RSpec.configure do |config|
config.before(:suite) do
KnapsackPro::Hooks::Queue.call_before_queue
end
end
end
|
#bind_regular_mode_time_tracker ⇒ Object
#bind_save_report ⇒ Object
#bind_time_tracker ⇒ Object
108
109
110
111
112
|
# File 'lib/knapsack_pro/adapters/rspec_adapter.rb', line 108
def bind_time_tracker
ensure_no_focus!
bind_regular_mode_time_tracker
log_tests_duration
end
|
#ensure_no_focus! ⇒ Object
#log_tests_duration ⇒ Object