From b2dede496e0b8c3a966dd93109ab7c326848ce52 Mon Sep 17 00:00:00 2001 From: Michael Bulat Date: Mon, 10 Jul 2017 16:20:27 -0400 Subject: [PATCH] change rspec old should syntax to expect --- spec/controllers/accounts_controller_spec.rb | 4 +- spec/controllers/entries_controller_spec.rb | 4 +- spec/controllers/reports_controller_spec.rb | 8 ++-- spec/models/account_spec.rb | 14 +++---- spec/models/amount_spec.rb | 2 +- spec/models/entry_spec.rb | 40 ++++++++++---------- spec/models/tenancy_spec.rb | 6 +-- spec/routing/accounts_routing_spec.rb | 2 +- spec/routing/entries_routing_spec.rb | 2 +- spec/support/account_shared_examples.rb | 22 +++++------ spec/support/amount_shared_examples.rb | 8 ++-- 11 files changed, 56 insertions(+), 56 deletions(-) diff --git a/spec/controllers/accounts_controller_spec.rb b/spec/controllers/accounts_controller_spec.rb index 82fd510a..cf804adc 100644 --- a/spec/controllers/accounts_controller_spec.rb +++ b/spec/controllers/accounts_controller_spec.rb @@ -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 diff --git a/spec/controllers/entries_controller_spec.rb b/spec/controllers/entries_controller_spec.rb index 22a2be13..211a78c6 100644 --- a/spec/controllers/entries_controller_spec.rb +++ b/spec/controllers/entries_controller_spec.rb @@ -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 diff --git a/spec/controllers/reports_controller_spec.rb b/spec/controllers/reports_controller_spec.rb index 31b70f23..7d5eb10a 100644 --- a/spec/controllers/reports_controller_spec.rb +++ b/spec/controllers/reports_controller_spec.rb @@ -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 diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 6baee1b6..a8516df7 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -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 @@ -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 @@ -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 diff --git a/spec/models/amount_spec.rb b/spec/models/amount_spec.rb index 78fc55f8..79b9ae67 100644 --- a/spec/models/amount_spec.rb +++ b/spec/models/amount_spec.rb @@ -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 diff --git a/spec/models/entry_spec.rb b/spec/models/entry_spec.rb index 35fda29d..ef0912e2 100644 --- a/spec/models/entry_spec.rb +++ b/spec/models/entry_spec.rb @@ -5,15 +5,15 @@ 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 @@ -21,13 +21,13 @@ module Plutus 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 @@ -35,13 +35,13 @@ module Plutus 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 @@ -50,23 +50,23 @@ 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 @@ -74,8 +74,8 @@ module Plutus 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 @@ -83,7 +83,7 @@ module Plutus 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 @@ -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) } @@ -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 diff --git a/spec/models/tenancy_spec.rb b/spec/models/tenancy_spec.rb index 1d4fd2a8..c1359779 100644 --- a/spec/models/tenancy_spec.rb +++ b/spec/models/tenancy_spec.rb @@ -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 diff --git a/spec/routing/accounts_routing_spec.rb b/spec/routing/accounts_routing_spec.rb index d163c46b..bb16ef8e 100644 --- a/spec/routing/accounts_routing_spec.rb +++ b/spec/routing/accounts_routing_spec.rb @@ -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 diff --git a/spec/routing/entries_routing_spec.rb b/spec/routing/entries_routing_spec.rb index 3a13c44b..c468ab52 100644 --- a/spec/routing/entries_routing_spec.rb +++ b/spec/routing/entries_routing_spec.rb @@ -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 diff --git a/spec/support/account_shared_examples.rb b/spec/support/account_shared_examples.rb index f8f36544..4a720a64 100644 --- a/spec/support/account_shared_examples.rb +++ b/spec/support/account_shared_examples.rb @@ -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 @@ -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 diff --git a/spec/support/amount_shared_examples.rb b/spec/support/amount_shared_examples.rb index c4cc9bfb..536b5ff7 100644 --- a/spec/support/amount_shared_examples.rb +++ b/spec/support/amount_shared_examples.rb @@ -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