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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.