Class: Oncall::Core::Runner

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reporter = Oncall::Core.reporter, config = Oncall::Core.config, world = Oncall::Core.world) ⇒ Runner

Returns a new instance of Runner.



4
5
6
7
8
# File 'lib/oncall/core/runner.rb', line 4

def initialize(reporter=Oncall::Core.reporter, config=Oncall::Core.config, world=Oncall::Core.world)
  @config = config
  @world = world
  @reporter = reporter
end

Class Method Details

.invoke(args) ⇒ Object



10
11
12
13
# File 'lib/oncall/core/runner.rb', line 10

def self.invoke(args)
  status = run(args, $stderr, $stdout).to_i
  exit(status) if status != 0
end

.run(args, err = $stderr, out = $stdout) ⇒ Object



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

def self.run(args, err=$stderr, out=$stdout)
  new.run(args, err, out)
end

Instance Method Details

#run(args, err, out) ⇒ Object



19
20
21
22
# File 'lib/oncall/core/runner.rb', line 19

def run(args, err, out)
  setup(args, err, out)
  run_tests(@world.suite)
end

#run_tests(suite) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/oncall/core/runner.rb', line 41

def run_tests(suite)
  @reporter.report(suite) do |reporter|
    suite.map { |g| g.run(reporter) }
  end

  @reporter.success? ? 0 : @config.failure_exit_code
end

#setup(args, err, out) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/oncall/core/runner.rb', line 24

def setup(args, err, out)
  begin
    config = YAML.load_file('oncall.yml')
  rescue StandardError
    puts 'Cannot load oncall.yml'
    exit 1
  end

  env = args[1] || config['default']

  @config.set_config(config)
  @config.set_env(env)

  files = @config.test_files
  @world.register_suite(files)
end