Class: CLIntegracon::Subject
- Inherits:
-
Object
- Object
- CLIntegracon::Subject
- Defined in:
- lib/CLIntegracon/subject.rb
Attributes collapse
-
#default_args ⇒ 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.
-
#environment_vars ⇒ 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.
-
#executable ⇒ String
The executable statement to use for the tests.
-
#name ⇒ String
The name of the binary to use for the tests.
-
#output_path ⇒ String
The path where the output of the executable will be written to.
-
#replace_patterns ⇒ Hash<String|Regexp,String>
The replace patterns, whose keys are expected to occur in the output, which should be redacted, when the subject will be executed.
Initializer collapse
-
#initialize(name = 'subject', executable = nil) ⇒ Subject
constructor
“Designated” initializer.
DSL-like Setter collapse
-
#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.
-
#replace_pattern(pattern, replacement) ⇒ Object
Define a pattern, whose occurrences in the output should be replaced by a given placeholder.
-
#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.
Interaction collapse
-
#launch(head_arguments = '', tail_arguments = '') ⇒ String
Runs the executable with the given arguments.
Constructor Details
#initialize(name = 'subject', executable = nil) ⇒ Subject
“Designated” initializer
51 52 53 54 55 56 57 58 |
# File 'lib/CLIntegracon/subject.rb', line 51 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_args ⇒ Array<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.
25 26 27 |
# File 'lib/CLIntegracon/subject.rb', line 25 def default_args @default_args end |
#environment_vars ⇒ Hash<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.
19 20 21 |
# File 'lib/CLIntegracon/subject.rb', line 19 def environment_vars @environment_vars end |
#executable ⇒ String
Returns The executable statement to use for the tests.
14 15 16 |
# File 'lib/CLIntegracon/subject.rb', line 14 def executable @executable end |
#name ⇒ String
Returns The name of the binary to use for the tests.
10 11 12 |
# File 'lib/CLIntegracon/subject.rb', line 10 def name @name end |
#output_path ⇒ String
Returns The path where the output of the executable will be written to.
36 37 38 |
# File 'lib/CLIntegracon/subject.rb', line 36 def output_path @output_path end |
#replace_patterns ⇒ Hash<String|Regexp,String>
Returns The replace patterns, whose keys are expected to occur in the output, which should be redacted, when the subject will be 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.
32 33 34 |
# File 'lib/CLIntegracon/subject.rb', line 32 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.
123 124 125 126 127 128 |
# File 'lib/CLIntegracon/subject.rb', line 123 def launch(head_arguments='', tail_arguments='') command = command_line(head_arguments, tail_arguments) output = apply_replacements(run(command)) write_output(command, output) output 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.
87 88 89 90 |
# File 'lib/CLIntegracon/subject.rb', line 87 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.
74 75 76 |
# File 'lib/CLIntegracon/subject.rb', line 74 def replace_pattern(pattern, replacement) self.replace_patterns[replacement] = pattern 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.
101 102 103 104 |
# File 'lib/CLIntegracon/subject.rb', line 101 def replace_user_path(path, name=nil) name ||= "$HOME/#{path}" self.replace_path %r[/Users/.*/#{path.to_s}], name end |