Class: RspecStarter::InvokeRspecStep

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

Instance Attribute Summary

Attributes inherited from Step

#relevant_options

Instance Method Summary collapse

Methods inherited from Step

#should_skip?

Constructor Details

#initialize(defaults, runner) ⇒ InvokeRspecStep



4
5
6
7
8
9
10
11
# File 'lib/rspec_starter/steps/invoke_rspec_step.rb', line 4

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
  @user_wants_to_skip_xvfb = ARGV.any? { |option| option.include?("--no-xvfb") }
  init_rspec_options
end

Instance Method Details

#commandObject

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



36
37
38
39
40
41
42
# File 'lib/rspec_starter/steps/invoke_rspec_step.rb', line 36

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



27
28
29
30
31
32
33
# File 'lib/rspec_starter/steps/invoke_rspec_step.rb', line 27

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

#failed?Boolean



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

def failed?
  !@success_or_skipped
end

#init_rspec_optionsObject



13
14
15
16
17
# File 'lib/rspec_starter/steps/invoke_rspec_step.rb', line 13

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



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

def should_execute?
  true
end