Skip to content

Instantly share code, notes, and snippets.

@cjjavellana
Created April 13, 2015 22:07
Show Gist options
  • Save cjjavellana/18e995c452e24f57ae5a to your computer and use it in GitHub Desktop.
Save cjjavellana/18e995c452e24f57ae5a to your computer and use it in GitHub Desktop.
RSpec Raise Error

There is a subtle difference between the expect that is used to validate an output against the expect that is used to validate that a block of code does raise an error

When asserting that an output is correct use:

expect(cart).to be_empty

When expecting a block of code to raise an error:

expect{cart.add_item("fake-sku")}.to raise_error

Notice that parenthesis in the first expect and the curly brackets in the second expect statements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment