Sha256: b7c7b026c0ce6395cd620e291de393c8d99dd965ec772c0bf82a279c4b3af89e

Contents?: true

Size: 2 KB

Versions: 3

Compression:

Stored size: 2 KB

Contents

# frozen_string_literal: true

require 'spec_helper'
require 'polish_banks'

RSpec.describe PolishBank do
  subject { described_class.new(iban) }

  describe "standard iban check" do
    let(:iban) { "PL9912406999" }

    it "detects bank name" do
      expect(subject.name).to be_a String
      expect(subject.name.length).to be_positive
    end

    it "detects bank branch" do
      expect(subject.branch).to be_a String
      expect(subject.branch.length).to be_positive
    end

    context "with only partial match" do
      let(:iban) { "PL9912406666" }

      it "detects bank name" do
        expect(subject.name).to be_a String
        expect(subject.name.length).to be_positive
      end

      it "detects bank branch" do
        expect(subject.branch).to be_a String
        expect(subject.branch.length).to be_zero
      end
    end

    context "with special characters" do
      let(:iban) { "99-1240 6999" }

      it "detects bank name" do
        expect(subject.name).to be_a String
        expect(subject.name.length).to be_positive
      end

      it "detects bank branch" do
        expect(subject.branch).to be_a String
        expect(subject.branch.length).to be_positive
      end
    end
  end

  describe "account number check" do
    let(:iban) { "9912406999" }

    it "detects bank name" do
      expect(subject.name).to be_a String
      expect(subject.name.length).to be_positive
    end

    it "detects bank branch" do
      expect(subject.branch).to be_a String
      expect(subject.branch.length).to be_positive
    end
  end

  describe "error raising" do
    context "foreign iban" do
      let(:iban) { "DE9912406999" }

      it "raises UnsupportedCountry error" do
        expect { subject }.to raise_error(UnsupportedCountry, "Iban #{iban} is not Polish")
      end
    end

    context "unknown bank" do
      let(:iban) { "PL6666666666" }

      it "raises BankNotFound error" do
        expect { subject }.to raise_error(BankNotFound, "Polish bank not found for #{iban}")
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
polish_banks-1.1.3 spec/polish_banks_spec.rb
polish_banks-1.1.2 spec/polish_banks_spec.rb
polish_banks-1.1.1 spec/polish_banks_spec.rb