Class: Completely::Tester

Inherits:
Object
  • Object
show all
Defined in:
lib/completely/tester.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(function_name:, script: nil, script_path: nil) ⇒ Tester

Returns a new instance of Tester.



8
9
10
11
12
# File 'lib/completely/tester.rb', line 8

def initialize(function_name:, script: nil, script_path: nil)
  @script = script
  @script_path = script_path
  @function_name = function_name
end

Instance Attribute Details

#complineObject (readonly)

Returns the value of attribute compline.



6
7
8
# File 'lib/completely/tester.rb', line 6

def compline
  @compline
end

#cwordObject (readonly)

Returns the value of attribute cword.



6
7
8
# File 'lib/completely/tester.rb', line 6

def cword
  @cword
end

#function_nameObject (readonly)

Returns the value of attribute function_name.



6
7
8
# File 'lib/completely/tester.rb', line 6

def function_name
  @function_name
end

#scriptObject (readonly)

Returns the value of attribute script.



6
7
8
# File 'lib/completely/tester.rb', line 6

def script
  @script
end

#script_pathObject (readonly)

Returns the value of attribute script_path.



6
7
8
# File 'lib/completely/tester.rb', line 6

def script_path
  @script_path
end

Instance Method Details

#test(compline) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/completely/tester.rb', line 14

def test(compline)
  Tempfile.create 'completely-tester' do |f|
    f << tester_script(compline)
    f.flush
    `bash #{f.path}`
  end.split "\n"
end

#tester_script(compline) ⇒ Object



22
23
24
25
# File 'lib/completely/tester.rb', line 22

def tester_script(compline)
  set_compline_vars compline
  ERB.new(template, trim_mode: '%-').result(binding)
end