Class: Testjour::CLI::LocalRun

Inherits:
BaseCommand show all
Defined in:
lib/testjour/commands/local_run.rb

Direct Known Subclasses

SlaveRun

Instance Attribute Summary

Attributes inherited from BaseCommand

#non_options, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseCommand

detailed_help, help, inherited, #option_parser, options, #testjour_bin_path

Constructor Details

#initialize(parser, args) ⇒ LocalRun

Returns a new instance of LocalRun.


18
19
20
21
22
# File 'lib/testjour/commands/local_run.rb', line 18

def initialize(parser, args)
  Testjour.logger.debug "Runner command #{self.class}..."
  super
  @queue = @non_options.shift
end

Class Method Details

.commandObject


14
15
16
# File 'lib/testjour/commands/local_run.rb', line 14

def self.command
  "local:run"
end

Instance Method Details

#drb_uriObject


78
79
80
81
82
83
84
# File 'lib/testjour/commands/local_run.rb', line 78

def drb_uri
  uri = URI.parse(@queue)
  uri.scheme = "druby"
  uri.path = ""
  uri.user = nil
  uri.to_s
end

#feature_parserObject


86
87
88
# File 'lib/testjour/commands/local_run.rb', line 86

def feature_parser
  @feature_parser ||= Cucumber::TreetopParser::FeatureParser.new
end

#options_for_cucumberObject


61
62
63
# File 'lib/testjour/commands/local_run.rb', line 61

def options_for_cucumber
  @non_options
end

#queue_serverObject


71
72
73
74
75
76
# File 'lib/testjour/commands/local_run.rb', line 71

def queue_server
  @queue_server ||= begin
    DRb.start_service
    DRbObject.new(nil, drb_uri)
  end
end

#require_filesObject


54
55
56
57
58
59
# File 'lib/testjour/commands/local_run.rb', line 54

def require_files
  cli = Cucumber::CLI.new
  Testjour.logger.debug "Cucumber options: #{options_for_cucumber.inspect}"
  cli.parse_options!(options_for_cucumber)
  cli.send(:require_files)
end

#runObject


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/testjour/commands/local_run.rb', line 24

def run
  ARGV.clear # Don't pass along args to RSpec
  Testjour.load_cucumber
  
  status, stdout, stderr = systemu("#{testjour_bin_path} mysql:create")
  database_name = stdout.split.last.strip
  Testjour.logger.info "MySQL db name: #{database_name.inspect}"
  
  Cucumber::CLI.executor.formatters = Testjour::DRbFormatter.new(queue_server)
  require_files
  work
  
  status, stdout, stderr = systemu("#{testjour_bin_path} mysql:drop #{database_name}")
  Testjour.logger.info "Dropped MySQL db: #{status.inspect}, #{stdout.inspect}, #{stderr.inspect}"
end

#run_file(file) ⇒ Object


65
66
67
68
69
# File 'lib/testjour/commands/local_run.rb', line 65

def run_file(file)
  Testjour.logger.debug "Running feature file: #{file}"
  features = feature_parser.parse_feature(File.expand_path(file))
  Cucumber::CLI.executor.visit_features(features)
end

#workObject


40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/testjour/commands/local_run.rb', line 40

def work
  begin
    loop do
      begin
        run_file(queue_server.take_work)
      rescue Testjour::QueueServer::NoWorkUnitsAvailableError
        # If no work, ignore and keep looping
      end
    end
  rescue DRb::DRbConnError
    Testjour.logger.debug "DRb connection error. (This is normal.) Exiting runner."
  end
end