I am working on code that I haven't written and trying to understand how RSpec works.
let(:course) { create :new_course }
before { assign :course, course }
I know that let
creates a memoized variable.
What does assign
do in this example?
You must be looking at a view spec. In an rspec-rails view spec, assign
assigns its second argument to the template instance variable named by the first argument. In your example, assign :course, course
sets @course
in the template to the value of course
.
More here: https://www.relishapp.com/rspec/rspec-rails/v/3-3/docs/view-specs/view-spec