user3814030 user3814030 - 5 months ago 21
Ruby Question

What does assign do in rspec-rails?

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
creates a memoized variable.
What does
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: