Add verifying double features from rspec-fire.
Created by: xaviershay
This is intended to be both API compatible with rspec-fire, and to completely obsolete it. It does not yet implement any of the suggested changes in #227 (closed), such as transferring nested constants by default or an alternate constant stubbing interface.
It adds the following behaviours:
verifying doubles
class doubles
when doubled class is not loaded
allows any method to be stubbed
when doubled class is loaded
can transfer nested constants to the double
can replace existing constants for the duration of the test
only allows class methods that exist to be expected
only allows class methods that exist to be stubbed
allows class to be specified by constant
instance doubles
when doubled class is not loaded
allows any instance method to be stubbed
when doubled class is loaded
only allows instance methods that exist to be expected
only allows instance methods that exist to be stubbed
checks the arity of stubbed methods
allows class to be specified by constant
when verify_constant_names config option is set
prevents creation of instance doubles for unloaded constants
prevents creation of class doubles for unloaded constants
It adds a perhaps unexpected method to the public API: ArityMatcher.match!
. This seemed useful enough on its own to make public, but I would consider keeping it private if anyone exists.
Suggested reading order
If you are not familiar with rspec-fire
, start with features/verifying_doubles/README.md
. lib/rspec/mocks/example_methods.rb
is the entry point for the feature. Trace that through until you find lib/rspec/mocks/verifying_proxy.rb
which contains the bulk of the logic.
Questions for reviewers
- I'm not familiar with yardoc style. Does this conform?
- What is the preferred way to split features over the
README
and actual cucumber files? - It is unfortunate that I need to use a parallel class hierarchy for the verifying counterparts. Is there a better way to do this?
@myronmarston @jonrowe
Fixes #227 (closed).