Class: Rspec::Bash::StubbedEnv

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/bash/stubbed_env.rb

Constant Summary collapse

RUBY_STUB =
:ruby_stub
BASH_STUB =
:bash_stub

Instance Method Summary collapse

Constructor Details

#initialize(stub_type) ⇒ StubbedEnv

Returns a new instance of StubbedEnv.



18
19
20
# File 'lib/rspec/bash/stubbed_env.rb', line 18

def initialize(stub_type)
  start_stub_server(stub_type)
end

Instance Method Details

#execute(command, env_vars = {}) ⇒ Object



34
35
36
37
38
# File 'lib/rspec/bash/stubbed_env.rb', line 34

def execute(command, env_vars = {})
  script_runner = "command source #{command}"
  script_wrapper = wrap_script(script_runner)
  execute_script(env_vars, script_wrapper)
end

#execute_function(script, command, env_vars = {}) ⇒ Object



40
41
42
43
44
# File 'lib/rspec/bash/stubbed_env.rb', line 40

def execute_function(script, command, env_vars = {})
  script_runner = "command source #{script}\n#{command}"
  script_wrapper = wrap_script(script_runner)
  execute_script(env_vars, script_wrapper)
end

#execute_inline(command_string, env_vars = {}) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/rspec/bash/stubbed_env.rb', line 46

def execute_inline(command_string, env_vars = {})
  temp_command_file = Tempfile.new('inline-')
  temp_command_path = temp_command_file.path
  write_file(temp_command_path, command_string)
  stdout, stderr, status = execute(temp_command_path, env_vars)
  delete_file(temp_command_path)
  [stdout, stderr, status]
end

#start_stub_server(stub_type) ⇒ Object



22
23
24
25
26
# File 'lib/rspec/bash/stubbed_env.rb', line 22

def start_stub_server(stub_type)
  tcp_server = create_tcp_server
  stub_server = create_stub_server(stub_type)
  stub_server.start(tcp_server)
end

#stub_command(command) ⇒ Object



28
29
30
31
32
# File 'lib/rspec/bash/stubbed_env.rb', line 28

def stub_command(command)
  check_if_command_is_allowed(command)
  add_override_for_command(command)
  create_stubbed_command(command)
end