We tend to use describe() for things and context() for context
RSpec book
- wrap a set of tests 'against one functionality'
- "use describe for things"
- start describe with '#' for instance method
- start describe with '.' for class method
- wrap a set of tests against one functionality 'under the same state'
- "use context for state"
- start context with
when/with
describe '#dead' do
subject(:cat) { Cat.new(lives: starting_lives) }
context "with nine lives" do
let(:starting_lives) { 9 }
it { is_expected.not_to be_dead }
end
context "with no lives" do
let(:starting_lives) { 0 }
it { is_expected.to be_dead }
end
# Alternatively, sometimes you can't use is_expected syntax
context 'when cat has no more lives' do
let(:starting_lives) { 0 }
it 'is dead :(' do
expect(cat).to be_dead
end
end
end
- don't use
should
in test names- instead say what will happen
- prefer active verbs
- Use
it
to say what you're expecting to happen