Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 let creates a memoized variable. What does assign do in this example?

like image 588
user3814030 Avatar asked Aug 16 '15 12:08

user3814030


People also ask

What is assigns RSpec?

assigns relates to the instance variables created within a controller action (and assigned to the view).

What does RSpec describe do?

The word describe is an RSpec keyword. It is used to define an “Example Group”. You can think of an “Example Group” as a collection of tests. The describe keyword can take a class name and/or string argument.

What is expect in RSpec?

RSpec::Expectations provides a simple, readable API to express the expected outcomes in a code example. To express an expected outcome, wrap an object or block in expect , call to or to_not (aliased as not_to ) and pass it a matcher object: expect(order. total).

Does RSpec clean database?

I use the database_cleaner gem to scrub my test database before each test runs, ensuring a clean slate and stable baseline every time. By default, RSpec will actually do this for you, running every test with a database transaction and then rolling back that transaction after it finishes.


1 Answers

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

like image 112
Dave Schweisguth Avatar answered Oct 07 '22 00:10

Dave Schweisguth