Skip to Main Content
Rails 5 Test Prescriptions
book

Rails 5 Test Prescriptions

by Noel Rappin
February 2018
Intermediate to advanced content levelIntermediate to advanced
406 pages
9h 52m
English
Pragmatic Bookshelf
Content preview from Rails 5 Test Prescriptions

Creating Stubs

A stub is a replacement for all or part of an object that prevents a normal method call from happening and instead returns a value that is preset when the stub is created. In RSpec, there are two kinds of stubs. You can create entire objects that exist only to be stubs, which we’ll call full doubles, or you can stub specific methods of existing objects, which we’ll call partial doubles.

A partial double is useful, for example, when you want to use a “real” ActiveRecord object but you have one or two dangerous or expensive methods you want to bypass. A full double is useful when you’re testing that your code works with a specific API rather than a specific object. By passing in a generic object that responds to only certain methods, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Rails 4 Test Prescriptions

Rails 4 Test Prescriptions

Noel Rappin
Agile Web Development with Rails 5.1

Agile Web Development with Rails 5.1

Sam Ruby, David B. Copeland, Dave Thomas
Rspec Essentials

Rspec Essentials

Mani Tadayon

Publisher Resources

ISBN: 9781680505566Errata Page