Class: Rspec::Bash::BashWrapper

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

Instance Method Summary collapse

Constructor Details

#initialize(port) ⇒ BashWrapper

Returns a new instance of BashWrapper.



4
5
6
7
8
# File 'lib/rspec/bash/wrapper/bash_wrapper.rb', line 4

def initialize(port)
  @port = port
  @override_list = []
  at_exit { cleanup }
end

Instance Method Details

#add_override(override) ⇒ Object



41
42
43
# File 'lib/rspec/bash/wrapper/bash_wrapper.rb', line 41

def add_override(override)
  @override_list << override
end

#cleanupObject



32
33
34
35
# File 'lib/rspec/bash/wrapper/bash_wrapper.rb', line 32

def cleanup
  remove_file_system_path wrapper_output_path
  remove_file_system_path stderr_output_path
end

#remove_file_system_path(path) ⇒ Object



37
38
39
# File 'lib/rspec/bash/wrapper/bash_wrapper.rb', line 37

def remove_file_system_path(path)
  FileUtils.remove_entry_secure(path) if Pathname.new(path).exist?
end

#stderr_output_pathObject



28
29
30
# File 'lib/rspec/bash/wrapper/bash_wrapper.rb', line 28

def stderr_output_path
  File.join(Dir.tmpdir, "stderr-#{@port}.tmp")
end

#wrap_script(script) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/rspec/bash/wrapper/bash_wrapper.rb', line 10

def wrap_script(script)
  wrapper_template = ERB.new(File.new(wrapper_input_path).read, nil, '%')
  File.open(wrapper_output_path, 'w') do |file|
    file.write(wrapper_template.result(binding))
  end
  File.chmod(0755, wrapper_output_path)

  wrapper_output_path
end

#wrapper_input_pathObject



20
21
22
# File 'lib/rspec/bash/wrapper/bash_wrapper.rb', line 20

def wrapper_input_path
  File.join(project_root, 'bin', 'bash_wrapper.sh.erb')
end

#wrapper_output_pathObject



24
25
26
# File 'lib/rspec/bash/wrapper/bash_wrapper.rb', line 24

def wrapper_output_path
  File.join(Dir.tmpdir, "wrapper-#{@port}.sh")
end