Class: RspecStarter::Runner

Inherits:
Object
  • Object
show all
Includes:
Help
Defined in:
lib/rspec_starter/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) ⇒ Runner

Returns a new instance of Runner.



22
23
24
25
26
27
28
29
30
# File 'lib/rspec_starter/runner.rb', line 22

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

Instance Attribute Details

#step_numObject (readonly)

Returns the value of attribute step_num.



20
21
22
# File 'lib/rspec_starter/runner.rb', line 20

def step_num
  @step_num
end

#stepsObject (readonly)

Returns the value of attribute steps.



20
21
22
# File 'lib/rspec_starter/runner.rb', line 20

def steps
  @steps
end

#xvfb_installedObject (readonly)

Returns the value of attribute xvfb_installed.



20
21
22
# File 'lib/rspec_starter/runner.rb', line 20

def xvfb_installed
  @xvfb_installed
end

Instance Method Details

#app_uses_rails?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/rspec_starter/runner.rb', line 44

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

#is_linux?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/rspec_starter/runner.rb', line 55

def is_linux?
  operating_system_name == 'Linux'
end

#is_mac?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/rspec_starter/runner.rb', line 59

def is_mac?
  operating_system_name == 'MacOS'
end

#operating_system_nameObject



48
49
50
51
52
53
# File 'lib/rspec_starter/runner.rb', line 48

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

#runObject



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rspec_starter/runner.rb', line 32

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

  @steps.each do |step|
    if step.should_execute?
      step.execute
      @step_num += 1
      break if step.failed?
    end
  end
end

#xvfb_installed?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/rspec_starter/runner.rb', line 63

def xvfb_installed?
  @xvfb_installed
end