lundi 20 février 2017

RSpec: Multiple asserts for a controller spec

Let me explain the issue...

I was testing a Rails controller with RSpec and I have one scenario with about 8 asserts..

I don't like to have an "it" with that amount of asserts so what I did was this:

RSpec.shared_examples 'successful payment' do |term_type, years|
  let(:surgeon_package) { assigns(:surgeon).reload.last_surgeon_package }
  let(:payment)         { surgeon_package.payments.first }

  before do
    put(:update_account, params)
  end

  it 'package term must be yearly' do
    expect(surgeon_package.payment_term.term).to eq(1)
    expect(surgeon_package.payment_term.term_type).to eq(term_type)
  end

  it 'package payments must be one' do
    expect(surgeon_package.payments.count).to eq(1)
  end

  it '...'
end

But as you can see I request the action :update_account on each it.

What do you think is the best way to solve this issue? since I don't want to request /update_account every time.

Global variables? $cache? get the code back to one "it" ? thoughts?

Thanks community

Aucun commentaire:

Enregistrer un commentaire