dev-resources.site
for different kinds of informations.
RSpec & Rails: what not to write in `it`
Published at
5/19/2022
Categories
ruby
testing
programming
Author
Vasily Polovnyov
1. Useless, general words that bring no value:
# bad: what value? for what?
it "adds certain value"
# good
it "snoozes for an extra 5 minutes"
# bad: which result is correct?
it "returns correct result"
# good
it "returns user's initials"
# bad: how exactly it fails?
it "fails"
# good
it "raises a not found error"
# bad: formatted how?
it "returns formatted string"
# good
it "returns time in 24-hour format"
# bad: what 'ok' means?
it "is ok"
# good
it "creates draft invoices"
2. Implementation details:
# bad
it "changes @scheduled_on"
# good
it "reschedules campaign"
# bad
it "sets @todos"
# good
it "assigns todos to a given user"
3. Lies:
it "returns time in 24-hour format" do
expect(...).to eq "9:25"
end
it "strips leading zeroes" do
expect(foo(" 9:25 ")).to eq "9:25"
end
See also:
RSpec Style Guide
Better Specs
Articles
12 articles in total
RSpec & Rails: what not to write in `it`
currently reading
RSpec & Rails: how to stub env vars
read article
How to test code that works with an external API: a stub on Sinatra
read article
Quick tip: stub requests to unix sockets
read article
Using Faker is anti-pattern
read article
Fake data in tests
read article
Linting Ruby right in Neovim
read article
โWhatโ and โFor whatโ in pull requests
read article
Rack application as a stub
read article
Learning Through Overuse
read article
My new favourite programming font: iA Writer Mono S
read article
Is it time to quit?
read article
Featured ones: