Recovering interrupter with occasional relapses, lover of spreadsheets, blogger, programmer, adept debugger, conjurer of analogies, and probably other things.
One of my favorite things in RSpec is to consider how let, subject, describe, and context can help you create specs that "self-document" (as in the formatted out is quite nice). When done well, it means I don't need to write many of the it "something or other" (which can sometimes drift from the spec).
RSpec.describeUserdodescribe"#registered?"let(:confirmation_status){true}let(:user){User.new(confirmation_status: confirmation_status)}subject(:method_call){user.registered?}context"when no confirmation"dolet(:confirmation_status){false}it{is_expected.tobe_falsey}endcontext"with confirmation"dolet(:confirmation_status){true}it{is_expected.tobe_truthy}endendend
Definitely! I like how the tests can be self-documenting and also that RSpec provides a way to print the outcomes in various formats so it reads like a specification document.
Recovering interrupter with occasional relapses, lover of spreadsheets, blogger, programmer, adept debugger, conjurer of analogies, and probably other things.
I choose "describe" for the thing under test (e.g. describe "#call"). And "context" for the conditionals (e.g. context "when given user is logged in").
One of my favorite things in RSpec is to consider how
let
,subject
,describe
, andcontext
can help you create specs that "self-document" (as in the formatted out is quite nice). When done well, it means I don't need to write many of theit "something or other"
(which can sometimes drift from the spec).Definitely! I like how the tests can be self-documenting and also that RSpec provides a way to print the outcomes in various formats so it reads like a specification document.
Curious on how you think about
describe
vscontext
. In simple terms, how you decide to use one vs the other in different scenarios?I choose "describe" for the thing under test (e.g.
describe "#call"
). And "context" for the conditionals (e.g.context "when given user is logged in"
).I've always liked this, too! It's one of the reasons I find other testing tools so ... unpleasant.
Especially when there's lots of syntactical punctuation littered around.