Rails unit-testing best practices(blog.rainforestqa.com)
blog.rainforestqa.com
Rails unit-testing best practices
https://blog.rainforestqa.com/2014-07-28-optimal-rails-unit-testing-toolset/
3 comments
Nice summary of one of the many different testing philosophies (this one happens to be very close to my own).
As an alternative, where you currently have:
As an alternative, where you currently have:
it { expect(client.active?).to be_false }
It might be even more idiomatic to write: subject { client }
it { should_not be_active }
# etc.
...beautiful!Or even better, simply replace
Rspec's syntax is great.
let(:client) { create(:client, :inactive) }
with subject { create(:client, :inactive) }
and then carry on as above.Rspec's syntax is great.
I am the author of that post, feel free to ask any question or give feedback :)
I would have written a different title though, because as the last paragraph indicates, the post recommends some tools but not best practices (which at this basic level would be things like: minimize the interaction with the database and external systems, extract duplicated test code to helpers, label your tests with descriptive names, etc).