Class: Lino::Executors::Mock

Inherits:
Object
  • Object
show all
Defined in:
lib/lino/executors/mock.rb

Defined Under Namespace

Classes: Execution

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMock

Returns a new instance of Mock.



9
10
11
# File 'lib/lino/executors/mock.rb', line 9

def initialize
  reset
end

Instance Attribute Details

#executionsObject (readonly)

Returns the value of attribute executions.



6
7
8
# File 'lib/lino/executors/mock.rb', line 6

def executions
  @executions
end

#exit_codeObject

Returns the value of attribute exit_code.



7
8
9
# File 'lib/lino/executors/mock.rb', line 7

def exit_code
  @exit_code
end

#stderr_contentsObject (readonly)

Returns the value of attribute stderr_contents.



6
7
8
# File 'lib/lino/executors/mock.rb', line 6

def stderr_contents
  @stderr_contents
end

#stdout_contentsObject (readonly)

Returns the value of attribute stdout_contents.



6
7
8
# File 'lib/lino/executors/mock.rb', line 6

def stdout_contents
  @stdout_contents
end

Instance Method Details

#execute(command_line, opts = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/lino/executors/mock.rb', line 13

def execute(command_line, opts = {})
  execution = Execution.new(command_line:, opts:, exit_code: @exit_code)
  execution = process_streams(execution, opts)

  @executions << execution

  return if @exit_code.zero?

  raise Lino::Errors::ExecutionError.new(
    command_line.string, @exit_code
  )
end

#fail_all_executionsObject



26
27
28
# File 'lib/lino/executors/mock.rb', line 26

def fail_all_executions
  self.exit_code = 1
end

#resetObject



38
39
40
41
42
43
# File 'lib/lino/executors/mock.rb', line 38

def reset
  @executions = []
  @exit_code = 0
  @stdout_contents = nil
  @stderr_contents = nil
end

#write_to_stderr(contents) ⇒ Object



34
35
36
# File 'lib/lino/executors/mock.rb', line 34

def write_to_stderr(contents)
  @stderr_contents = contents
end

#write_to_stdout(contents) ⇒ Object



30
31
32
# File 'lib/lino/executors/mock.rb', line 30

def write_to_stdout(contents)
  @stdout_contents = contents
end