Share
Embed
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
Transcript
109 slides
-
Caleb Hearth dice.camp/@caleb calebhearth.com Test Double dice.camp/@caleb Caleb Hearth calebhearth.com
Test Double RSpec: The Bad Parts -
Caleb Hearth dice.camp/@caleb calebhearth.com Test Double let(:player) { Dwarf.new }
let(:party) { [player] } -
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 -
Caleb Hearth dice.camp/@caleb calebhearth.com Test Double let(:player) { Dwarf.new }
let(:party) { [player] } subject { player } -
Caleb Hearth dice.camp/@caleb calebhearth.com Test Double it "has 10 pages"
expect(Book.new.page_count) .to eq 10 end Book.new -
Caleb Hearth dice.camp/@caleb calebhearth.com Test Double it "has 10 pages"
expect(Book.new.page_count) .to eq 10 end Book.new -
Caleb Hearth dice.camp/@caleb calebhearth.com Test Double it "has 10 pages"
expect(Book.new.page_count) .to eq 10 end Book.new -
- The Pragmatic Programmer Every piece of knowledge must have
a single, unambiguous, authoritative representation within a system “ -
- The Pragmatic Programmer Every piece of knowledge must have
a single, unambiguous, authoritative representation within a system “ -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
Caleb Hearth dice.camp/@caleb calebhearth.com Test Double ✅ Database Cleaner ✅
Webmock before(:everything) -
Caleb Hearth dice.camp/@caleb calebhearth.com Test Double ✅ Database Cleaner ✅
Webmock ✅ Global things before(:everything) -
Caleb Hearth dice.camp/@caleb calebhearth.com Test Double ✅ Database Cleaner ✅
Webmock ✅ Global things ❌ Most things in spec fi les before(:everything) -
Caleb Hearth dice.camp/@caleb calebhearth.com Test Double module DoThingsable extend ActiveModel::Concern
end Caleb Hearth dice.camp/@caleb calebhearth.com Test Double -
Caleb Hearth dice.camp/@caleb calebhearth.com What topics would be helpful to
you? link.testdouble.com/rubysurvey -
Got a puzzler? Request a 1:1 virtual pairing
session with us! link.testdouble.com/rubypair Caleb Hearth dice.camp/@caleb calebhearth.com