-
-
Notifications
You must be signed in to change notification settings - Fork 1k
stub_model & mock_model handle mock_with syntax = [:expect]. #764
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
Conversation
Regression test for failure stubbing/mocking models when mock_with is set to `config.syntax = [:expect]` (no :should option) so #stub is unavailable.
When configured without the :should mode present, the #stub method is not available. RSpec::Rails::Mocks.add_stubs bypasses the switchable syntax layer, directly configuring a Matchers::Receive instance.
@@ -96,7 +103,8 @@ def self.primary_key; :id; end | |||
:valid? => true, | |||
:blank? => false) | |||
|
|||
double("#{model_class.name}_#{stubs[:id]}", stubs).tap do |m| | |||
double("#{model_class.name}_#{stubs[:id]}").tap do |m| | |||
RSpec::Rails::Mocks.add_stubs(m, stubs) | |||
m.singleton_class.class_eval do |
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.
This change would not be necessary after double(name, stubs)
is fixed in rspec/rspec-mocks#306, but it's a safe option for the moment.
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.
Perfect, thanks.
Nice catch here, thank you. I definitely want this in before 2.14.0. Once I hear back from Myron on the interface, I'll get this merged. |
I'll be happy to. |
Nice, thanks for getting that done. |
When configured without the
:should
mode present, the#stub
method isnot available. This means
stub_model
andmock_model
are broken in thisconfiguration.
Internal use of a new RSpec::Rails::Mocks.add_stubs method bypasses the
switchable syntax layer, directly configuring a Matchers::Receive instance.
Includes regression test for failure stubbing/mocking models when mock_with is
set to
config.syntax = [:expect]
(no :should option).See also: rspec/rspec-mocks#306