-
-
Notifications
You must be signed in to change notification settings - Fork 394
Block matchers not detecting passed in block arguments #1134
Comments
I agree. This sort of major breaking change does not belong in a Z release. |
👋 Hi, sorry about this, this is not a breaking change though, it's a bug. The change was intended as an improvement to the warning which happens when people incorrectly pass in values to block matchers. This is an edge case that was overlooked and we'll investigate a fix. |
@msxavi Can you please provide more details on how the subject is defined? |
@pirj Hi! Voxpupuli has noticed build failures in several of our puppet modules this morning. Puppet module testing is based on rspec-puppet If it helps, I can provide some other examples, or drop by |
@alexjfisher This and how block matchers are implemented is causing problems. Would you agree instead of using expect { catalogue }.to raise_error(Puppet::Error)
# ...
expect { catalogue }.to have_resource_count(9) I can send pull requests to
|
@pirj Hi! Thanks for getting back to me. Is the new syntax just until rspec-puppet can be fixed? |
and thank you for your offer of PRs to rspec-puppet. I'm sure they would be very much appreciated. |
@alexjfisher I suggest you to explicitly set # Gemfile
group :test do
gem 'rspec-expectations', '< 3.8.5' and update |
Yes, we can certainly do that. We manage a lot of puppet modules though and they almost all use rspec-puppet. I'll see if I can get the dependency updated there (until it's fixed). |
this applies until a solution to rspec/rspec-expectations#1134 is created
@pirj here it is. It's a regular post request defined as a lambda. TBH that looks a little bit wicked.
|
@msxavi Agree. describe 'POST #create' do
def send_request
post :create, params: params
end
let(:params) {}
it 'creates a new post' do
expect { send_request }.to change { Post.count }.by(1)
end
end Let's keep the issue open to track Vox Pupuli's issues with |
@pirj Hi! rspec-puppet has had a new release, but bundler doesn't prefer the latest version of rspec-puppet over the latest version of rspec-expectations. (Not without us updating every Gemfile, which we're hoping to avoid). |
@alexjfisher So, bundler prefers let(:catalogue) { -> { load_catalogue } }
subject { catalogue }
...
is_expected.to raise_error ...
expect(subject).to raise_error ...
expect(catalogue).to raise_error ... won't work, since it's a built-in subject { catalogue }
let(:catalogue) { load_catalogue }
...
expect { subject }.to raise_error ...
expect { catalogue }.to raise_error ... |
It's seems non deterministic. In local testing I've seen |
This test was failing due to some changes on rspec-expectactions gems. More info here: rspec/rspec-expectations#1134
While yes the work arounds are good, this is a breaking change, and there are a ton of puppet modules and work arounds, we have |
Hi @cyberious as I've mentioned we are looking into it. However please remember this is an open source project staffed by volunteers, so I'm afraid "when" is "when we have time". |
Fixing @JonRowe WDYT if we revert this change in 3.8.6 and re-introduce in 4.0? @cyberious This means that |
That would give us time to make changes. Maybe even a rubocop-rspec enhancement could help, or perhaps someone could even figure out a rubocop-rspec-puppet with an autofix for the most common issues? |
@alexjfisher There's Doing otherwise that would only detect built-in RSpec block matchers, and would miss block matchers wrapped in methods, e.g.: def create_user
change { User.count }.by(1)
end
it { is_expected.to create_user } |
Ended up introducing |
Thanks, @pirj but I agree with @cyberious this is a breaking change regardless and I've got many other specs in the same format. Where are we about reverting #1125? Is that an option? |
#1125 Has been reverted for the time being, so this should no longer be an issue. Released as 3.8.6. |
Why introducing a breaking change in the latest patch?
Upgrading expectations from 3.8.4 to 3.8.5 breaks specs with:
You must pass a block rather than an argument to
expectto use the provided block expectation matcher (change
Post.countby 1).
Your environment
Steps to reproduce
Expected behavior
is_expected.to change { Post.count }.by(1)
should not raise an error.Breaking changes should be introduced in major updates like 4.0. Is there any approach to keep the compatibility?
Actual behavior
is_expected.to change { Post.count }.by(1)
raisesYou must pass a block rather than an argument to
expectto use the provided block expectation matcher (change
Post.countby 1)
The text was updated successfully, but these errors were encountered: