Skip to content

Commit

Permalink
refactor test by using let instead of before block when creating inst…
Browse files Browse the repository at this point in the history
…ance variables
  • Loading branch information
zaziemo authored and denschub committed Jul 16, 2015
1 parent 9b3ff1a commit abf8788
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions spec/models/aspect_membership_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@
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

Expand Down

0 comments on commit abf8788

Please sign in to comment.