Spy more easily with `spy_on` helper
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib/rspec
spec
yard/template/default
.gitignore
.rspec
.travis.yml
.yardopts
Gemfile
LICENSE.txt
README.md
Rakefile
rspec-spy_on.gemspec

README.md

Rspec::SpyOn Build StatusCoverage Status

RSpec::SpyOn allows easier setup of test spies through the use of the spy_on method

Installation

Add this line to your application's Gemfile:

gem 'rspec-spy_on'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rspec-spy_on

Usage

Instead of doing the following:

allow(dbl).to receive(:foo)
allow(dbl).to receive(:bar)

do_something_with(dbl)

expect(dbl).to have_received(:foo)
expect(dbl).to have_received(:bar)

You can instead do:

spy_on(dbl, :foo, :bar)

do_something_with(dbl)

expect(dbl).to have_received(:foo)
expect(dbl).to have_received(:bar)

Where this particularly comes in handy is when you need to spy with a real instance of an object (what is known as a partial double).

When called on any ruby object that is not an RSpec::Mocks::TestDouble it will automatically call and_call_original if the passed in object responds to the desired message.