How to fix RSpec syntax for version 2.99?

I recently upgraded a Rails 4 application from RSpec 2.X to 2.99 and although Transpec is already running , some of my tests still fail.

require 'spec_helper'

describe Invoice, :type => :model do

  before :each do
    @user = FactoryGirl.create(:user)
    @invoice = FactoryGirl.create(:invoice, :user => @user)
  end

  it "is not open" do
    expect {
      FactoryGirl.create(:payment, :invoice => @invoice, :amount => 100)  
    }.to change{@invoice.reload.open?}.from(true).to(false)
  end

  it "is open" do
    expect {
      FactoryGirl.create(:payment, :invoice => @invoice, :amount => 99.99)  
    }.to_not change{@invoice.reload.open?}.to(false)
  end

end

The first test is the same as before the RSpec update.

The second test, however, raises an error:

Failure/Error: expect {
   `expect { }.not_to change { }.to()` is deprecated.

What should I change my syntax?

I have already tried a couple of things like not_to, be_falseyetc. So far, nothing has worked.

Thanks for any help.

+4
source share
1 answer

Do not claim that the value has not changed, just say that it does not change:

it "is open" do
  expect {
    FactoryGirl.create(:payment, :invoice => @invoice, :amount => 99.99)  
  }.to_not change { @invoice.reload.open? }
end

@invoice.reload.open?, . .

, RSpec 3 .from , , , , :

it "is open" do
  expect {
    FactoryGirl.create(:payment, :invoice => @invoice, :amount => 99.99)  
  }.to_not change { @invoice.reload.open? }.from(false)
end

RSpec 2; .to_not change {}.from , , .from, . RSpec 2.99, .

+9

Source: https://habr.com/ru/post/1544922/


All Articles