Class: CLIntegracon::Subject

Inherits:
Object
  • Object
show all
Defined in:
lib/CLIntegracon/subject.rb

Defined Under Namespace

Classes: ReplacementPattern

Attributes collapse

Initializer collapse

DSL-like Setter collapse

Interaction collapse

Constructor Details

#initialize(name = 'subject', executable = nil) ⇒ Subject

“Designated” initializer

Parameters:

  • name (String) (defaults to: 'subject')

    The name of the binary

  • executable (String) (defaults to: nil)

    The executable subject statement (optional)



58
59
60
61
62
63
64
65
# File 'lib/CLIntegracon/subject.rb', line 58

def initialize(name='subject', executable=nil)
  self.name = name
  self.executable = executable || name
  self.environment_vars = {}
  self.default_args = []
  self.replace_patterns = []
  self.output_path = 'execution_output.txt'
end

Instance Attribute Details

#default_argsArray<String>

Returns The arguments which will always passed to the executable on launch and should not been passed explicitly every time to the launch method. Those are added behind the arguments given on launch.

Returns:

  • (Array<String>)

    The arguments which will always passed to the executable on launch and should not been passed explicitly every time to the launch method. Those are added behind the arguments given on launch.



33
34
35
# File 'lib/CLIntegracon/subject.rb', line 33

def default_args
  @default_args
end

#environment_varsHash<String,String>

Returns The environment variables which will always been defined for the executable on launch should not been passed explicitly every time to the launch method.

Returns:

  • (Hash<String,String>)

    The environment variables which will always been defined for the executable on launch should not been passed explicitly every time to the launch method.



27
28
29
# File 'lib/CLIntegracon/subject.rb', line 27

def environment_vars
  @environment_vars
end

#executableString

Returns The executable statement to use for the tests.

Returns:

  • (String)

    The executable statement to use for the tests



22
23
24
# File 'lib/CLIntegracon/subject.rb', line 22

def executable
  @executable
end

#nameString

Returns The name of the binary to use for the tests.

Returns:

  • (String)

    The name of the binary to use for the tests



18
19
20
# File 'lib/CLIntegracon/subject.rb', line 18

def name
  @name
end

#output_pathString

Returns The path where the output of the executable will be written to.

Returns:

  • (String)

    The path where the output of the executable will be written to.



43
44
45
# File 'lib/CLIntegracon/subject.rb', line 43

def output_path
  @output_path
end

#replace_patternsArray<ReplacementPattern>

Returns The replace patterns that are redacted when the subject is executed. These are e.g. paths were side-effects occur, like manipulation of user configurations in dot files or caching-specific directories or just dates and times.

Returns:

  • (Array<ReplacementPattern>)

    The replace patterns that are redacted when the subject is executed. These are e.g. paths were side-effects occur, like manipulation of user configurations in dot files or caching-specific directories or just dates and times.



39
40
41
# File 'lib/CLIntegracon/subject.rb', line 39

def replace_patterns
  @replace_patterns
end

Instance Method Details

#launch(head_arguments = '', tail_arguments = '') ⇒ String

Runs the executable with the given arguments.

@note: You can check by ‘$?.success?` if the execution succeeded.

Parameters:

  • head_arguments (String) (defaults to: '')

    The arguments to pass to the executable before the default arguments.

  • tail_arguments (String) (defaults to: '')

    The arguments to pass to the executable after the default arguments.

Returns:

  • (String)

    The output, which is emitted while execution.



130
131
132
133
134
135
136
# File 'lib/CLIntegracon/subject.rb', line 130

def launch(head_arguments='', tail_arguments='')
  command = command_line(head_arguments, tail_arguments)
  output, status = run(command)
  output = apply_replacements(output)
  write_output(command, output)
  [output, status]
end

#replace_path(path, name = nil) ⇒ Object

Define a path, whose occurrences in the output should be replaced by either its basename or a given placeholder.

Parameters:

  • path (String)

    The path

  • name (String) (defaults to: nil)

    The name of the path, or the basename of the given path



94
95
96
97
# File 'lib/CLIntegracon/subject.rb', line 94

def replace_path(path, name=nil)
  name ||= File.basename path
  self.replace_pattern path, name
end

#replace_pattern(pattern, replacement) ⇒ Object

Define a pattern, whose occurrences in the output should be replaced by a given placeholder.

Parameters:

  • pattern (Regexp|String)

    The pattern

  • replacement (String)

    The replacement



81
82
83
# File 'lib/CLIntegracon/subject.rb', line 81

def replace_pattern(pattern, replacement)
  self.replace_patterns << ReplacementPattern.new(pattern, replacement)
end

#replace_user_path(path, name = nil) ⇒ Object

Define a path in the user directory, whose occurrences in the output should be replaced by either its basename or a given placeholder.

Parameters:

  • path (String)

    The path

  • name (String) (defaults to: nil)

    The name of the path, or the given path



108
109
110
111
# File 'lib/CLIntegracon/subject.rb', line 108

def replace_user_path(path, name=nil)
  name ||= "$HOME/#{path}"
  self.replace_path %r[/Users/.*/#{path.to_s}], name
end