Saturday, June 7, 2014

Notes - Rails Tutorial - Chapter 6

let http://www.railstutorial.org/book/modeling_users#sidebar-let
From Michael Harl's Rails Tutorial Chapter 6 Box 6.3. Using let
RSpec’s let method provides a convenient way to create local variables inside tests. The syntax might look a little strange, but its effect is similar to variable assignment. The argument of let is a symbol, and it takes a block whose return value is assigned to a local variable with the symbol’s name. In other words, 
let(:found_user) { User.find_by(email: @user.email) } 
creates a found_user variable whose value is equal to the result of find_by. We can then use this variable in any of the before or it blocks throughout the rest of the test. One advantage of let is that it memoizes its value, which means that it remembers the value from one invocation to the next. (Note that memoize is a technical term; in particular, it’s not a misspelling of “memorize”.) In the present case, because let memoizes the found_user variable, the find_by method will only be called once whenever the User model specs are run.
specify method -
This is just a synonym for it, and can be used when writing it would sound unnatural.

reload method for reloading a value from the database and the eq method for testing equality.
debug method
controller: static_pages
action: home 
This is a YAML3 representation of params, which is basically a hash, and in this case identifies the controller and action for the page.
params variable

Rails comes equipped with three environments: test, development, and production. The default environment for the Rails console is development:

No comments:

Post a Comment