Class: RspecStarter::InvokeRspecStep

Inherits:
Step
  • Object
show all
Defined in:
lib/rspec_starter/legacy/steps/invoke_rspec_step.rb

Overview

The step that actually starts the RSpec.

Instance Attribute Summary collapse

Attributes inherited from Step

#relevant_options

Instance Method Summary collapse

Methods inherited from Step

#should_skip?

Constructor Details

#initialize(defaults, runner) ⇒ InvokeRspecStep

Returns a new instance of InvokeRspecStep.



6
7
8
9
10
11
12
13
14
15
# File 'lib/rspec_starter/legacy/steps/invoke_rspec_step.rb', line 6

def initialize(defaults, runner)
  super(runner)

  @allow_xvfb = defaults.fetch(:allow_xvfb, true)
  @relevant_options = ["--no-xvfb"]
  @success_or_skipped = nil # Will be updated once step executes
  @rspec_exit_status = nil # Will be updated once step executes
  @user_wants_to_skip_xvfb = ARGV.any? { |option| option.include?("--no-xvfb") }
  init_rspec_options
end

Instance Attribute Details

#rspec_exit_statusObject (readonly)

Returns the value of attribute rspec_exit_status.



4
5
6
# File 'lib/rspec_starter/legacy/steps/invoke_rspec_step.rb', line 4

def rspec_exit_status
  @rspec_exit_status
end

Instance Method Details

#commandObject

Returns a string that will either be ‘xvfb-run bundle exec rspec’ or ‘bundle exec rspec’



41
42
43
44
45
46
47
48
# File 'lib/rspec_starter/legacy/steps/invoke_rspec_step.rb', line 41

def command
  base = "bundle exec rspec"
  return base if @runner.is_mac?
  return base unless @allow_xvfb
  return base if @user_wants_to_skip_xvfb

  @runner.xvfb_installed? ? "xvfb-run #{base}" : base
end

#executeObject



31
32
33
34
35
36
37
38
# File 'lib/rspec_starter/legacy/steps/invoke_rspec_step.rb', line 31

def execute
  cmd = command
  cmd = "#{cmd} #{@rspec_options.join(' ')}" unless @rspec_options.empty?
  puts "[#{@runner.step_num}] Running specs with '#{cmd.colorize(:light_blue)}' ...\n\n"
  system cmd
  @rspec_exit_status = $CHILD_STATUS.exitstatus
  @success_or_skipped = true
end

#failed?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/rspec_starter/legacy/steps/invoke_rspec_step.rb', line 27

def failed?
  !@success_or_skipped
end

#init_rspec_optionsObject



17
18
19
20
21
# File 'lib/rspec_starter/legacy/steps/invoke_rspec_step.rb', line 17

def init_rspec_options
  step_options = []
  @runner.steps.each { |step| step_options.concat(step.relevant_options) }
  @rspec_options = ARGV - step_options.to_a
end

#should_execute?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/rspec_starter/legacy/steps/invoke_rspec_step.rb', line 23

def should_execute?
  true
end