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"”

  1. Dylan Says:

    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

  2. Dylan Says:

    http://pastie.caboo.se/86784

  3. Lance Says:

    I feel like it should be it_should instead. What do you think?

  4. Keeran Says:

    Hey guys,

    Wouldn’t Dylan’s solution provide a clearer spec output, as by aliasing the method you end up with specs like:

    A list item
    - denormalise task name
    

    Either way it increases readability so all good! :) Thanks

  5. Erik Says:

    I use:

    it "denormalizes task name"
    

    Reads well in the code, reads well in the doc, keeps the words that describe the behavior, and omits a sea of shoulds.

Sorry, comments are closed for this article.