Class: RspecStarter::LegacyRunner

Inherits:
Object
  • Object
show all
Includes:
Help
Defined in:
lib/rspec_starter/legacy/legacy_runner.rb

Overview

This is a simple class that encapulates the process of running RSpec. When a Runner is created, it creates a set of steps that will be executed, in order, when the ‘run’ method is invoked. Each step encapsulates an action that can be taken to help invoke Rspec. Steps are typically independent do not depend on information from other steps. However this is not a hard rule. If more complex steps are needed, feel free to create them. Each steps knows about the main runner object, so the runner object is a good place to store shared info.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Help

#calling_file_name, #should_show_help?, #show_help

Constructor Details

#initialize(defaults) ⇒ LegacyRunner

Returns a new instance of LegacyRunner.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rspec_starter/legacy/legacy_runner.rb', line 21

def initialize(defaults)
  @steps = []
  @step_num = 1
  @xvfb_installed = RspecStarter.which("xvfb-run")
  @prep_db_step = PrepareDatabaseStep.new(defaults, self)
  @run_rspec_step = InvokeRspecStep.new(defaults, self)
  @steps << VerifyXvfbStep.new(defaults, self)
  @steps << @prep_db_step
  @steps << RemoveTmpFolderStep.new(defaults, self)
  @steps << @run_rspec_step
end

Instance Attribute Details

#step_numObject (readonly)

Returns the value of attribute step_num.



19
20
21
# File 'lib/rspec_starter/legacy/legacy_runner.rb', line 19

def step_num
  @step_num
end

#stepsObject (readonly)

Returns the value of attribute steps.



19
20
21
# File 'lib/rspec_starter/legacy/legacy_runner.rb', line 19

def steps
  @steps
end

#xvfb_installedObject (readonly)

Returns the value of attribute xvfb_installed.



19
20
21
# File 'lib/rspec_starter/legacy/legacy_runner.rb', line 19

def xvfb_installed
  @xvfb_installed
end

Instance Method Details

#finalize_exitObject



84
85
86
87
88
# File 'lib/rspec_starter/legacy/legacy_runner.rb', line 84

def finalize_exit
  exit(1) if @run_rspec_step.rspec_exit_status.nonzero?
  exit(1) if @prep_db_step.exit_status.nonzero?
  exit(0)
end

#is_linux?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/rspec_starter/legacy/legacy_runner.rb', line 72

def is_linux?
  operating_system_name == 'Linux'
end

#is_mac?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/rspec_starter/legacy/legacy_runner.rb', line 76

def is_mac?
  operating_system_name == 'MacOS'
end

#operating_system_nameObject



64
65
66
67
68
69
70
# File 'lib/rspec_starter/legacy/legacy_runner.rb', line 64

def operating_system_name
  result = `uname`
  return 'Linux' if result.include?('Linux')
  return 'MacOS' if result.include?('Darwin')

  'Unknown'
end

#project_has_lib_dir?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/rspec_starter/legacy/legacy_runner.rb', line 60

def project_has_lib_dir?
  Dir.exist?("#{Dir.pwd}/lib")
end

#project_is_rails_app?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/rspec_starter/legacy/legacy_runner.rb', line 47

def project_is_rails_app?
  File.file?(File.join(Dir.pwd, 'config', 'application.rb'))
end

#project_is_rails_engine?Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
# File 'lib/rspec_starter/legacy/legacy_runner.rb', line 51

def project_is_rails_engine?
  return false unless project_has_lib_dir?

  Dir["#{Dir.pwd}/lib/**/*.rb"].each do |file|
    return true if File.readlines(file).detect { |line| line.match(/\s*class\s+.*<\s+::Rails::Engine/) }
  end
  false
end

#runObject



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rspec_starter/legacy/legacy_runner.rb', line 33

def run
  return show_help if should_show_help? # If we show help, exit and don't do anything else.

  @steps.each do |step|
    next unless step.should_execute?

    step.execute
    @step_num += 1
    break if step.failed?
  end

  finalize_exit
end

#xvfb_installed?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/rspec_starter/legacy/legacy_runner.rb', line 80

def xvfb_installed?
  @xvfb_installed
end