Read more

One-liner syntax in RSpec's should-based and expect-based syntaxes

Henning Koch
February 22, 2016Software engineer at makandra GmbH

RSpec supports a one-liner syntax for setting an expectation on the subject:

describe Array do
  describe "when first created" do
    it { should be_empty }
  end
end
Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

The example description "it should be empty" will be defined automatically.

With RSpec 3's expect-based syntax you use it_is_expected instead:

describe Array do
  describe "when first created" do
    it { is_expected.to be_empty }
  end
end
Posted by Henning Koch to makandra dev (2016-02-22 14:03)