From abf87889a0235fa3bdd7cc5a1ee3c6b1471f07a5 Mon Sep 17 00:00:00 2001 From: zaziemo <maren.heltsche@gmail.com> Date: Mon, 13 Jul 2015 11:35:15 +0200 Subject: [PATCH] refactor test by using let instead of before block when creating instance variables --- spec/models/aspect_membership_spec.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/models/aspect_membership_spec.rb b/spec/models/aspect_membership_spec.rb index 12b01fe240..1f96946706 100644 --- a/spec/models/aspect_membership_spec.rb +++ b/spec/models/aspect_membership_spec.rb @@ -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 -- GitLab