<commit_before>require 'spec_helper'

describe VlatkoDawanda::Money do

  context '#conversion_rates parsing' do
    let(:hash_currency_input){{'USD' => 1.11, 'Bitcoin' => 0.0047}}
    let(:currencies){described_class.conversion_rates('EUR', hash_currency_input)}

    it 'includes the right currencies from input' do
      expect(currencies.keys).to contain_exactly(:eur, :usd, :bitcoin)
    end

    it 'does not include a currency that is not in the input' do
      expect(currencies.keys).to_not include(:mkd)
    end

    context 'raises an InvalidRate' do
      specify 'rate is zero' do
        invalid_hash = {'MKD' => 0}
        expect{described_class.conversion_rates('EUR', invalid_hash)}.to raise_error VlatkoDawanda::InvalidRate
      end

      specify 'rate is negative number' do
        invalid_hash = {'MKD' => -1}
        expect{described_class.conversion_rates('EUR', invalid_hash)}.to raise_error VlatkoDawanda::InvalidRate
      end
    end

    it 'parses the base currency with rate 1' do
      expect(currencies[:eur][:rate]).to eq 1
    end

    it 'parses the currencies with bigdecimal classes' do
      expect(currencies.map{|k,v| v[:rate]}).to all(be_an_instance_of(BigDecimal))
    end

    it 'equals the same rates as the input hash' do
      expect(currencies[:usd][:rate]).to eq hash_currency_input[currencies[:usd][:iso_code]]
      expect(currencies[:bitcoin][:rate]).to eq hash_currency_input[currencies[:bitcoin][:iso_code]]
    end
  end

  context 'instantation of objects' do
    before(:example) do
      described_class.conversion_rates('EUR', {'USD' => 1.11, 'Bitcoin' => 0.0047})
    end
<commit_msg>refactor: test suite to a before context hook<commit_after>require 'spec_helper'

describe VlatkoDawanda::Money do

  context '#conversion_rates parsing' do
    let(:hash_currency_input){{'USD' => 1.11, 'Bitcoin' => 0.0047}}
    let(:currencies){described_class.conversion_rates('EUR', hash_currency_input)}

    it 'includes the right currencies from input' do
      expect(currencies.keys).to contain_exactly(:eur, :usd, :bitcoin)
    end

    it 'does not include a currency that is not in the input' do
      expect(currencies.keys).to_not include(:mkd)
    end

    context 'raises an InvalidRate' do
      specify 'rate is zero' do
        invalid_hash = {'MKD' => 0}
        expect{described_class.conversion_rates('EUR', invalid_hash)}.to raise_error VlatkoDawanda::InvalidRate
      end

      specify 'rate is negative number' do
        invalid_hash = {'MKD' => -1}
        expect{described_class.conversion_rates('EUR', invalid_hash)}.to raise_error VlatkoDawanda::InvalidRate
      end
    end

    it 'parses the base currency with rate 1' do
      expect(currencies[:eur][:rate]).to eq 1
    end

    it 'parses the currencies with bigdecimal classes' do
      expect(currencies.map{|k,v| v[:rate]}).to all(be_an_instance_of(BigDecimal))
    end

    it 'equals the same rates as the input hash' do
      expect(currencies[:usd][:rate]).to eq hash_currency_input[currencies[:usd][:iso_code]]
      expect(currencies[:bitcoin][:rate]).to eq hash_currency_input[currencies[:bitcoin][:iso_code]]
    end
  end

  context 'instantation of objects' do
    before(:context) do
      described_class.conversion_rates('EUR', {'USD' => 1.11, 'Bitcoin' => 0.0047})
    end

{'fraction_non_alphanumeric': 0.1164259927797834, 'fraction_numerical': 0.012033694344163659, 'mean_word_length': 3.8469387755102042, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7299799', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1037, 'n_words': 273}