Skip to content

Commit

Permalink
Convert specs to RSpec 3.0.0 syntax with Transpec
Browse files Browse the repository at this point in the history
  • Loading branch information
ledermann committed Jun 9, 2014
1 parent 9bf1946 commit bdfc051
Show file tree
Hide file tree
Showing 14 changed files with 185 additions and 186 deletions.
4 changes: 2 additions & 2 deletions sepa_king.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'builder'
s.add_runtime_dependency 'iban-tools'

s.add_development_dependency 'bundler', '~> 1.3'
s.add_development_dependency 'rspec', '>=2.14'
s.add_development_dependency 'bundler'
s.add_development_dependency 'rspec', '~> 3.0'
s.add_development_dependency 'coveralls'
s.add_development_dependency 'simplecov'
s.add_development_dependency 'rake'
Expand Down
12 changes: 6 additions & 6 deletions spec/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,31 @@

describe :name do
it 'should accept valid value' do
SEPA::Account.should accept('Gläubiger GmbH', 'Zahlemann & Söhne GbR', 'X' * 70, for: :name)
expect(SEPA::Account).to accept('Gläubiger GmbH', 'Zahlemann & Söhne GbR', 'X' * 70, for: :name)
end

it 'should not accept invalid value' do
SEPA::Account.should_not accept(nil, '', 'X' * 71, for: :name)
expect(SEPA::Account).not_to accept(nil, '', 'X' * 71, for: :name)
end
end

describe :iban do
it 'should accept valid value' do
SEPA::Account.should accept('DE21500500009876543210', 'PL61109010140000071219812874', for: :iban)
expect(SEPA::Account).to accept('DE21500500009876543210', 'PL61109010140000071219812874', for: :iban)
end

it 'should not accept invalid value' do
SEPA::Account.should_not accept(nil, '', 'invalid', for: :iban)
expect(SEPA::Account).not_to accept(nil, '', 'invalid', for: :iban)
end
end

describe :bic do
it 'should accept valid value' do
SEPA::Account.should accept('DEUTDEFF', 'DEUTDEFF500', 'SPUEDE2UXXX', for: :bic)
expect(SEPA::Account).to accept('DEUTDEFF', 'DEUTDEFF500', 'SPUEDE2UXXX', for: :bic)
end

it 'should not accept invalid value' do
SEPA::Account.should_not accept('', 'invalid', for: :bic)
expect(SEPA::Account).not_to accept('', 'invalid', for: :bic)
end
end
end
26 changes: 13 additions & 13 deletions spec/converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,48 @@

describe :convert_text do
it 'should remove invalid chars' do
convert_text('&@"=<>!').should == ''
expect(convert_text('&@"=<>!')).to eq('')
end

it 'should not touch valid chars' do
convert_text("abc-ABC-0123- ':?,-(+.)/").should == "abc-ABC-0123- ':?,-(+.)/"
expect(convert_text("abc-ABC-0123- ':?,-(+.)/")).to eq("abc-ABC-0123- ':?,-(+.)/")
end

it 'should convert umlaute' do
convert_text('üöäÜÖÄß').should == 'uoaUOAss'
expect(convert_text('üöäÜÖÄß')).to eq('uoaUOAss')
end

it 'should convert line breaks' do
convert_text("one\ntwo") .should == 'one two'
convert_text("one\ntwo\n") .should == 'one two'
convert_text("\none\ntwo\n").should == 'one two'
convert_text("one\n\ntwo") .should == 'one two'
expect(convert_text("one\ntwo")) .to eq('one two')
expect(convert_text("one\ntwo\n")) .to eq('one two')
expect(convert_text("\none\ntwo\n")).to eq('one two')
expect(convert_text("one\n\ntwo")) .to eq('one two')
end

it 'should convert number' do
convert_text(1234).should == '1234'
expect(convert_text(1234)).to eq('1234')
end

it 'should not touch nil' do
convert_text(nil).should == nil
expect(convert_text(nil)).to eq(nil)
end
end

describe :convert_decimal do
it "should convert Integer to BigDecimal" do
convert_decimal(42).should == BigDecimal('42.00')
expect(convert_decimal(42)).to eq(BigDecimal('42.00'))
end

it "should convert Float to BigDecimal" do
convert_decimal(42.12).should == BigDecimal('42.12')
expect(convert_decimal(42.12)).to eq(BigDecimal('42.12'))
end

it 'should round' do
convert_decimal(1.345).should == BigDecimal('1.35')
expect(convert_decimal(1.345)).to eq(BigDecimal('1.35'))
end

it 'should not touch nil' do
convert_decimal(nil).should == nil
expect(convert_decimal(nil)).to eq(nil)
end
end
end
86 changes: 43 additions & 43 deletions spec/credit_transfer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
credit_transfer.add_transaction(credit_transfer_transaction)
end

expect(credit_transfer).to have(3).transactions
expect(credit_transfer.transactions.size).to eq(3)
end

it 'should fail for invalid transaction' do
Expand Down Expand Up @@ -120,73 +120,73 @@
end

it 'should have message_identification' do
subject.should have_xml('//Document/CstmrCdtTrfInitn/GrpHdr/MsgId', /SEPA-KING\/[0-9]+/)
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/GrpHdr/MsgId', /SEPA-KING\/[0-9]+/)
end

it 'should contain <PmtInfId>' do
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf/PmtInfId', /SEPA-KING\/[0-9]+\/1/)
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/PmtInfId', /SEPA-KING\/[0-9]+\/1/)
end

it 'should contain <ReqdExctnDt>' do
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf/ReqdExctnDt', Date.today.next.iso8601)
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/ReqdExctnDt', Date.today.next.iso8601)
end

it 'should contain <PmtMtd>' do
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf/PmtMtd', 'TRF')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/PmtMtd', 'TRF')
end

it 'should contain <BtchBookg>' do
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf/BtchBookg', 'true')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/BtchBookg', 'true')
end

it 'should contain <NbOfTxs>' do
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf/NbOfTxs', '2')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/NbOfTxs', '2')
end

it 'should contain <CtrlSum>' do
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CtrlSum', '161.50')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CtrlSum', '161.50')
end

it 'should contain <Dbtr>' do
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf/Dbtr/Nm', 'Schuldner GmbH')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/Dbtr/Nm', 'Schuldner GmbH')
end

it 'should contain <DbtrAcct>' do
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf/DbtrAcct/Id/IBAN', 'DE87200500001234567890')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/DbtrAcct/Id/IBAN', 'DE87200500001234567890')
end

it 'should contain <DbtrAgt>' do
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf/DbtrAgt/FinInstnId/BIC', 'BANKDEFFXXX')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/DbtrAgt/FinInstnId/BIC', 'BANKDEFFXXX')
end

it 'should contain <EndToEndId>' do
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/PmtId/EndToEndId', 'XYZ-1234/123')
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/PmtId/EndToEndId', 'XYZ-5678/456')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/PmtId/EndToEndId', 'XYZ-1234/123')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/PmtId/EndToEndId', 'XYZ-5678/456')
end

it 'should contain <Amt>' do
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/Amt/InstdAmt', '102.50')
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/Amt/InstdAmt', '59.00')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/Amt/InstdAmt', '102.50')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/Amt/InstdAmt', '59.00')
end

it 'should contain <CdtrAgt> for every BIC given' do
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/CdtrAgt/FinInstnId/BIC', 'PBNKDEFF370')
subject.should_not have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/CdtrAgt')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/CdtrAgt/FinInstnId/BIC', 'PBNKDEFF370')
expect(subject).not_to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/CdtrAgt')
end

it 'should contain <Cdtr>' do
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/Cdtr/Nm', 'Telekomiker AG')
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/Cdtr/Nm', 'Amazonas GmbH')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/Cdtr/Nm', 'Telekomiker AG')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/Cdtr/Nm', 'Amazonas GmbH')
end

it 'should contain <CdtrAcct>' do
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/CdtrAcct/Id/IBAN', 'DE37112589611964645802')
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/CdtrAcct/Id/IBAN', 'DE27793589132923472195')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/CdtrAcct/Id/IBAN', 'DE37112589611964645802')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/CdtrAcct/Id/IBAN', 'DE27793589132923472195')
end

it 'should contain <RmtInf>' do
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/RmtInf/Ustrd', 'Rechnung vom 22.08.2013')
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/RmtInf/Ustrd', 'Rechnung vom 21.08.2013')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/RmtInf/Ustrd', 'Rechnung vom 22.08.2013')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/RmtInf/Ustrd', 'Rechnung vom 21.08.2013')
end
end

Expand All @@ -202,15 +202,15 @@
end

it 'should contain two payment_informations with <ReqdExctnDt>' do
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/ReqdExctnDt', (Date.today + 1).iso8601)
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/ReqdExctnDt', (Date.today + 2).iso8601)
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/ReqdExctnDt', (Date.today + 1).iso8601)
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/ReqdExctnDt', (Date.today + 2).iso8601)

subject.should_not have_xml('//Document/CstmrCdtTrfInitn/PmtInf[3]')
expect(subject).not_to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[3]')
end

it 'should contain two payment_informations with different <PmtInfId>' do
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/PmtInfId', /SEPA-KING\/[0-9]+\/1/)
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/PmtInfId', /SEPA-KING\/[0-9]+\/2/)
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/PmtInfId', /SEPA-KING\/[0-9]+\/1/)
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/PmtInfId', /SEPA-KING\/[0-9]+\/2/)
end
end

Expand All @@ -226,10 +226,10 @@
end

it 'should contain two payment_informations with <BtchBookg>' do
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/BtchBookg', 'false')
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/BtchBookg', 'true')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/BtchBookg', 'false')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/BtchBookg', 'true')

subject.should_not have_xml('//Document/CstmrCdtTrfInitn/PmtInf[3]')
expect(subject).not_to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[3]')
end
end

Expand All @@ -246,24 +246,24 @@
end

it 'should contain multiple payment_informations' do
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/ReqdExctnDt', (Date.today + 1).iso8601)
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/BtchBookg', 'false')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/ReqdExctnDt', (Date.today + 1).iso8601)
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/BtchBookg', 'false')

subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/ReqdExctnDt', (Date.today + 1).iso8601)
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/BtchBookg', 'true')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/ReqdExctnDt', (Date.today + 1).iso8601)
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/BtchBookg', 'true')

subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf[3]/ReqdExctnDt', (Date.today + 2).iso8601)
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf[3]/BtchBookg', 'false')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[3]/ReqdExctnDt', (Date.today + 2).iso8601)
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[3]/BtchBookg', 'false')

subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf[4]/ReqdExctnDt', (Date.today + 2).iso8601)
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf[4]/BtchBookg', 'true')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[4]/ReqdExctnDt', (Date.today + 2).iso8601)
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[4]/BtchBookg', 'true')
end

it 'should have multiple control sums' do
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/CtrlSum', '1.00')
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/CtrlSum', '2.00')
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf[3]/CtrlSum', '4.00')
subject.should have_xml('//Document/CstmrCdtTrfInitn/PmtInf[4]/CtrlSum', '8.00')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/CtrlSum', '1.00')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/CtrlSum', '2.00')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[3]/CtrlSum', '4.00')
expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[4]/CtrlSum', '8.00')
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions spec/credit_transfer_transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,29 @@
describe :schema_compatible? do
context 'for pain.001.003.03' do
it 'should success' do
SEPA::CreditTransferTransaction.new({}).should be_schema_compatible('pain.001.003.03')
expect(SEPA::CreditTransferTransaction.new({})).to be_schema_compatible('pain.001.003.03')
end
end

context 'pain.001.002.03' do
it 'should success for valid attributes' do
SEPA::CreditTransferTransaction.new(:bic => 'SPUEDE2UXXX', :service_level => 'SEPA').should be_schema_compatible('pain.001.002.03')
expect(SEPA::CreditTransferTransaction.new(:bic => 'SPUEDE2UXXX', :service_level => 'SEPA')).to be_schema_compatible('pain.001.002.03')
end

it 'should fail for invalid attributes' do
SEPA::CreditTransferTransaction.new(:bic => nil).should_not be_schema_compatible('pain.001.002.03')
SEPA::CreditTransferTransaction.new(:bic => 'SPUEDE2UXXX', :service_level => 'URGP').should_not be_schema_compatible('pain.001.002.03')
expect(SEPA::CreditTransferTransaction.new(:bic => nil)).not_to be_schema_compatible('pain.001.002.03')
expect(SEPA::CreditTransferTransaction.new(:bic => 'SPUEDE2UXXX', :service_level => 'URGP')).not_to be_schema_compatible('pain.001.002.03')
end
end
end

context 'Requested date' do
it 'should allow valid value' do
SEPA::CreditTransferTransaction.should accept(nil, Date.today, Date.today.next, Date.today + 2, for: :requested_date)
expect(SEPA::CreditTransferTransaction).to accept(nil, Date.today, Date.today.next, Date.today + 2, for: :requested_date)
end

it 'should not allow invalid value' do
SEPA::CreditTransferTransaction.should_not accept(Date.new(1995,12,21), Date.today - 1, for: :requested_date)
expect(SEPA::CreditTransferTransaction).not_to accept(Date.new(1995,12,21), Date.today - 1, for: :requested_date)
end
end
end
4 changes: 2 additions & 2 deletions spec/creditor_account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

describe :creditor_identifier do
it 'should accept valid value' do
SEPA::CreditorAccount.should accept('DE98ZZZ09999999999', 'AT12ZZZ00000000001', 'IT97ZZZA1B2C3D4E5F6G7H8', 'NL97ZZZ123456780001', 'FR12ZZZ123456', for: :creditor_identifier)
expect(SEPA::CreditorAccount).to accept('DE98ZZZ09999999999', 'AT12ZZZ00000000001', 'IT97ZZZA1B2C3D4E5F6G7H8', 'NL97ZZZ123456780001', 'FR12ZZZ123456', for: :creditor_identifier)
end

it 'should not accept invalid value' do
SEPA::CreditorAccount.should_not accept('', 'invalid', 'DE98ZZZ099999999990', 'DEAAAAAAAAAAAAAAAA', for: :creditor_identifier)
expect(SEPA::CreditorAccount).not_to accept('', 'invalid', 'DE98ZZZ099999999990', 'DEAAAAAAAAAAAAAAAA', for: :creditor_identifier)
end
end
end
Loading

0 comments on commit bdfc051

Please sign in to comment.