# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../dummy/config/environment", __FILE__)
require 'rspec/rails'

require 'fabrication'
Fabrication.configure do |config|
  config.path_prefix = AutoError::Engine.root
end

ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '../')

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
#Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
Dir[File.join(ENGINE_RAILS_ROOT, "spec/support/**/*.rb")].each { |f| require f }

RSpec.configure do |config|
  config.mock_with :rspec

  # If you're not using ActiveRecord, or you'd prefer not to run each of your
  # examples within a transaction, remove the following line or assign false
  # instead of true.
  config.use_transactional_fixtures = true

  config.include AutoError::Engine.routes.url_helpers

  def log_error!( env, exception, overrides={}, data={} )
    AutoError::AppError.log!( env, exception, {
      controller: "SomethingController",
      action: 'some_action'
    }.merge( overrides ), data )
  end

  config.before( :each ) { AutoError::Config.send(:set_defaults) }
end
