Class: Teaspoon::Console

Inherits:
Object
  • Object
show all
Defined in:
lib/teaspoon/console.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Console

Returns a new instance of Console.



6
7
8
9
10
11
12
13
14
15
# File 'lib/teaspoon/console.rb', line 6

def initialize(options = {})
  @default_options = options
  @suites = {}
  Teaspoon::Environment.check_env!(options[:environment])
  Teaspoon::Environment.load(options)

  @server = start_server
rescue Teaspoon::ServerError => e
  Teaspoon.abort(e.message)
end

Instance Method Details

#execute(options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/teaspoon/console.rb', line 27

def execute(options = {})
  execute_without_handling(options)
rescue Teaspoon::Failure
  false
rescue Teaspoon::RunnerError => e
  log(e.message)
  false
rescue Teaspoon::Error => e
  Teaspoon.abort(e.message)
end

#execute_without_handling(execute_options = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/teaspoon/console.rb', line 38

def execute_without_handling(execute_options = {})
  @execute_options = execute_options
  @suites = {}
  resolve(options[:files])

  0 == suites.inject(0) do |failures, suite|
    export(suite) if options.include?(:export)
    failures += run_specs(suite)
    log("") # empty line for space
    failures
  end
end

#export(suite) ⇒ Object



61
62
63
64
65
66
# File 'lib/teaspoon/console.rb', line 61

def export(suite)
  raise Teaspoon::UnknownSuite.new(name: suite) unless Teaspoon.configuration.suite_configs[suite.to_s]

  log("Teaspoon exporting #{suite} suite at #{base_url_for(suite)}")
  Teaspoon::Exporter.new(suite, url_for(suite, false), options[:export]).export
end

#failures?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/teaspoon/console.rb', line 23

def failures?
  !execute
end

#optionsObject



17
18
19
20
21
# File 'lib/teaspoon/console.rb', line 17

def options
  @execute_options ||= {}
  @default_options ||= {}
  @default_options.merge(@execute_options)
end

#run_specs(suite) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/teaspoon/console.rb', line 51

def run_specs(suite)
  raise Teaspoon::UnknownSuite.new(name: suite) unless Teaspoon.configuration.suite_configs[suite.to_s]

  log("Teaspoon running #{suite} suite at #{base_url_for(suite)}")
  runner = Teaspoon::Runner.new(suite)
  driver.run_specs(runner, url_for(suite))
  raise Teaspoon::Failure if Teaspoon.configuration.fail_fast && runner.failure_count > 0
  runner.failure_count
end