Class: TestSquad::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/test_squad/runner.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRunner

Returns a new instance of Runner.



11
12
13
# File 'lib/test_squad/runner.rb', line 11

def initialize
  Rails.configuration.logger = logger
end

Class Method Details

.runObject



7
8
9
# File 'lib/test_squad/runner.rb', line 7

def self.run
  new.run
end

Instance Method Details

#app_serverObject



23
24
25
# File 'lib/test_squad/runner.rb', line 23

def app_server
  Rack::Handler.pick(["puma", "thin", "webrick"])
end

#configObject



15
16
17
# File 'lib/test_squad/runner.rb', line 15

def config
  TestSquad.configuration
end

#loggerObject



19
20
21
# File 'lib/test_squad/runner.rb', line 19

def logger
  @logger ||= Logger.new(StringIO.new)
end

#runObject



27
28
29
30
# File 'lib/test_squad/runner.rb', line 27

def run
  run_server
  run_tests
end

#run_serverObject



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

def run_server
  Thread.new do
    app_server.run Rails.application,
      Port: config.server_port,
      Host: config.server_host,
      Logger: logger,
      AccessLog: [],
      Silent: true
  end
end

#run_testsObject



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/test_squad/runner.rb', line 47

def run_tests
  output, status = Open3.capture2(
    config.phantomjs_bin,
    runner_script,
    config.server_uri,
    config.timeout.to_s
  )

  $stdout << output
  exit status.exitstatus
end

#runner_scriptObject



43
44
45
# File 'lib/test_squad/runner.rb', line 43

def runner_script
  File.expand_path("../../../phantomjs/runner.js", __FILE__)
end