require 'validator'

describe Validator::Configuration do
  Validator::Configuration::DEFAULTS.each do |key, value|
    it "##{key}= method can set attribute #{key}" do
      config = Validator::Configuration.new
      config.send(:"#{key}=", value)
      expect(config.instance_variable_get("@#{key}")).to eq(value)
    end
  end

  describe '#initialize' do
    it 'sets attributes using defaults' do
      Validator::Configuration::DEFAULTS.each do |key, value|
        expect(Validator::Configuration.new.send(key)).to eq(value)
      end
    end

    it 'sets an attribute using args instead of default if provided' do
      expect(Validator::Configuration.new(parser: :xml).parser).to eq(:xml)
      expect(Validator::Configuration.new(showsource: false).showsource).to eq(false)
    end

    it 'returns an instance of Validator::Configuration' do
      expect(Validator::Configuration.new).to be_a(Validator::Configuration)
    end
  end

  describe '#parser=' do
    it 'returns a Symbol' do
      expect(Validator::Configuration.new.send(:parser=, :xml)).to be_a(Symbol)
    end

    it "only accepts: #{Validator::Configuration::ALLOWED_PARSERS.join(', ')}" do
      expect { Validator::Configuration.new.parser = :foo }.to raise_error(ArgumentError)
    end
  end

  it "#level= only accepts: #{Validator::Configuration::ALLOWED_LEVELS.join(', ')}" do
    expect { Validator::Configuration.new.level = :foo }.to raise_error(ArgumentError)
  end

  describe '#to_hash' do
    it 'returns a Hash' do
      expect(Validator::Configuration.new.to_hash).to be_a(Hash)
    end
  end
end
