Rails 5 is without a doubt the best, most complete version of Rails yet. It has become better experience out of the box. Let's find out the secrets of testing rails 5 apps.
23. Returns a saved User instance (writes to DB)
user = create(:user)
# Returns a User instance that's not saved (does not write to DB)
user = build(:user)
factory :user do
association posts
end
FactoryGirl.build(:user) #this creates posts in the database even though you are only building the parent
object(user)
Returns an object with all defined attributes stubbed out
stub = build_stubbed(:user)
24.
25.
26. 20 Tools and Techniques That Make You More
Creative
We are hitting the postcontroller create. We are checking if it is redirected to correct path. But we are also checking database value change which is not actually part of the response.
They dont actually follow the same request / response cycle as it happens when a request hits the application. They bypass typical request/response cycle. It directly hits the particular action and tries to see what happenning inside.They are not really testing the controller in true sense. They are just like unit testing the controller actions.
We can write functional type controller tests in rails… They dont bypass middleware stack. They go through the way when a request hits rails app.
Rails by default will not generate the controller test codes. It will generate integrated test codes.
Rails by default will not generate the controller test codes. It will generate integrated test codes.
Rails by default will not generate the controller test codes. It will generate integrated test codes.
Rails is suggesting not to test the internals rather than test the outcome