Class: Hussh::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/hussh/configuration.rb

Instance Method Summary collapse

Instance Method Details

#configure_rspecObject



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 ||
      if .has_key?(:parent_example_group)
        recording_name_for[[:parent_example_group]] +
          [:description]
      elsif .has_key?(:example_group)
        recording_name_for[[:example_group]] +
          [:description]
      else
        Pathname.new([:description])
      end
    end

    config.before(:each, hussh: lambda { |v| !!v }) do |example|
      options = example.[:hussh]
      if options.is_a?(Hash)
        options = options.dup
        recording_name = options.delete(:recording_name) ||
                         recording_name_for[example.]
      elsif options.is_a?(String)
        recording_name = options
        options = {}
      else
        recording_name = recording_name_for[example.]
        options = {}
      end

      Hussh.load_recording(recording_name)
      Hussh.clear_stubbed_responses
    end

    config.after(:each, hussh: lambda { |v| !!v }) do |example|
      options = example.[: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

#recordings_directory(directory) ⇒ Object



3
4
5
# File 'lib/hussh/configuration.rb', line 3

def recordings_directory(directory)
  Hussh.recordings_directory = directory
end