Class: Rspec::Shell::Expectations::CallConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/shell/expectations/call_configuration.rb

Overview

Configuration of a stubbed command

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_path, command) ⇒ CallConfiguration



10
11
12
13
14
# File 'lib/rspec/shell/expectations/call_configuration.rb', line 10

def initialize(config_path, command)
  @config_path = config_path
  @configuration = {}
  @command = command
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



8
9
10
# File 'lib/rspec/shell/expectations/call_configuration.rb', line 8

def command
  @command
end

Instance Method Details

#set_exitcode(statuscode, args = []) ⇒ Object



16
17
18
19
# File 'lib/rspec/shell/expectations/call_configuration.rb', line 16

def set_exitcode(statuscode, args = [])
  @configuration[args] ||= {}
  @configuration[args][:statuscode] = statuscode
end

#set_output(content, target, args = []) ⇒ Object



21
22
23
24
25
# File 'lib/rspec/shell/expectations/call_configuration.rb', line 21

def set_output(content, target, args = [])
  @configuration[args] ||= {}
  @configuration[args][:outputs] ||= []
  @configuration[args][:outputs] << { target: target, content: content }
end

#writeObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rspec/shell/expectations/call_configuration.rb', line 27

def write
  structure = []
  @configuration.each do |args, results|
    call = {
      args: args
    }.merge results
    structure << call
  end

  @config_path.open('w') do |f|
    f.puts structure.to_yaml
  end
end