Sha256: 3b940c6016c79bbac1b8b0b7c84469d688aeab24e16faa87f3646d31e1d9482d

Contents?: true

Size: 1.15 KB

Versions: 7

Compression:

Stored size: 1.15 KB

Contents

require "teabag/exceptions"

module Teabag
  module Environment

    def self.load(options = {})
      unless rails_loaded?
        require_environment(options[:environment])
        raise "Rails environment not found." unless rails_loaded?
      end

      require "teabag"
      require "teabag/suite"
      require "teabag/server"

      configure_from_options(options)
    end

    def self.require_environment(override = nil)
      return require_env(File.expand_path(override, Dir.pwd)) if override

      standard_environments.each do |filename|
        file = File.expand_path(filename, Dir.pwd)
        return require_env(file) if File.exists?(file)
      end

      raise Teabag::EnvironmentNotFound
    end

    def self.standard_environments
      ["spec/teabag_env.rb", "test/teabag_env.rb", "teabag_env.rb"]
    end

    def self.configure_from_options(options)
      options.each do |key, value|
        Teabag.configuration.send("#{key.downcase}=", value) if Teabag.configuration.respond_to?("#{key.downcase}=")
      end
    end

    def self.require_env(file)
      require(file)
    end

    def self.rails_loaded?
      defined?(Rails)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
teabag-0.7.3 lib/teabag/environment.rb
teabag-0.7.2 lib/teabag/environment.rb
teabag-0.7.1 lib/teabag/environment.rb
teabag-0.7.0 lib/teabag/environment.rb
teabag-0.6.0 lib/teabag/environment.rb
teabag-0.5.5 lib/teabag/environment.rb
teabag-0.5.4 lib/teabag/environment.rb