refactor test by using let instead of before block when creating instance variables

This commit is contained in:
zaziemo 2015-07-13 11:35:15 +02:00 committed by Dennis Schubert
parent 9b3ff1a416
commit abf87889a0

View file

@ -7,25 +7,25 @@ require 'spec_helper'
describe AspectMembership, :type => :model do
describe '#before_destroy' do
before do
@aspect = alice.aspects.create(:name => "two")
@contact = alice.contact_for(bob.person)
let(:aspect) { alice.aspects.create(:name => "two") }
let(:contact) { alice.contact_for(bob.person) }
let(:am) { alice.aspects.where(:name => "generic").first.aspect_memberships.first }
@am = alice.aspects.where(:name => "generic").first.aspect_memberships.first
allow(@am).to receive(:user).and_return(alice)
before do
allow(am).to receive(:user).and_return(alice)
end
it 'calls disconnect if its the last aspect for the contact' do
expect(alice).to receive(:disconnect).with(@contact)
expect(alice).to receive(:disconnect).with(contact)
@am.destroy
am.destroy
end
it 'does not call disconnect if its not the last aspect for the contact' do
expect(alice).not_to receive(:disconnect)
alice.add_contact_to_aspect(@contact, @aspect)
@am.destroy
alice.add_contact_to_aspect(contact, aspect)
am.destroy
end
end