rspec: always typing it "should"
Courtenay : August 10th, 2007
Do your specs always start with it "should" ?
Like
context "A list-item" do
it "should denormalize task name" do
@item = ListItem.new :task => mock_model(Task, :name => "TaskName")
Well, rather than moaning about changing the syntax, do it yourself! (Thanks to David Chelimsky in #rspec)
Put this in spec_helper
module Spec::DSL::BehaviourEval::ModuleMethods
alias :should :it
end
Now you can refer to either "should", or "it".
context "A list-item" do
should "denormalize task name" do
Win!
5 Responses to “rspec: always typing it "should"”
Sorry, comments are closed for this article.
August 10th, 2007 at 10:29 PM
I’ve been using, just to keep the should in the specdocs.
module Spec::DSL::BehaviourEval::ModuleMethods def should(description=:_generatedescription, opts={}, &block) it(“should ” + description, opts, &block) end end
August 10th, 2007 at 10:30 PM
http://pastie.caboo.se/86784
August 11th, 2007 at 10:39 PM
I feel like it should be it_should instead. What do you think?
August 12th, 2007 at 05:19 AM
Hey guys,
Wouldn’t Dylan’s solution provide a clearer spec output, as by aliasing the method you end up with specs like:
Either way it increases readability so all good! :) Thanks
August 29th, 2007 at 01:32 PM
I use:
Reads well in the code, reads well in the doc, keeps the words that describe the behavior, and omits a sea of shoulds.