O'Reilly logo

Rails 4 Test Prescriptions by Noel Rappin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, as in many Ruby double libraries, there are two kinds of fake objects. 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 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required