lib/teaspoon/console.rb in teaspoon-0.9.1 vs lib/teaspoon/console.rb in teaspoon-1.0.0

- old
+ new

@@ -3,15 +3,16 @@ module Teaspoon class Console def initialize(options = {}) @default_options = options @suites = {} + Teaspoon::Environment.check_env!(options[:environment]) Teaspoon::Environment.load(options) @server = start_server - rescue Teaspoon::ServerException => e - abort(e.message) + rescue Teaspoon::ServerError => e + Teaspoon.abort(e.message) end def options @execute_options ||= {} @default_options ||= {} @@ -24,15 +25,15 @@ def execute(options = {}) execute_without_handling(options) rescue Teaspoon::Failure false - rescue Teaspoon::RunnerException => e + rescue Teaspoon::RunnerError => e log(e.message) false rescue Teaspoon::Error => e - abort(e.message) + Teaspoon.abort(e.message) end def execute_without_handling(execute_options = {}) @execute_options = execute_options @suites = {} @@ -45,25 +46,21 @@ failures end end def run_specs(suite) - unless Teaspoon.configuration.suite_configs[suite.to_s] - raise Teaspoon::UnknownSuite, "Unknown suite: \"#{suite}\"" - end + 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 def export(suite) - unless Teaspoon.configuration.suite_configs[suite.to_s] - raise Teaspoon::UnknownSuite, "Unknown suite: \"#{suite}\"" - end + 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 @@ -92,14 +89,12 @@ Teaspoon.configuration.suite_configs.keys end def driver return @driver if @driver - klass = "#{Teaspoon.configuration.driver.to_s.camelize}Driver" - @driver = Teaspoon::Drivers.const_get(klass).new(Teaspoon.configuration.driver_options) - rescue NameError - raise Teaspoon::UnknownDriver, "Unknown driver: \"#{Teaspoon.configuration.driver}\"" + driver = Teaspoon::Driver.fetch(Teaspoon.configuration.driver) + @driver = driver.new(Teaspoon.configuration.driver_options) end def base_url_for(suite) ["#{@server.url}#{Teaspoon.configuration.mount_at}", suite].join("/") end @@ -115,15 +110,10 @@ parts << "grep=#{URI::encode(options[:filter])}" if options[:filter].present? (@suites[suite] || options[:files] || []).flatten.each { |file| parts << "file[]=#{URI::encode(file)}" } "#{parts.join('&')}" if parts.present? end - def log(str, force = false) - STDOUT.print("#{str}\n") if force || !Teaspoon.configuration.suppress_log - end - - def abort(message = nil) - log(message, true) if message - exit(1) + def log(str) + STDOUT.print("#{str}\n") unless Teaspoon.configuration.suppress_log end end end