# encoding: utf-8

# Coverage support needs to be required *before* the RuboCop code is required!
require 'support/coverage'

require 'rubocop'

require 'webmock/rspec'

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

RSpec.configure do |config|
  # These two settings work together to allow you to limit a spec run
  # to individual examples or groups you care about by tagging them with
  # `:focus` metadata. When nothing is tagged with `:focus`, all examples
  # get run.
  config.filter_run :focus
  config.run_all_when_everything_filtered = true

  config.order = :random
  Kernel.srand config.seed

  config.filter_run_excluding ruby: ->(v) { !RUBY_VERSION.start_with?(v.to_s) }

  ruby_version = Gem::Version.new(RUBY_VERSION)
  config.filter_run_excluding ruby_less_than: (lambda do |v|
    ruby_version >= Gem::Version.new(v)
  end)
  config.filter_run_excluding ruby_greater_than_or_equal: (lambda do |v|
    ruby_version < Gem::Version.new(v)
  end)

  broken_filter = lambda do |v|
    v.is_a?(Symbol) ? RUBY_ENGINE == v.to_s : v
  end
  config.filter_run_excluding broken: broken_filter

  config.expect_with :rspec do |expectations|
    expectations.include_chain_clauses_in_custom_matcher_descriptions = true
    expectations.syntax = :expect # Disable `should`
  end

  config.mock_with :rspec do |mocks|
    mocks.syntax = :expect # Disable `should_receive` and `stub`
    mocks.verify_partial_doubles = true
  end
end

# Disable colors in specs
Rainbow.enabled = false

# Disable network connections
WebMock.disable_net_connect!(allow: 'codeclimate.com')
