Skip to content

Commit

Permalink
change rspec old should syntax to expect
Browse files Browse the repository at this point in the history
  • Loading branch information
mbulat committed Jul 10, 2017
1 parent 66f06fd commit b2dede4
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 56 deletions.
4 changes: 2 additions & 2 deletions spec/controllers/accounts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ def mock_account(stubs={})

describe "GET index" do
it "assigns all accounts as @accounts" do
Account.stub(:all).and_return([mock_account])
allow(Account).to receive(:all).and_return([mock_account])
get :index
assigns[:accounts].should == [mock_account]
expect(assigns[:accounts]).to eq([mock_account])
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/entries_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ def mock_entry(stubs={})

describe "GET index" do
it "assigns all entries as @entries" do
Entry.stub_chain(:per, :order).and_return([mock_entry])
allow(Entry).to receive_message_chain(:per, :order).and_return([mock_entry])
get :index
assigns[:entries].should == [mock_entry]
expect(assigns[:entries]).to eq([mock_entry])
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/reports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ def mock_entry(stubs={})

describe "GET balance_sheet" do
it "renders when one entry exists" do
Entry.stub_chain(:order).and_return([mock_entry])
allow(Entry).to receive_message_chain(:order).and_return([mock_entry])
get :balance_sheet
response.should be_success
expect(response).to be_success
end
it "renders when no entries exist" do
Entry.stub_chain(:order).and_return([])
allow(Entry).to receive_message_chain(:order).and_return([])
get :balance_sheet
response.should be_success
expect(response).to be_success
end
end
end
Expand Down
14 changes: 7 additions & 7 deletions spec/models/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ module Plutus
let(:account) { FactoryGirl.build(:account) }
subject { account }

it { should_not be_valid } # must construct a child type instead
it { is_expected.not_to be_valid } # must construct a child type instead

describe "when using a child type" do
let(:account) { FactoryGirl.create(:account, type: "Finance::Asset") }
it { should be_valid }
it { is_expected.to be_valid }

it "should be unique per name" do
conflict = FactoryGirl.build(:account, name: account.name, type: account.type)
conflict.should_not be_valid
conflict.errors[:name].should == ["has already been taken"]
expect(conflict).not_to be_valid
expect(conflict.errors[:name]).to eq(["has already been taken"])
end
end

Expand All @@ -28,10 +28,10 @@ module Plutus

describe ".trial_balance" do
subject { Account.trial_balance }
it { should be_kind_of BigDecimal }
it { is_expected.to be_kind_of BigDecimal }

context "when given no entries" do
it { should == 0 }
it { is_expected.to eq(0) }
end

context "when given correct entries" do
Expand Down Expand Up @@ -69,7 +69,7 @@ module Plutus
FactoryGirl.create(:entry, :credit_amounts => [ca5], :debit_amounts => [da5])
}

it { should == 0 }
it { is_expected.to eq(0) }
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/models/amount_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
module Plutus
describe Amount do
subject { FactoryGirl.build(:amount) }
it { should_not be_valid } # construct a child class instead
it { is_expected.not_to be_valid } # construct a child class instead
end
end
40 changes: 20 additions & 20 deletions spec/models/entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,43 @@ module Plutus
let(:entry) { FactoryGirl.build(:entry) }
subject { entry }

it { should_not be_valid }
it { is_expected.not_to be_valid }

context "with credit and debit" do
let(:entry) { FactoryGirl.build(:entry_with_credit_and_debit) }
it { should be_valid }
it { is_expected.to be_valid }

it "should require a description" do
entry.description = nil
entry.should_not be_valid
expect(entry).not_to be_valid
end
end

context "with a debit" do
before {
entry.debit_amounts << FactoryGirl.build(:debit_amount, entry: entry)
}
it { should_not be_valid }
it { is_expected.not_to be_valid }

context "with an invalid credit" do
before {
entry.credit_amounts << FactoryGirl.build(:credit_amount, entry: entry, amount: nil)
}
it { should_not be_valid }
it { is_expected.not_to be_valid }
end
end

context "with a credit" do
before {
entry.credit_amounts << FactoryGirl.build(:credit_amount, entry: entry)
}
it { should_not be_valid }
it { is_expected.not_to be_valid }

context "with an invalid debit" do
before {
entry.debit_amounts << FactoryGirl.build(:debit_amount, entry: entry, amount: nil)
}
it { should_not be_valid }
it { is_expected.not_to be_valid }
end
end

Expand All @@ -50,40 +50,40 @@ module Plutus

context "should assign a default date before being saved" do
before { entry.save! }
its(:date) { should == Time.now.to_date }
its(:date) { is_expected.to eq(Time.now.to_date) }
end
end

it "should require the debit and credit amounts to cancel" do
entry.credit_amounts << FactoryGirl.build(:credit_amount, :amount => 100, :entry => entry)
entry.debit_amounts << FactoryGirl.build(:debit_amount, :amount => 200, :entry => entry)
entry.should_not be_valid
entry.errors['base'].should == ["The credit and debit amounts are not equal"]
expect(entry).not_to be_valid
expect(entry.errors['base']).to eq(["The credit and debit amounts are not equal"])
end

it "should require the debit and credit amounts to cancel even with fractions" do
entry = FactoryGirl.build(:entry)
entry.credit_amounts << FactoryGirl.build(:credit_amount, :amount => 100.1, :entry => entry)
entry.debit_amounts << FactoryGirl.build(:debit_amount, :amount => 100.2, :entry => entry)
entry.should_not be_valid
entry.errors['base'].should == ["The credit and debit amounts are not equal"]
expect(entry).not_to be_valid
expect(entry.errors['base']).to eq(["The credit and debit amounts are not equal"])
end

it "should ignore debit and credit amounts marked for destruction to cancel" do
entry.credit_amounts << FactoryGirl.build(:credit_amount, :amount => 100, :entry => entry)
debit_amount = FactoryGirl.build(:debit_amount, :amount => 100, :entry => entry)
debit_amount.mark_for_destruction
entry.debit_amounts << debit_amount
entry.should_not be_valid
entry.errors['base'].should == ["The credit and debit amounts are not equal"]
expect(entry).not_to be_valid
expect(entry.errors['base']).to eq(["The credit and debit amounts are not equal"])
end

it "should have a polymorphic commercial document associations" do
mock_document = FactoryGirl.create(:asset) # one would never do this, but it allows us to not require a migration for the test
entry = FactoryGirl.build(:entry_with_credit_and_debit, commercial_document: mock_document)
entry.save!
saved_entry = Entry.find(entry.id)
saved_entry.commercial_document.should == mock_document
expect(saved_entry.commercial_document).to eq(mock_document)
end

context "given a set of accounts" do
Expand All @@ -93,13 +93,13 @@ module Plutus
let!(:sales_tax_payable) { FactoryGirl.create(:liability, name: "Sales Tax Payable") }

shared_examples_for 'a built-from-hash Plutus::Entry' do
its(:credit_amounts) { should_not be_empty }
its(:debit_amounts) { should_not be_empty }
it { should be_valid }
its(:credit_amounts) { is_expected.not_to be_empty }
its(:debit_amounts) { is_expected.not_to be_empty }
it { is_expected.to be_valid }

context "when saved" do
before { entry.save! }
its(:id) { should_not be_nil }
its(:id) { is_expected.not_to be_nil }

context "when reloaded" do
let(:saved_transaction) { Entry.find(entry.id) }
Expand Down Expand Up @@ -158,7 +158,7 @@ module Plutus

it("should be deprecated") {
# .build is the only thing deprecated
::ActiveSupport::Deprecation.should_receive(:warn).once
expect(::ActiveSupport::Deprecation).to receive(:warn).once
entry
}
end
Expand Down
6 changes: 3 additions & 3 deletions spec/models/tenancy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ module Plutus
account = FactoryGirl.create(:asset, tenant_id: 10)

record = FactoryGirl.build(:asset, name: account.name, tenant_id: 10)
record.should_not be_valid
record.errors[:name].should == ['has already been taken']
expect(record).not_to be_valid
expect(record.errors[:name]).to eq(['has already been taken'])
end

it 'allows same name scoped under a different tenant' do
account = FactoryGirl.create(:asset, tenant_id: 10)

record = FactoryGirl.build(:asset, name: account.name, tenant_id: 11)
record.should be_valid
expect(record).to be_valid
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/routing/accounts_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Plutus

describe "routing" do
it "recognizes and generates #index" do
{ :get => "/accounts" }.should route_to(:controller => "plutus/accounts", :action => "index")
expect(:get => "/accounts").to route_to(:controller => "plutus/accounts", :action => "index")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/routing/entries_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Plutus

describe "routing" do
it "recognizes and generates #index" do
{ :get => "/entries" }.should route_to(:controller => "plutus/entries", :action => "index")
expect(:get => "/entries").to route_to(:controller => "plutus/entries", :action => "index")
end
end
end
Expand Down
22 changes: 11 additions & 11 deletions spec/support/account_shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@

describe "class methods" do
subject { account.class }
its(:balance) { should be_kind_of(BigDecimal) }
its(:balance) { is_expected.to be_kind_of(BigDecimal) }
describe "trial_balance" do
it "should raise NoMethodError" do
lambda { subject.trial_balance }.should raise_error NoMethodError
expect { subject.trial_balance }.to raise_error NoMethodError
end
end
end

describe "instance methods" do
its(:balance) { should be_kind_of(BigDecimal) }
its(:balance) { is_expected.to be_kind_of(BigDecimal) }

it "reports a balance with date range" do
account.balance(:from_date => "2014-01-01", :to_date => Date.today).should be_kind_of(BigDecimal)
expect(account.balance(:from_date => "2014-01-01", :to_date => Date.today)).to be_kind_of(BigDecimal)
end

it { should respond_to(:credit_entries) }
it { should respond_to(:debit_entries) }
it { is_expected.to respond_to(:credit_entries) }
it { is_expected.to respond_to(:debit_entries) }
end

it "requires a name" do
account.name = nil
account.should_not be_valid
expect(account).not_to be_valid
end

# Figure out which way credits and debits should apply
Expand All @@ -40,21 +40,21 @@

describe "when given a debit" do
before { FactoryGirl.create(:debit_amount, account: account) }
its(:balance) { should be.send(debit_condition, 0) }
its(:balance) { is_expected.to be.send(debit_condition, 0) }

describe "on a contra account" do
let(:contra) { true }
its(:balance) { should be.send(credit_condition, 0) }
its(:balance) { is_expected.to be.send(credit_condition, 0) }
end
end

describe "when given a credit" do
before { FactoryGirl.create(:credit_amount, account: account) }
its(:balance) { should be.send(credit_condition, 0) }
its(:balance) { is_expected.to be.send(credit_condition, 0) }

describe "on a contra account" do
let(:contra) { true }
its(:balance) { should be.send(debit_condition, 0) }
its(:balance) { is_expected.to be.send(debit_condition, 0) }
end
end
end
8 changes: 4 additions & 4 deletions spec/support/amount_shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
let(:amount) { FactoryGirl.build(elements[:kind]) }
subject { amount }

it { should be_valid }
it { is_expected.to be_valid }

it "should require an amount" do
amount.amount = nil
amount.should_not be_valid
expect(amount).not_to be_valid
end

it "should require a entry" do
amount.entry = nil
amount.should_not be_valid
expect(amount).not_to be_valid
end

it "should require an account" do
amount.account = nil
amount.should_not be_valid
expect(amount).not_to be_valid
end
end

0 comments on commit b2dede4

Please sign in to comment.