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

Posted . Visible to the public.

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

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
Henning Koch
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2016-02-22 13:03)