-
-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add verifying double features from rspec-fire. #378
Conversation
When using verifying doubles, RSpec will check that the methods being stubbed | ||
are actually present on the underlying object if it is available. | ||
|
||
No checking will happen when running the spec in isolation, but when run in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the "when running the spec in isolation" part is a bit misleading: it's not about if I run rspec path/to/one/spec.rb
vs rspec spec
but about whether or not the named constant is loaded or not. I think of rspec path/to/one/spec.rb
as "running a spec in isolation", but it will still verify the double if the named constant is loaded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
No checking will happen if the object definition isn't loaded, but when run with the object loaded (either as a full spec run or by explicitly preloading collaborators) a failure will be triggered if an invalid method is being stubbed.
Looking good so far. I need to go fold laundry but I'll come back later (or perhaps tomorrow) to read through and comment on the rest. |
Currently this is failing for all our |
|
||
# once you do this, you can no longer access MyCoolGem::Widget in your | ||
# example... | ||
class_double("MyCoolGem") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I the only one that finds class_double
confusing when used on a Module
? :)
Thanks for the great feedback! Will address it all in the next couple of days. |
New commits are hiding an open discussion about naming of
|
1.8.7 is passing now. |
This is OK.
I dislike. "verify verifying" is awkwardly awkward.
It's OK.
It's OK.
I think I like this one best.
I like this one OK, too. |
method.name, | ||
arity_description, | ||
actual_arity | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason you prefer this over "#{string} #{interpolation}"
? I find string interpolation easier to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(BTW, I'm not writing that to tell you you must change it--I'm genuinely curious why you chose to go that route!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I find this version easier to read, since I see the "shape" of the sentence much clearer, and there's not so many that it isn't obvious which value interpolates where.
- It fits much nicer in 80-chars.
@@ -0,0 +1,52 @@ | |||
Feature: Using a class double | |||
|
|||
`class_double` is provided as a complement to `instance_double`, with the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that this references instance_double
, but comes first alphabetically, it would be good to list the order we want this in the relish nav file, so that this file can come later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in new commit.
All other comments make sense, will revise. |
underlying object if it is available. Prefer using veryifing doubles over | ||
normal doubles. | ||
|
||
No checking will happen if the object definition is not loaded, but when run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No checking will happen if the object definition is not loaded
This is a bit misleading/inaccurate: it's not about whether or not the object definition is loaded, it's about whether or not the named class constant is defined. I've actually run into a subtle edge case where the class constant was defined but the object definition wasn't loaded, and rspec-fire told me the named class didn't implement a method that it actually did (at least it did when fully loaded). The specific edge case I ran into was in our use of a github-sourced gem in our gemfile that used the common idiom (as generated by bundle gem
) whereby the .gemspec
file has a require 'mygem/version'
, which caused MyGem::VERSION
to get loaded (which implies that MyGem
was a defined constant) when Bundler.setup
ran (since it eval'd the gemspec file), but the actual definition of the MyGem
class wasn't loaded. Note that this isn't a problem with normal released gems...the .gemspec
file gets compiled to a static YAML file during that process, and thus bundler can read the gemspec w/o it loading the version constant.
While this is a bit of an edge case other users will hopefully never run into, I think it's good to reduce potential future confusion by accurately stating that the checking happens if the class constant is defined, regardless of whether or not the class definition is actually loaded.
Don't have a strong opinion on the |
As far as I'm concerned, this needs a changelog entry, and to be rebased against master (or merged against it, if you prefer), and it needs a green travis build, but is ready to be merged otherwise. |
This is intended to be both API compatible with rspec-fire, and to completely obsolete it. Fixes rspec#227.
@myronmarston rebased, Changelog entry added, CI is green. |
Add verifying double features from rspec-fire.
Beautiful :). Thanks for doing such a great job with this! |
BTW, I opened up issues for the other features and changes we discussed so that we don't forget them:
Do you want to take a stab at any of these, @xaviershay? If so, please comment on them so someone else doesn't also work on them and cause wasted effort. |
@xaviershay thanks so much, this is a really cool feature. |
@xaviershay I'm very excited about your work on this! Thanks a ton. |
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, such as transferring nested constants by default or an alternate constant stubbing interface.
It adds the following behaviours:
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 withfeatures/verifying_doubles/README.md
.lib/rspec/mocks/example_methods.rb
is the entry point for the feature. Trace that through until you findlib/rspec/mocks/verifying_proxy.rb
which contains the bulk of the logic.Questions for reviewers
README
and actual cucumber files?@myronmarston @JonRowe
Fixes #227.