The 5 Rules of Simple RSpec Tests | solnic.codes - 3. meaninful example descriptions

PHOTO EMBED

Fri May 28 2021 14:40:41 GMT+0000 (Coordinated Universal Time)

Saved by @captm

RSpec.describe CreateUser do
  subject do
    CreateUser.new
  end

  context "with valid params" do
    specify {
      expect(create_user.(name: "Jane", email: "jane@doe.org")).to be_success
    }
  end
end
content_copyCOPY

You can streamline a lot with RSpec’s powerful DSL but I prefer to optimize for readability and having nice descriptions is part of this. In general, I try to describe actual scenarios that can happen in the actual client code (as in, the code that will be using the thing I’m writing a spec for).

https://solnic.codes/2021/05/11/the-5-rules-of-simple-rspec-tests/