user3814030 user3814030 - 1 year ago 111
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?

Answer Source

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:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download