Sha256: c44460a00145c59f5f2f4d11720497d9d1ff6a40e643ec85b94715985bbd2291

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

require "teaspoon/exceptions"

module Teaspoon
  module Environment

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

      require "teaspoon"
      require "teaspoon/suite"
      require "teaspoon/server"
      require "teaspoon/exception_handling"

      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 Teaspoon::EnvironmentNotFound
    end

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

    def self.configure_from_options(options)
      options.each do |key, value|
        Teaspoon.configuration.send("#{key.downcase}=", value) if Teaspoon.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

1 entries across 1 versions & 1 rubygems

Version Path
teaspoon-0.7.8 lib/teaspoon/environment.rb