Skip to content

Instantly share code, notes, and snippets.

@patwey
Last active April 21, 2017 01:25
Show Gist options
  • Save patwey/40ec478f0295bc4d61c312e967b9bb8b to your computer and use it in GitHub Desktop.
Save patwey/40ec478f0295bc4d61c312e967b9bb8b to your computer and use it in GitHub Desktop.
A few notes I'm jotting down as I work through a scotch.io tutorial

let vs. let!

let is a lazy-loaded memoized helper method, meaning that it won't be evaluated until the first time it's called.

let! forces the method's evaluation before each example

described_class

The first argument to the outermost example group:

  RSpec.describe MyClass do
    described_class # => MyClass
  end

subject

implicit - the first argument to the outermost example group (see above)

explicit - defined by subject,

  • subject { MyClass.new(arg1) }
  • named explicit: subject(:my_subject) { MyClass.new(arg1) }

shoulda-matchers gem

Provides a nice syntax for creating one-liner tests of common Rails functionality:

it { validates_presence_of :name }

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