spec/account_spec.rb in banktools-se-2.5.0 vs spec/account_spec.rb in banktools-se-2.6.0
- old
+ new
@@ -3,24 +3,24 @@
require "spec_helper"
require "banktools-se"
describe BankTools::SE::Account do
it "should initialize" do
- BankTools::SE::Account.new("foo").should be_a(BankTools::SE::Account)
+ expect(BankTools::SE::Account.new("foo")).to be_a(BankTools::SE::Account)
end
describe "#valid?" do
it "should be true with no errors" do
account = BankTools::SE::Account.new("foo")
- account.stub(:errors).and_return([])
- account.should be_valid
+ allow(account).to receive(:errors).and_return([])
+ expect(account).to be_valid
end
it "should be false with errors" do
account = BankTools::SE::Account.new("foo")
- account.stub(:errors).and_return([:error])
- account.should_not be_valid
+ allow(account).to receive(:errors).and_return([:error])
+ expect(account).not_to be_valid
end
end
describe "#errors" do
[
@@ -66,101 +66,101 @@
"9570-0000000000", # Sparbanken Syd.
"9960-00", # Nordea/Plusgirot.
].each do |number|
it "should be empty for a valid number like #{number}" do
- BankTools::SE::Account.new(number).errors.should == []
+ expect(BankTools::SE::Account.new(number).errors).to eq([])
end
end
it "should include :too_short for numbers shorter than the bank allows" do
- BankTools::SE::Account.new("11007").errors.should include(BankTools::SE::Errors::TOO_SHORT)
+ expect(BankTools::SE::Account.new("11007").errors).to include(BankTools::SE::Errors::TOO_SHORT)
end
it "should not include :too_short for Swedbank/Sparbanker numbers that can be zerofilled" do
- BankTools::SE::Account.new("8000-2-00000000").errors.should_not include(BankTools::SE::Errors::TOO_SHORT)
- BankTools::SE::Account.new("9300-2-00000000").errors.should_not include(BankTools::SE::Errors::TOO_SHORT)
- BankTools::SE::Account.new("9570-2-00000000").errors.should_not include(BankTools::SE::Errors::TOO_SHORT)
+ expect(BankTools::SE::Account.new("8000-2-00000000").errors).not_to include(BankTools::SE::Errors::TOO_SHORT)
+ expect(BankTools::SE::Account.new("9300-2-00000000").errors).not_to include(BankTools::SE::Errors::TOO_SHORT)
+ expect(BankTools::SE::Account.new("9570-2-00000000").errors).not_to include(BankTools::SE::Errors::TOO_SHORT)
end
it "should include :too_long for numbers longer than the bank allows" do
- BankTools::SE::Account.new("1100000000007").errors.should include(BankTools::SE::Errors::TOO_LONG)
+ expect(BankTools::SE::Account.new("1100000000007").errors).to include(BankTools::SE::Errors::TOO_LONG)
end
it "should not include :too_long for Swedbank/Sparbanker numbers with clearing checksum" do
- BankTools::SE::Account.new("8000-2-0000000000").errors.should_not include(BankTools::SE::Errors::TOO_LONG)
+ expect(BankTools::SE::Account.new("8000-2-0000000000").errors).not_to include(BankTools::SE::Errors::TOO_LONG)
end
it "should include :invalid_characters for numbers with other character than digits, spaces and dashes" do
- BankTools::SE::Account.new("1 2-3X").errors.should include(BankTools::SE::Errors::INVALID_CHARACTERS)
- BankTools::SE::Account.new("1 2-3").errors.should_not include(BankTools::SE::Errors::INVALID_CHARACTERS)
+ expect(BankTools::SE::Account.new("1 2-3X").errors).to include(BankTools::SE::Errors::INVALID_CHARACTERS)
+ expect(BankTools::SE::Account.new("1 2-3").errors).not_to include(BankTools::SE::Errors::INVALID_CHARACTERS)
end
it "should include :bad_checksum for Nordea personkonto if the serial Luhn/mod 10 checksum is incorrect" do
- BankTools::SE::Utils.valid_luhn?("800928-6249").should eq(true)
- BankTools::SE::Utils.valid_luhn?("3300-800928-6249").should eq(false)
- BankTools::SE::Account.new("3300-800928-6249").errors.should_not include(BankTools::SE::Errors::BAD_CHECKSUM)
+ expect(BankTools::SE::Utils.valid_luhn?("800928-6249")).to eq(true)
+ expect(BankTools::SE::Utils.valid_luhn?("3300-800928-6249")).to eq(false)
+ expect(BankTools::SE::Account.new("3300-800928-6249").errors).not_to include(BankTools::SE::Errors::BAD_CHECKSUM)
end
it "should include :unknown_clearing_number if the clearing number is unknown" do
- BankTools::SE::Account.new("10000000009").errors.should include(BankTools::SE::Errors::UNKNOWN_CLEARING_NUMBER)
- BankTools::SE::Account.new("11000000007").errors.should_not include(BankTools::SE::Errors::UNKNOWN_CLEARING_NUMBER)
+ expect(BankTools::SE::Account.new("10000000009").errors).to include(BankTools::SE::Errors::UNKNOWN_CLEARING_NUMBER)
+ expect(BankTools::SE::Account.new("11000000007").errors).not_to include(BankTools::SE::Errors::UNKNOWN_CLEARING_NUMBER)
end
end
describe "#bank" do
it "should return the bank for the current clearing number" do
- BankTools::SE::Account.new("11000000007").bank.should == "Nordea"
- BankTools::SE::Account.new("11550000001").bank.should == "Nordea"
- BankTools::SE::Account.new("11990000009").bank.should == "Nordea"
- BankTools::SE::Account.new("12000000005").bank.should == "Danske Bank"
+ expect(BankTools::SE::Account.new("11000000007").bank).to eq("Nordea")
+ expect(BankTools::SE::Account.new("11550000001").bank).to eq("Nordea")
+ expect(BankTools::SE::Account.new("11990000009").bank).to eq("Nordea")
+ expect(BankTools::SE::Account.new("12000000005").bank).to eq("Danske Bank")
end
it "should return nil for unknown clearing numbers" do
- BankTools::SE::Account.new("10000000009").bank.should be_nil
+ expect(BankTools::SE::Account.new("10000000009").bank).to be_nil
end
end
describe "#clearing_number" do
it "should be the first four digits" do
- BankTools::SE::Account.new("12345678").clearing_number.should == "1234"
+ expect(BankTools::SE::Account.new("12345678").clearing_number).to eq("1234")
end
it "should be the first five digits if there is a clearing number checksum" do
- BankTools::SE::Account.new("8000-2-0000000000").clearing_number.should == "8000-2"
+ expect(BankTools::SE::Account.new("8000-2-0000000000").clearing_number).to eq("8000-2")
end
end
describe "#serial_number" do
it "should be the digits after the first four digits" do
- BankTools::SE::Account.new("12345678").serial_number.should == "5678"
+ expect(BankTools::SE::Account.new("12345678").serial_number).to eq("5678")
end
it "should be the digits after the first five digits if there is a clearing number checksum" do
- BankTools::SE::Account.new("8000-2-0000000000").serial_number.should == "0000000000"
+ expect(BankTools::SE::Account.new("8000-2-0000000000").serial_number).to eq("0000000000")
end
it "should be the empty string if there aren't enough numbers" do
- BankTools::SE::Account.new("12").serial_number.should == ""
+ expect(BankTools::SE::Account.new("12").serial_number).to eq("")
end
end
describe "#normalize" do
it "should normalize to clearing number dash serial number" do
- account = BankTools::SE::Account.new("11000000007").normalize.should == "1100-0000007"
+ account = expect(BankTools::SE::Account.new("11000000007").normalize).to eq("1100-0000007")
end
it "should keep any Swedbank/Sparbanker clearing checksum" do
- BankTools::SE::Account.new("8000-2-0000000000").normalize.should == "8000-2-0000000000"
+ expect(BankTools::SE::Account.new("8000-2-0000000000").normalize).to eq("8000-2-0000000000")
end
it "should not attempt to normalize invalid numbers" do
- account = BankTools::SE::Account.new(" 1-2-3 ").normalize.should == " 1-2-3 "
+ account = expect(BankTools::SE::Account.new(" 1-2-3 ").normalize).to eq(" 1-2-3 ")
end
it "should prepend zeroes to the serial number if necessary" do
- BankTools::SE::Account.new("8000-2-80000003").normalize.should == "8000-2-0080000003"
- BankTools::SE::Account.new("8000-2-8000000003").normalize.should == "8000-2-8000000003"
+ expect(BankTools::SE::Account.new("8000-2-80000003").normalize).to eq("8000-2-0080000003")
+ expect(BankTools::SE::Account.new("8000-2-8000000003").normalize).to eq("8000-2-8000000003")
end
end
end