Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RSpec: The Bad Parts

Caleb Hearth
November 29, 2022

RSpec: The Bad Parts

RSpec is good, but it’s even better with less of it. Looking at a realistic example spec, we’ll learn why parts of RSpec like let, subject, shared_examples, behaves like, and before can make your tests hard to read, difficult to navigate, and more complex. We'll discuss when DRY is not worth the price and how we can avoid repetition without using RSpec's built-in DSL methods. In the end, we'll look at what's left. RSpec: The Good Parts.

Caleb Hearth

November 29, 2022
Tweet

More Decks by Caleb Hearth

Other Decks in Programming

Transcript

  1. Caleb Hearth dice.camp/@caleb calebhearth.com Test Double let(:player) { Dwarf.new }

    let(:party) { [player] } context "An elf" do let(:player) { Elf.new } end
  2. Caleb Hearth dice.camp/@caleb calebhearth.com Test Double it "has 10 pages"

    expect(Book.new.page_count) .to eq 10 end Book.new
  3. Caleb Hearth dice.camp/@caleb calebhearth.com Test Double it "has 10 pages"

    expect(Book.new.page_count) .to eq 10 end Book.new
  4. Caleb Hearth dice.camp/@caleb calebhearth.com Test Double it "has 10 pages"

    expect(Book.new.page_count) .to eq 10 end Book.new
  5. - The Pragmatic Programmer Every piece of knowledge must have

    a single, unambiguous, authoritative representation within a system “
  6. - The Pragmatic Programmer Every piece of knowledge must have

    a single, unambiguous, authoritative representation within a system “
  7. Caleb Hearth dice.club/@caleb calebhearth.com Test Double describe '#mute!' do subject

    { account.mute!(target_account, notifications: arg_notifications) } end context 'Mute does not exist yet' do context 'arg :notifications is nil' do let(:arg_notifications) { nil } it 'creates Mute, and returns Mute' do expect do expect(subject).to be_kind_of Mute end.to change { account.mute_relationships.count }.by 1 end end context 'arg :notifications is false' do let(:arg_notifications) { false } it 'creates Mute, and returns Mute' do expect do expect(subject).to be_kind_of Mute end.to change { account.mute_relationships.count }.by 1 end end context 'arg :notifications is true' do let(:arg_notifications) { true } it 'creates Mute, and returns Mute' do expect do expect(subject).to be_kind_of Mute end.to change { account.mute_relationships.count }.by 1 end end end context 'Mute already exists' do before do account.mute_relationships << mute end let(:mute) do Fabricate(:mute, account: account, target_account: target_account, hide_notifications: hide_notifications) end context 'mute.hide_notifications is true' do let(:hide_notifications) { true } context 'arg :notifications is nil' do let(:arg_notifications) { nil } it 'returns Mute without updating mute.hide_notifications' do expect do expect(subject).to be_kind_of Mute end.not_to change { mute.reload.hide_notifications? }.from(true) end end context 'arg :notifications is false' do let(:arg_notifications) { false } it 'returns Mute, and updates mute.hide_notifications false' do expect do expect(subject).to be_kind_of Mute end.to change { mute.reload.hide_notifications? }.from(true).to(false) end end context 'arg :notifications is true' do let(:arg_notifications) { true } it 'returns Mute without updating mute.hide_notifications' do expect do expect(subject).to be_kind_of Mute end.not_to change { mute.reload.hide_notifications? }.from(true) end end end context 'mute.hide_notifications is false' do let(:hide_notifications) { false } context 'arg :notifications is nil' do let(:arg_notifications) { nil } it 'returns Mute, and updates mute.hide_notifications true' do expect do expect(subject).to be_kind_of Mute end.to change { mute.reload.hide_notifications? }.from(false).to(true) end end context 'arg :notifications is false' do let(:arg_notifications) { false } it 'returns Mute without updating mute.hide_notifications' do expect do expect(subject).to be_kind_of Mute end.not_to change { mute.reload.hide_notifications? }.from(false) end end context 'arg :notifications is true' do let(:arg_notifications) { true } it 'returns Mute, and updates mute.hide_notifications true' do expect do expect(subject).to be_kind_of Mute end.to change { mute.reload.hide_notifications? }.from(false).to(true) end end end end
  8. Caleb Hearth dice.club/@caleb calebhearth.com Test Double describe '#mute!' do subject

    { account.mute!(target_account, notifications: arg_notifications) } end context 'Mute does not exist yet' do context 'arg :notifications is nil' do let(:arg_notifications) { nil } it 'creates Mute, and returns Mute' do expect do expect(subject).to be_kind_of Mute end.to change { account.mute_relationships.count }.by 1 end end context 'arg :notifications is false' do let(:arg_notifications) { false } it 'creates Mute, and returns Mute' do expect do expect(subject).to be_kind_of Mute end.to change { account.mute_relationships.count }.by 1 end end context 'arg :notifications is true' do let(:arg_notifications) { true } it 'creates Mute, and returns Mute' do expect do expect(subject).to be_kind_of Mute end.to change { account.mute_relationships.count }.by 1 end end end context 'Mute already exists' do before do account.mute_relationships << mute end let(:mute) do Fabricate(:mute, account: account, target_account: target_account, hide_notifications: hide_notifications) end context 'mute.hide_notifications is true' do let(:hide_notifications) { true } context 'arg :notifications is nil' do let(:arg_notifications) { nil } it 'returns Mute without updating mute.hide_notifications' do expect do expect(subject).to be_kind_of Mute end.not_to change { mute.reload.hide_notifications? }.from(true) end end context 'arg :notifications is false' do let(:arg_notifications) { false } it 'returns Mute, and updates mute.hide_notifications false' do expect do expect(subject).to be_kind_of Mute end.to change { mute.reload.hide_notifications? }.from(true).to(false) end end context 'arg :notifications is true' do let(:arg_notifications) { true } it 'returns Mute without updating mute.hide_notifications' do expect do expect(subject).to be_kind_of Mute end.not_to change { mute.reload.hide_notifications? }.from(true) end end end context 'mute.hide_notifications is false' do let(:hide_notifications) { false } context 'arg :notifications is nil' do let(:arg_notifications) { nil } it 'returns Mute, and updates mute.hide_notifications true' do expect do expect(subject).to be_kind_of Mute end.to change { mute.reload.hide_notifications? }.from(false).to(true) end end context 'arg :notifications is false' do let(:arg_notifications) { false } it 'returns Mute without updating mute.hide_notifications' do expect do expect(subject).to be_kind_of Mute end.not_to change { mute.reload.hide_notifications? }.from(false) end end context 'arg :notifications is true' do let(:arg_notifications) { true } it 'returns Mute, and updates mute.hide_notifications true' do expect do expect(subject).to be_kind_of Mute end.to change { mute.reload.hide_notifications? }.from(false).to(true) end end end end spec/models/concerns/account_interactions_spec.rb
  9. Caleb Hearth dice.club/@caleb calebhearth.com Test Double describe '#mute!' do subject

    { account.mute!(target_account, notifications: arg_notifications) } end context 'Mute does not exist yet' do context 'arg :notifications is nil' do let(:arg_notifications) { nil } it 'creates Mute, and returns Mute' do expect do expect(subject).to be_kind_of Mute end.to change { account.mute_relationships.count }.by 1 end end context 'arg :notifications is false' do let(:arg_notifications) { false } it 'creates Mute, and returns Mute' do expect do expect(subject).to be_kind_of Mute end.to change { account.mute_relationships.count }.by 1 end end context 'arg :notifications is true' do let(:arg_notifications) { true } it 'creates Mute, and returns Mute' do expect do expect(subject).to be_kind_of Mute end.to change { account.mute_relationships.count }.by 1 end end end context 'Mute already exists' do before do account.mute_relationships << mute end let(:mute) do Fabricate(:mute, account: account, target_account: target_account, hide_notifications: hide_notifications) end context 'mute.hide_notifications is true' do let(:hide_notifications) { true } context 'arg :notifications is nil' do let(:arg_notifications) { nil } it 'returns Mute without updating mute.hide_notifications' do expect do expect(subject).to be_kind_of Mute end.not_to change { mute.reload.hide_notifications? }.from(true) end end context 'arg :notifications is false' do let(:arg_notifications) { false } it 'returns Mute, and updates mute.hide_notifications false' do expect do expect(subject).to be_kind_of Mute end.to change { mute.reload.hide_notifications? }.from(true).to(false) end end context 'arg :notifications is true' do let(:arg_notifications) { true } it 'returns Mute without updating mute.hide_notifications' do expect do expect(subject).to be_kind_of Mute end.not_to change { mute.reload.hide_notifications? }.from(true) end end end context 'mute.hide_notifications is false' do let(:hide_notifications) { false } context 'arg :notifications is nil' do let(:arg_notifications) { nil } it 'returns Mute, and updates mute.hide_notifications true' do expect do expect(subject).to be_kind_of Mute end.to change { mute.reload.hide_notifications? }.from(false).to(true) end end context 'arg :notifications is false' do let(:arg_notifications) { false } it 'returns Mute without updating mute.hide_notifications' do expect do expect(subject).to be_kind_of Mute end.not_to change { mute.reload.hide_notifications? }.from(false) end end context 'arg :notifications is true' do let(:arg_notifications) { true } it 'returns Mute, and updates mute.hide_notifications true' do expect do expect(subject).to be_kind_of Mute end.to change { mute.reload.hide_notifications? }.from(false).to(true) end end end end spec/models/concerns/account_interactions_spec.rb
  10. Caleb Hearth dice.club/@caleb calebhearth.com Test Double describe '#mute!' do subject

    { account.mute!(target_account, notifications: arg_notifications) } end context 'Mute does not exist yet' do context 'arg :notifications is nil' do let(:arg_notifications) { nil } it 'creates Mute, and returns Mute' do expect do expect(subject).to be_kind_of Mute end.to change { account.mute_relationships.count }.by 1 end end context 'arg :notifications is false' do let(:arg_notifications) { false } it 'creates Mute, and returns Mute' do expect do expect(subject).to be_kind_of Mute end.to change { account.mute_relationships.count }.by 1 end end context 'arg :notifications is true' do let(:arg_notifications) { true } it 'creates Mute, and returns Mute' do expect do expect(subject).to be_kind_of Mute end.to change { account.mute_relationships.count }.by 1 end end end context 'Mute already exists' do before do account.mute_relationships << mute end let(:mute) do Fabricate(:mute, account: account, target_account: target_account, hide_notifications: hide_notifications) end context 'mute.hide_notifications is true' do let(:hide_notifications) { true } context 'arg :notifications is nil' do let(:arg_notifications) { nil } it 'returns Mute without updating mute.hide_notifications' do expect do expect(subject).to be_kind_of Mute end.not_to change { mute.reload.hide_notifications? }.from(true) end end context 'arg :notifications is false' do let(:arg_notifications) { false } it 'returns Mute, and updates mute.hide_notifications false' do expect do expect(subject).to be_kind_of Mute end.to change { mute.reload.hide_notifications? }.from(true).to(false) end end context 'arg :notifications is true' do let(:arg_notifications) { true } it 'returns Mute without updating mute.hide_notifications' do expect do expect(subject).to be_kind_of Mute end.not_to change { mute.reload.hide_notifications? }.from(true) end end end context 'mute.hide_notifications is false' do let(:hide_notifications) { false } context 'arg :notifications is nil' do let(:arg_notifications) { nil } it 'returns Mute, and updates mute.hide_notifications true' do expect do expect(subject).to be_kind_of Mute end.to change { mute.reload.hide_notifications? }.from(false).to(true) end end context 'arg :notifications is false' do let(:arg_notifications) { false } it 'returns Mute without updating mute.hide_notifications' do expect do expect(subject).to be_kind_of Mute end.not_to change { mute.reload.hide_notifications? }.from(false) end end context 'arg :notifications is true' do let(:arg_notifications) { true } it 'returns Mute, and updates mute.hide_notifications true' do expect do expect(subject).to be_kind_of Mute end.to change { mute.reload.hide_notifications? }.from(false).to(true) end end end end
  11. Caleb Hearth dice.club/@caleb calebhearth.com Test Double describe '#mute!' do end

    context 'Mute does not exist yet' do context 'arg :notifications is nil' do let(:arg_notifications) { nil } it 'creates Mute, and returns Mute' do expect do mute = account.mute!(target_account, notifications: arg_notifications) expect(mute).to be_kind_of Mute end.to change { account.mute_relationships.count }.by 1 end end context 'arg :notifications is false' do let(:arg_notifications) { false } it 'creates Mute, and returns Mute' do expect do mute = account.mute!(target_account, notifications: arg_notifications) expect(mute).to be_kind_of Mute end.to change { account.mute_relationships.count }.by 1 end end context 'arg :notifications is true' do let(:arg_notifications) { true } it 'creates Mute, and returns Mute' do expect do mute = account.mute!(target_account, notifications: arg_notifications) expect(mute).to be_kind_of Mute end.to change { account.mute_relationships.count }.by 1 end end end context 'Mute already exists' do before do account.mute_relationships << mute end let(:mute) do Fabricate(:mute, account: account, target_account: target_account, hide_notifications: hide_notifications) end context 'mute.hide_notifications is true' do let(:hide_notifications) { true } context 'arg :notifications is nil' do let(:arg_notifications) { nil } it 'returns Mute without updating mute.hide_notifications' do expect do mute = account.mute!(target_account, notifications: arg_notifications) expect(mute).to be_kind_of Mute end.not_to change { mute.reload.hide_notifications? }.from(true) end end context 'arg :notifications is false' do let(:arg_notifications) { false } it 'returns Mute, and updates mute.hide_notifications false' do expect do mute = account.mute!(target_account, notifications: arg_notifications) expect(mute).to be_kind_of Mute end.to change { mute.reload.hide_notifications? }.from(true).to(false) end end context 'arg :notifications is true' do let(:arg_notifications) { true } it 'returns Mute without updating mute.hide_notifications' do expect do mute = account.mute!(target_account, notifications: arg_notifications) expect(mute).to be_kind_of Mute end.not_to change { mute.reload.hide_notifications? }.from(true) end end end context 'mute.hide_notifications is false' do let(:hide_notifications) { false } context 'arg :notifications is nil' do let(:arg_notifications) { nil } it 'returns Mute, and updates mute.hide_notifications true' do expect do mute = account.mute!(target_account, notifications: arg_notifications) expect(mute).to be_kind_of Mute end.to change { mute.reload.hide_notifications? }.from(false).to(true) end end context 'arg :notifications is false' do let(:arg_notifications) { false } it 'returns Mute without updating mute.hide_notifications' do expect do mute = account.mute!(target_account, notifications: arg_notifications) expect(mute).to be_kind_of Mute end.not_to change { mute.reload.hide_notifications? }.from(false) end end context 'arg :notifications is true' do let(:arg_notifications) { true } it 'returns Mute, and updates mute.hide_notifications true' do expect do mute = account.mute!(target_account, notifications: arg_notifications) expect(mute).to be_kind_of Mute end.to change { mute.reload.hide_notifications? }.from(false).to(true) end end end end
  12. Caleb Hearth dice.club/@caleb calebhearth.com Test Double describe '#mute!' do end

    context 'Mute already exists' do before do account.mute_relationships << mute end let(:mute) do Fabricate(:mute, account: account, target_account: target_account, hide_notifications: hide_notifications) end context 'mute.hide_notifications is true' do let(:hide_notifications) { true } context 'arg :notifications is nil' do let(:arg_notifications) { nil } it 'returns Mute without updating mute.hide_notifications' do expect do mute = account.mute!(target_account, notifications: arg_notifications) expect(mute).to be_kind_of Mute end.not_to change { mute.reload.hide_notifications? }.from(true) end end context 'arg :notifications is false' do let(:arg_notifications) { false } it 'returns Mute, and updates mute.hide_notifications false' do expect do mute = account.mute!(target_account, notifications: arg_notifications) expect(mute).to be_kind_of Mute end.to change { mute.reload.hide_notifications? }.from(true).to(false) end end context 'arg :notifications is true' do let(:arg_notifications) { true } it 'returns Mute without updating mute.hide_notifications' do expect do mute = account.mute!(target_account, notifications: arg_notifications) expect(mute).to be_kind_of Mute end.not_to change { mute.reload.hide_notifications? }.from(true) end end end
  13. Caleb Hearth dice.club/@caleb calebhearth.com Test Double describe '#mute!' do end

    context 'arg :notifications is false' do let(:arg_notifications) { false } it 'returns Mute, and updates mute.hide_notifications false' do expect do mute = account.mute!(target_account, notifications: arg_notifications) expect(mute).to be_kind_of Mute end.to change { mute.reload.hide_notifications? }.from(true).to(false) end end
  14. Caleb Hearth dice.club/@caleb calebhearth.com Test Double describe '#mute!' do end

    context 'arg :notifications is false' do let(:arg_notifications) { false } it 'returns Mute, and updates mute.hide_notifications false' do expect do mute = account.mute!(target_account, notifications: arg_notifications) expect(mute).to be_kind_of Mute end.to change { mute.reload.hide_notifications? }.from(true).to(false) end end
  15. Caleb Hearth dice.club/@caleb calebhearth.com Test Double describe '#mute!' do end

    context 'arg :notifications is false' do let(:arg_notifications) { false } it 'returns Mute, and updates mute.hide_notifications false' do expect do mute = account.mute!(target_account, notifications: arg_notifications) expect(mute).to be_kind_of Mute end.to change { mute.reload.hide_notifications? }.from(true).to(false) end end
  16. Caleb Hearth dice.club/@caleb calebhearth.com Test Double describe '#mute!' do end

    context 'arg :notifications is false' do let(:arg_notifications) { false } it 'returns Mute, and updates mute.hide_notifications false' do expect do account.mute!(target_account, notifications: arg_notifications) end.to change { mute.reload.hide_notifications? }.from(true).to(false) end end
  17. Caleb Hearth dice.club/@caleb calebhearth.com Test Double describe '#mute!' do end

    context 'Mute does not exist yet' do context 'arg :notifications is nil' do let(:arg_notifications) { nil } it 'returns a Mute' do expect(account.mute!(target_account, notifications: arg_notifications)) .to be_kind_of Mute end it 'creates a Mute' do expect do account.mute!(target_account, notifications: arg_notifications) end.to change { account.mute_relationships.count }.by 1 end end context 'arg :notifications is false' do let(:arg_notifications) { false } it 'creates a Mute' do expect do account.mute!(target_account, notifications: arg_notifications) end.to change { account.mute_relationships.count }.by 1 end end context 'arg :notifications is true' do let(:arg_notifications) { true } it 'creates a Mute' do expect do account.mute!(target_account, notifications: arg_notifications) end.to change { account.mute_relationships.count }.by 1 end end end context 'Mute already exists' do before do account.mute_relationships << mute end let(:mute) do Fabricate(:mute, account: account, target_account: target_account, hide_notifications: hide_notifications) end context 'mute.hide_notifications is true' do let(:hide_notifications) { true } context 'arg :notifications is nil' do let(:arg_notifications) { nil } it 'does not update mute.hide_notifications' do expect do account.mute!(target_account, notifications: arg_notifications) end.not_to change { mute.reload.hide_notifications? }.from(true) end end context 'arg :notifications is false' do let(:arg_notifications) { false } it 'updates mute.hide_notifications false' do expect do account.mute!(target_account, notifications: arg_notifications) end.to change { mute.reload.hide_notifications? }.from(true).to(false) end end context 'arg :notifications is true' do let(:arg_notifications) { true } it 'does not update mute.hide_notifications' do expect do account.mute!(target_account, notifications: arg_notifications) end.not_to change { mute.reload.hide_notifications? }.from(true) end end end context 'mute.hide_notifications is false' do let(:hide_notifications) { false } context 'arg :notifications is nil' do let(:arg_notifications) { nil } it 'updates mute.hide_notifications true' do expect do account.mute!(target_account, notifications: arg_notifications) end.to change { mute.reload.hide_notifications? }.from(false).to(true) end end context 'arg :notifications is false' do let(:arg_notifications) { false } it 'does not update mute.hide_notifications' do expect do account.mute!(target_account, notifications: arg_notifications) end.not_to change { mute.reload.hide_notifications? }.from(false) end end context 'arg :notifications is true' do let(:arg_notifications) { true } it 'updates mute.hide_notifications true' do expect do account.mute!(target_account, notifications: arg_notifications) end.to change { mute.reload.hide_notifications? }.from(false).to(true) end end end end
  18. Caleb Hearth dice.club/@caleb calebhearth.com Test Double describe '#mute!' do end

    context 'Mute does not exist yet' do context 'arg :notifications is nil' do let(:arg_notifications) { nil } it 'returns a Mute' do expect(account.mute!(target_account, notifications: arg_notifications)) .to be_kind_of Mute end it 'creates a Mute' do expect do account.mute!(target_account, notifications: arg_notifications) end.to change { account.mute_relationships.count }.by 1 end end context 'arg :notifications is false' do let(:arg_notifications) { false } it 'creates a Mute' do expect do account.mute!(target_account, notifications: arg_notifications) end.to change { account.mute_relationships.count }.by 1 end end context 'arg :notifications is true' do let(:arg_notifications) { true } it 'creates a Mute' do expect do account.mute!(target_account, notifications: arg_notifications) end.to change { account.mute_relationships.count }.by 1 end end end context 'Mute already exists' do before do account.mute_relationships << mute end let(:mute) do Fabricate(:mute, account: account, target_account: target_account, hide_notifications: true) end context 'mute.hide_notifications is true' do let(:hide_notifications) { true } context 'arg :notifications is nil' do let(:arg_notifications) { nil } it 'does not update mute.hide_notifications' do expect do account.mute!(target_account, notifications: arg_notifications) end.not_to change { mute.reload.hide_notifications? }.from(true) end end context 'arg :notifications is false' do let(:arg_notifications) { false } it 'updates mute.hide_notifications false' do expect do account.mute!(target_account, notifications: arg_notifications) end.to change { mute.reload.hide_notifications? }.from(true).to(false) end end context 'arg :notifications is true' do let(:arg_notifications) { true } it 'does not update mute.hide_notifications' do expect do account.mute!(target_account, notifications: arg_notifications) end.not_to change { mute.reload.hide_notifications? }.from(true) end end end context 'mute.hide_notifications is false' do let(:hide_notifications) { false } context 'arg :notifications is nil' do let(:arg_notifications) { nil } it 'updates mute.hide_notifications true' do expect do account.mute!(target_account, notifications: arg_notifications) end.to change { mute.reload.hide_notifications? }.from(false).to(true) end end context 'arg :notifications is false' do let(:arg_notifications) { false } it 'does not update mute.hide_notifications' do expect do account.mute!(target_account, notifications: arg_notifications) end.not_to change { mute.reload.hide_notifications? }.from(false) end end context 'arg :notifications is true' do let(:arg_notifications) { true } it 'updates mute.hide_notifications true' do expect do account.mute!(target_account, notifications: arg_notifications) end.to change { mute.reload.hide_notifications? }.from(false).to(true) end end end end
  19. Caleb Hearth dice.club/@caleb calebhearth.com Test Double describe '#mute!' do end

    context 'Mute does not exist yet' do context 'arg :notifications is nil' do it 'returns a Mute' do expect(account.mute!(target_account, notifications: nil)) .to be_kind_of Mute end it 'creates a Mute' do expect do account.mute!(target_account, notifications: nil) end.to change { account.mute_relationships.count }.by 1 end end context 'arg :notifications is false' do it 'creates a Mute' do expect do account.mute!(target_account, notifications: false) end.to change { account.mute_relationships.count }.by 1 end end context 'arg :notifications is true' do it 'creates a Mute' do expect do account.mute!(target_account, notifications: true) end.to change { account.mute_relationships.count }.by 1 end end end context 'Mute already exists' do before do account.mute_relationships << mute end let(:mute) do Fabricate(:mute, account: account, target_account: target_account, hide_notifications: true) end context 'mute.hide_notifications is true' do context 'arg :notifications is nil' do it 'does not update mute.hide_notifications' do expect do account.mute!(target_account, notifications: nil) end.not_to change { mute.reload.hide_notifications? }.from(true) end end context 'arg :notifications is false' do it 'updates mute.hide_notifications false' do expect do account.mute!(target_account, notifications: false) end.to change { mute.reload.hide_notifications? }.from(true).to(false) end end context 'arg :notifications is true' do it 'does not update mute.hide_notifications' do expect do account.mute!(target_account, notifications: true) end.not_to change { mute.reload.hide_notifications? }.from(true) end end end context 'mute.hide_notifications is false' do context 'arg :notifications is nil' do it 'updates mute.hide_notifications true' do expect do account.mute!(target_account, notifications: nil) end.to change { mute.reload.hide_notifications? }.from(false).to(true) end end context 'arg :notifications is false' do it 'does not update mute.hide_notifications' do expect do account.mute!(target_account, notifications: false) end.not_to change { mute.reload.hide_notifications? }.from(false) end end context 'arg :notifications is true' do it 'updates mute.hide_notifications true' do expect do account.mute!(target_account, notifications: true) end.to change { mute.reload.hide_notifications? }.from(false).to(true) end end end end
  20. Caleb Hearth dice.club/@caleb calebhearth.com Test Double describe '#mute!' do end

    context 'Mute does not exist yet' do context 'arg :notifications is nil' do it 'returns a Mute' do expect(account.mute!(target_account, notifications: nil)) .to be_kind_of Mute end it 'creates a Mute' do expect do account.mute!(target_account, notifications: nil) end.to change { account.mute_relationships.count }.by 1 end end context 'arg :notifications is false' do it 'creates a Mute' do expect do account.mute!(target_account, notifications: false) end.to change { account.mute_relationships.count }.by 1 end end context 'arg :notifications is true' do it 'creates a Mute' do expect do account.mute!(target_account, notifications: true) end.to change { account.mute_relationships.count }.by 1 end end end context 'Mute already exists' do before do account.mute_relationships << mute end let(:mute) do Fabricate(:mute, account: account, target_account: target_account, hide_notifications: true) end context 'mute.hide_notifications is true' do context 'arg :notifications is nil' do it 'does not update mute.hide_notifications' do expect do account.mute!(target_account, notifications: nil) end.not_to change { mute.reload.hide_notifications? }.from(true) end end context 'arg :notifications is false' do it 'updates mute.hide_notifications false' do expect do account.mute!(target_account, notifications: false) end.to change { mute.reload.hide_notifications? }.from(true).to(false) end end context 'arg :notifications is true' do it 'does not update mute.hide_notifications' do expect do account.mute!(target_account, notifications: true) end.not_to change { mute.reload.hide_notifications? }.from(true) end end end context 'mute.hide_notifications is false' do context 'arg :notifications is nil' do it 'updates mute.hide_notifications true' do expect do account.mute!(target_account, notifications: nil) end.to change { mute.reload.hide_notifications? }.from(false).to(true) end end context 'arg :notifications is false' do it 'does not update mute.hide_notifications' do expect do account.mute!(target_account, notifications: false) end.not_to change { mute.reload.hide_notifications? }.from(false) end end context 'arg :notifications is true' do it 'updates mute.hide_notifications true' do expect do account.mute!(target_account, notifications: true) end.to change { mute.reload.hide_notifications? }.from(false).to(true) end end end end
  21. Caleb Hearth dice.club/@caleb calebhearth.com Test Double describe '#mute!' do end

    context 'Mute does not exist yet' do it 'returns a Mute' do expect(account.mute!(target_account)) .to be_kind_of Mute end it 'creates a Mute when :notifications is nil' do expect do account.mute!(target_account, notifications: nil) end.to change { account.mute_relationships.count }.by 1 end it 'creates a Mute when :notifications is false' do expect do account.mute!(target_account, notifications: false) end.to change { account.mute_relationships.count }.by 1 end it 'creates a Mute when :notifications is true' do expect do account.mute!(target_account, notifications: true) end.to change { account.mute_relationships.count }.by 1 end end context 'Mute already exists' do before do account.mute_relationships << mute end let(:mute) do Fabricate(:mute, account: account, target_account: target_account, hide_notifications: true) end context 'mute.hide_notifications is true' do it 'does not update mute.hide_notifications when :notifications is nil' do expect do account.mute!(target_account, notifications: nil) end.not_to change { mute.reload.hide_notifications? }.from(true) end it 'updates mute.hide_notifications false when :notifications is false' do expect do account.mute!(target_account, notifications: false) end.to change { mute.reload.hide_notifications? }.from(true).to(false) end it 'doesnt update mute.hide_notifications false when :notifications=true' do expect do account.mute!(target_account, notifications: true) end.not_to change { mute.reload.hide_notifications? }.from(true) end end context 'mute.hide_notifications is false' do it 'updates mute.hide_notifications true when arg :notifications is nil' do expect do account.mute!(target_account, notifications: nil) end.to change { mute.reload.hide_notifications? }.from(false).to(true) end it 'doesnt update mute.hide_notifications when arg :notifications is false' do expect do account.mute!(target_account, notifications: false) end.not_to change { mute.reload.hide_notifications? }.from(false) end it 'updates mute.hide_notifications true when arg :notifications is true' do expect do account.mute!(target_account, notifications: true) end.to change { mute.reload.hide_notifications? }.from(false).to(true) end end end
  22. Caleb Hearth dice.club/@caleb calebhearth.com Test Double describe '#mute!' do end

    context 'Mute does not exist yet' do it 'returns a Mute' do expect(account.mute!(target_account)) .to be_kind_of Mute end it 'creates a Mute when :notifications is nil' do expect do account.mute!(target_account, notifications: nil) end.to change { account.mute_relationships.count }.by 1 end it 'creates a Mute when :notifications is false' do expect do account.mute!(target_account, notifications: false) end.to change { account.mute_relationships.count }.by 1 end it 'creates a Mute when :notifications is true' do expect do account.mute!(target_account, notifications: true) end.to change { account.mute_relationships.count }.by 1 end end context 'Mute already exists' do before do account.mute_relationships << mute end let(:mute) do Fabricate(:mute, account: account, target_account: target_account, hide_notifications: true) end context 'mute.hide_notifications is true' do it 'does not update mute.hide_notifications when :notifications is nil' do expect do account.mute!(target_account, notifications: nil) end.not_to change { mute.reload.hide_notifications? }.from(true) end it 'updates mute.hide_notifications false when :notifications is false' do expect do account.mute!(target_account, notifications: false) end.to change { mute.reload.hide_notifications? }.from(true).to(false) end it 'doesnt update mute.hide_notifications false when :notifications=true' do expect do account.mute!(target_account, notifications: true) end.not_to change { mute.reload.hide_notifications? }.from(true) end end context 'mute.hide_notifications is false' do it 'updates mute.hide_notifications true when arg :notifications is nil' do expect do account.mute!(target_account, notifications: nil) end.to change { mute.reload.hide_notifications? }.from(false).to(true) end it 'doesnt update mute.hide_notifications when arg :notifications is false' do expect do account.mute!(target_account, notifications: false) end.not_to change { mute.reload.hide_notifications? }.from(false) end it 'updates mute.hide_notifications true when arg :notifications is true' do expect do account.mute!(target_account, notifications: true) end.to change { mute.reload.hide_notifications? }.from(false).to(true) end end end
  23. Caleb Hearth dice.club/@caleb calebhearth.com Test Double describe '#mute!' do end

    context 'Mute does not exist yet' do it 'returns a Mute' do expect(account.mute!(target_account)) .to be_kind_of Mute end it 'creates a Mute when :notifications is nil' do expect do account.mute!(target_account, notifications: nil) end.to change { account.mute_relationships.count }.by 1 end it 'creates a Mute when :notifications is false' do expect do account.mute!(target_account, notifications: false) end.to change { account.mute_relationships.count }.by 1 end it 'creates a Mute when :notifications is true' do expect do account.mute!(target_account, notifications: true) end.to change { account.mute_relationships.count }.by 1 end end context 'Mute already exists' do before do account.mute_relationships << mute end let(:mute) do Fabricate(:mute, account: account, target_account: target_account, hide_notifications: true) end context 'mute.hide_notifications is true' do it 'does not update mute.hide_notifications when :notifications is nil' do expect do account.mute!(target_account, notifications: nil) end.not_to change { mute.reload.hide_notifications? }.from(true) end it 'updates mute.hide_notifications false when :notifications is false' do expect do account.mute!(target_account, notifications: false) end.to change { mute.reload.hide_notifications? }.from(true).to(false) end it 'doesnt update mute.hide_notifications false when :notifications=true' do expect do account.mute!(target_account, notifications: true) end.not_to change { mute.reload.hide_notifications? }.from(true) end end context 'mute.hide_notifications is false' do it 'updates mute.hide_notifications true when arg :notifications is nil' do expect do account.mute!(target_account, notifications: nil) end.to change { mute.reload.hide_notifications? }.from(false).to(true) end it 'doesnt update mute.hide_notifications when arg :notifications is false' do expect do account.mute!(target_account, notifications: false) end.not_to change { mute.reload.hide_notifications? }.from(false) end it 'updates mute.hide_notifications true when arg :notifications is true' do expect do account.mute!(target_account, notifications: true) end.to change { mute.reload.hide_notifications? }.from(false).to(true) end end end
  24. Caleb Hearth dice.club/@caleb calebhearth.com Test Double describe '#mute!' do end

    context 'Mute does not exist yet' do it 'returns a Mute' do expect(account.mute!(target_account)) .to be_kind_of Mute end it 'creates a Mute when :notifications is nil' do expect do account.mute!(target_account, notifications: nil) end.to change { account.mute_relationships.count }.by 1 end it 'creates a Mute when :notifications is false' do expect do account.mute!(target_account, notifications: false) end.to change { account.mute_relationships.count }.by 1 end it 'creates a Mute when :notifications is true' do expect do account.mute!(target_account, notifications: true) end.to change { account.mute_relationships.count }.by 1 end end context 'Mute already exists' do context 'mute.hide_notifications is true' do it 'does not update mute.hide_notifications when :notifications is nil' do mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: true account.mute_relationships << mute expect do account.mute!(target_account, notifications: nil) end.not_to change { mute.reload.hide_notifications? }.from(true) end it 'updates mute.hide_notifications false when :notifications is false' do mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: true account.mute_relationships << mute expect do account.mute!(target_account, notifications: false) end.to change { mute.reload.hide_notifications? }.from(true).to(false) end it 'doesnt update mute.hide_notifications false when :notifications=true' do mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: true account.mute_relationships << mute expect do account.mute!(target_account, notifications: true) end.not_to change { mute.reload.hide_notifications? }.from(true) end end context 'mute.hide_notifications is false' do it 'updates mute.hide_notifications true when arg :notifications is nil' do mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: false account.mute_relationships << mute expect do account.mute!(target_account, notifications: nil) end.to change { mute.reload.hide_notifications? }.from(false).to(true) end it 'doesnt update mute.hide_notifications when arg :notifications is false' do mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: false account.mute_relationships << mute expect do account.mute!(target_account, notifications: false) end.not_to change { mute.reload.hide_notifications? }.from(false) end it 'updates mute.hide_notifications true when arg :notifications is true' do mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: false account.mute_relationships << mute expect do account.mute!(target_account, notifications: true) end.to change { mute.reload.hide_notifications? }.from(false).to(true) end end end
  25. Caleb Hearth dice.club/@caleb calebhearth.com Test Double describe '#mute!' do end

    context 'Mute does not exist yet' do it 'returns a Mute' do expect(account.mute!(target_account)) .to be_kind_of Mute end it 'creates a Mute when :notifications is nil' do expect do account.mute!(target_account, notifications: nil) end.to change { account.mute_relationships.count }.by 1 end it 'creates a Mute when :notifications is false' do expect do account.mute!(target_account, notifications: false) end.to change { account.mute_relationships.count }.by 1 end it 'creates a Mute when :notifications is true' do expect do account.mute!(target_account, notifications: true) end.to change { account.mute_relationships.count }.by 1 end end context 'Mute already exists' do context 'mute.hide_notifications is true' do it 'does not update mute.hide_notifications when :notifications is nil' do mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: true account.mute_relationships << mute expect do account.mute!(target_account, notifications: nil) end.not_to change { mute.reload.hide_notifications? }.from(true) end it 'updates mute.hide_notifications false when :notifications is false' do mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: true account.mute_relationships << mute expect do account.mute!(target_account, notifications: false) end.to change { mute.reload.hide_notifications? }.from(true).to(false) end it 'doesnt update mute.hide_notifications false when :notifications=true' do mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: true account.mute_relationships << mute expect do account.mute!(target_account, notifications: true) end.not_to change { mute.reload.hide_notifications? }.from(true) end end context 'mute.hide_notifications is false' do it 'updates mute.hide_notifications true when arg :notifications is nil' do mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: false account.mute_relationships << mute expect do account.mute!(target_account, notifications: nil) end.to change { mute.reload.hide_notifications? }.from(false).to(true) end it 'doesnt update mute.hide_notifications when arg :notifications is false' do mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: false account.mute_relationships << mute expect do account.mute!(target_account, notifications: false) end.not_to change { mute.reload.hide_notifications? }.from(false) end it 'updates mute.hide_notifications true when arg :notifications is true' do mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: false account.mute_relationships << mute expect do account.mute!(target_account, notifications: true) end.to change { mute.reload.hide_notifications? }.from(false).to(true) end end end
  26. Caleb Hearth dice.club/@caleb calebhearth.com Test Double describe '#mute!' do end

    context 'Mute does not exist yet' do it 'returns a Mute' do expect(account.mute!(target_account)) .to be_kind_of Mute end it 'creates a Mute when :notifications is nil' do expect do account.mute!(target_account, notifications: nil) end.to change { account.mute_relationships.count }.by 1 end it 'creates a Mute when :notifications is false' do expect do account.mute!(target_account, notifications: false) end.to change { account.mute_relationships.count }.by 1 end it 'creates a Mute when :notifications is true' do expect do account.mute!(target_account, notifications: true) end.to change { account.mute_relationships.count }.by 1 end end context 'Mute already exists' do context 'mute.hide_notifications is true' do it 'does not update mute.hide_notifications when :notifications is nil' do mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: true account.mute_relationships << mute expect do account.mute!(target_account, notifications: nil) end.not_to change { mute.reload.hide_notifications? }.from(true) end it 'updates mute.hide_notifications false when :notifications is false' do mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: true account.mute_relationships << mute expect do account.mute!(target_account, notifications: false) end.to change { mute.reload.hide_notifications? }.from(true).to(false) end it 'doesnt update mute.hide_notifications false when :notifications=true' do mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: true account.mute_relationships << mute expect do account.mute!(target_account, notifications: true) end.not_to change { mute.reload.hide_notifications? }.from(true) end end context 'mute.hide_notifications is false' do it 'updates mute.hide_notifications true when arg :notifications is nil' do mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: false account.mute_relationships << mute expect do account.mute!(target_account, notifications: nil) end.to change { mute.reload.hide_notifications? }.from(false).to(true) end it 'doesnt update mute.hide_notifications when arg :notifications is false' do mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: false account.mute_relationships << mute expect do account.mute!(target_account, notifications: false) end.not_to change { mute.reload.hide_notifications? }.from(false) end it 'updates mute.hide_notifications true when arg :notifications is true' do mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: false account.mute_relationships << mute expect do account.mute!(target_account, notifications: true) end.to change { mute.reload.hide_notifications? }.from(false).to(true) end end end
  27. Caleb Hearth dice.club/@caleb calebhearth.com Test Double describe '#mute!' do end

    context 'Mute does not exist yet' do it 'returns a Mute' do expect(Fabricate(:account).mute!(Fabricate(:account))) .to be_kind_of Mute end it 'creates a Mute when :notifications is nil' do account = Fabricate(:account) expect do account.mute!(Fabricate(:account), notifications: nil) end.to change { account.mute_relationships.count }.by 1 end it 'creates a Mute when :notifications is false' do account = Fabricate(:account) expect do account.mute!(Fabricate(:account), notifications: false) end.to change { account.mute_relationships.count }.by 1 end it 'creates a Mute when :notifications is true' do account = Fabricate(:account) expect do account.mute!(Fabricate(:account), notifications: true) end.to change { account.mute_relationships.count }.by 1 end end context 'Mute already exists' do context 'mute.hide_notifications is true' do it 'does not update mute.hide_notifications when :notifications is nil' do account = Fabricate(:account) target_account = Fabricate(:account) mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: true account.mute_relationships << mute expect do account.mute!(target_account, notifications: nil) end.not_to change { mute.reload.hide_notifications? }.from(true) end it 'updates mute.hide_notifications false when :notifications is false' do account = Fabricate(:account) target_account = Fabricate(:account) mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: true account.mute_relationships << mute expect do account.mute!(target_account, notifications: false) end.to change { mute.reload.hide_notifications? }.from(true).to(false) end it 'doesnt update mute.hide_notifications false when :notifications=true' do account = Fabricate(:account) target_account = Fabricate(:account) mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: true account.mute_relationships << mute expect do account.mute!(target_account, notifications: true) end.not_to change { mute.reload.hide_notifications? }.from(true) end end context 'mute.hide_notifications is false' do it 'updates mute.hide_notifications true when arg :notifications is nil' do account = Fabricate(:account) target_account = Fabricate(:account) mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: false account.mute_relationships << mute expect do account.mute!(target_account, notifications: nil) end.to change { mute.reload.hide_notifications? }.from(false).to(true) end it 'doesnt update mute.hide_notifications when arg :notifications is false' do account = Fabricate(:account) target_account = Fabricate(:account) mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: false account.mute_relationships << mute expect do account.mute!(target_account, notifications: false) end.not_to change { mute.reload.hide_notifications? }.from(false) end it 'updates mute.hide_notifications true when arg :notifications is true' do account = Fabricate(:account) target_account = Fabricate(:account) mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: false account.mute_relationships << mute expect do account.mute!(target_account, notifications: true) end.to change { mute.reload.hide_notifications? }.from(false).to(true) end end end
  28. Caleb Hearth dice.club/@caleb calebhearth.com Test Double describe '#mute!' do end

    context 'Mute already exists' do context 'mute.hide_notifications is true' do it 'does not update mute.hide_notifications when :notifications is nil' do account = Fabricate(:account) target_account = Fabricate(:account) mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: true account.mute_relationships << mute expect do account.mute!(target_account, notifications: nil) end.not_to change { mute.reload.hide_notifications? }.from(true) end it 'updates mute.hide_notifications false when :notifications is false' do account = Fabricate(:account) target_account = Fabricate(:account) mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: true account.mute_relationships << mute expect do account.mute!(target_account, notifications: false) end.to change { mute.reload.hide_notifications? }.from(true).to(false) end it 'doesnt update mute.hide_notifications false when :notifications=true' do account = Fabricate(:account) target_account = Fabricate(:account) mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: true account.mute_relationships << mute expect do account.mute!(target_account, notifications: true) end.not_to change { mute.reload.hide_notifications? }.from(true) end end
  29. Caleb Hearth dice.club/@caleb calebhearth.com Test Double it 'returns Mute without

    updating mute.hide_notifications' do expect do expect(subject).to be_kind_of Mute end.not_to change { mute.reload.hide_notifications? }.from(true) end
  30. Caleb Hearth dice.club/@caleb calebhearth.com Test Double it 'returns Mute without

    updating mute.hide_notifications' do expect do expect(subject).to be_kind_of Mute end.not_to change { mute.reload.hide_notifications? }.from(true) end
  31. Caleb Hearth dice.club/@caleb calebhearth.com Test Double it 'returns Mute without

    updating mute.hide_notifications' do expect do expect(subject).to be_kind_of Mute end.not_to change { mute.reload.hide_notifications? }.from(true) end
  32. Caleb Hearth dice.club/@caleb calebhearth.com Test Double it 'returns Mute without

    updating mute.hide_notifications' do expect do expect(subject).to be_kind_of Mute end.not_to change { mute.reload.hide_notifications? }.from(true) end
  33. Caleb Hearth dice.club/@caleb calebhearth.com Test Double it 'returns Mute without

    updating mute.hide_notifications' do expect do expect(subject).to be_kind_of Mute end.not_to change { mute.reload.hide_notifications? }.from(true) end
  34. Caleb Hearth dice.club/@caleb calebhearth.com Test Double it 'returns Mute without

    updating mute.hide_notifications' do expect do expect(subject).to be_kind_of Mute end.not_to change { mute.reload.hide_notifications? }.from(true) end
  35. Caleb Hearth dice.club/@caleb calebhearth.com Test Double it 'returns Mute without

    updating mute.hide_notifications' do expect do expect(subject).to be_kind_of Mute end.not_to change { mute.reload.hide_notifications? }.from(true) end
  36. Caleb Hearth dice.club/@caleb calebhearth.com Test Double it 'returns Mute without

    updating mute.hide_notifications' do expect do expect(subject).to be_kind_of Mute end.not_to change { mute.reload.hide_notifications? }.from(true) end
  37. Caleb Hearth dice.club/@caleb calebhearth.com Test Double it 'does not update

    mute.hide_notifications when :notifications is nil' do account = Fabricate(:account) target_account = Fabricate(:account) mute = Fabricate :mute, account: account, target_account: target_account, hide_notifications: true account.mute_relationships << mute expect do account.mute!(target_account, notifications: nil) end.not_to change { mute.reload.hide_notifications? }.from(true) end
  38. Caleb Hearth dice.camp/@caleb calebhearth.com Test Double ✅ Database Cleaner ✅

    Webmock ✅ Global things ❌ Most things in spec fi les before(:everything)
  39. Got a puzzler? Request a 1:1 
 virtual pairing 


    session with us! link.testdouble.com/rubypair Caleb Hearth dice.camp/@caleb calebhearth.com