Skip to content

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

Closed
wants to merge 3 commits into from
Closed

stub_model & mock_model handle mock_with syntax = [:expect]. #764

wants to merge 3 commits into from

Conversation

pda
Copy link
Contributor

@pda pda commented Jun 12, 2013

When configured without the :should mode present, the #stub method is
not available. This means stub_model and mock_model are broken in this
configuration.

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

pda added 3 commits June 12, 2013 23:08
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
Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks.

@alindeman
Copy link
Contributor

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.

@pda
Copy link
Contributor Author

pda commented Jun 18, 2013

@pda -- want to take a stab at adding the above public APIs to RSpec mocks? — @myronmarston

I'll be happy to.
I should be able to squeeze it into my Rails Camp schedule this weekend.

@pda
Copy link
Contributor Author

pda commented Jul 4, 2013

Nice, thanks for getting that done.
Sorry for vanishing… work + moving overseas has killed my available time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants