Class: RspecStarter::Command

Inherits:
RspecStarterStep show all
Defined in:
lib/rspec_starter/command.rb

Overview

Commands are steps that execute shell scripts or shell commands. They can be created using the command method inside the RspecStarter.start block. Commands execute quietly unless you specifically set ‘quiet: false’.

RspecStarter.start do
  command "echo 'Done'"
  command "echo 'This command shows the echo'", quiet: false
end

Instance Attribute Summary collapse

Attributes inherited from RspecStarterStep

#exit_status, #id, #name, #options, #quiet, #run_time, #runner, #successful

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RspecStarterStep

default_stop_on_problem, #failed?, #helpers, provide_options_to, #quiet?, register_options, #run, #should_skip?, #stop_on_problem?, #verbose?

Constructor Details

#initialize(id, runner, command_string, options) ⇒ Command

Returns a new instance of Command.



13
14
15
16
# File 'lib/rspec_starter/command.rb', line 13

def initialize(id, runner, command_string, options)
  super(id, runner, options)
  @command_string = command_string
end

Instance Attribute Details

#statusObject

Returns the value of attribute status.



11
12
13
# File 'lib/rspec_starter/command.rb', line 11

def status
  @status
end

#stderrObject

Returns the value of attribute stderr.



11
12
13
# File 'lib/rspec_starter/command.rb', line 11

def stderr
  @stderr
end

#stdoutObject

Returns the value of attribute stdout.



11
12
13
# File 'lib/rspec_starter/command.rb', line 11

def stdout
  @stdout
end

Class Method Details

.default_quietObject



18
19
20
# File 'lib/rspec_starter/command.rb', line 18

def self.default_quiet
  true
end

Instance Method Details

#executeObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rspec_starter/command.rb', line 26

def execute
  if quiet?
    @stdout, @stderr, @status = Open3.capture3(@command_string)
  else
    @verbose_command_passed = system(@command_string)
    @status = $CHILD_STATUS
    print "Executed #{colored_command_string} -"
  end

  problem(exit_status: @status.exitstatus) if command_failed?
end


22
23
24
# File 'lib/rspec_starter/command.rb', line 22

def print_starting_message
  print "Executing #{colored_command_string} ..." + (quiet? ? "" : "\n")
end