7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/hussh/configuration.rb', line 7
def configure_rspec
::RSpec.configure do |config|
recording_name_for = lambda do |metadata|
if metadata.has_key?(:parent_example_group)
recording_name_for[metadata[:parent_example_group]] +
metadata[:description]
elsif metadata.has_key?(:example_group)
recording_name_for[metadata[:example_group]] +
metadata[:description]
else
Pathname.new(metadata[:description])
end
end
config.before(:each, hussh: lambda { |v| !!v }) do |example|
options = example.metadata[:hussh]
if options.is_a?(Hash)
options = options.dup
recording_name = options.delete(:recording_name) ||
recording_name_for[example.metadata]
elsif options.is_a?(String)
recording_name = options
options = {}
else
recording_name = recording_name_for[example.metadata]
options = {}
end
Hussh.load_recording(recording_name)
Hussh.clear_stubbed_responses
end
config.after(:each, hussh: lambda { |v| !!v }) do |example|
options = example.metadata[:hussh]
options = options.is_a?(Hash) ? options.dup : {}
Hussh.save_recording_if_changed
Hussh.clear_recorded_responses
Hussh.clear_stubbed_responses
Hussh.commands_run.clear
end
end
end
|