This repository has been archived by the owner on Nov 30, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #452 from rspec/fix-deprecation-helpers
Fix expect_warn_deprecation matching any message
- Loading branch information
Showing
2 changed files
with
114 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
require 'rspec/matchers/fail_matchers' | ||
|
||
RSpec.describe RSpecHelpers do | ||
def deprecate!(message) | ||
RSpec.configuration.reporter.deprecation(:message => message) | ||
end | ||
|
||
def fail_with(snippet) | ||
raise_error(RSpec::Mocks::MockExpectationError, snippet) | ||
end | ||
|
||
def raise_unrelated_expectation! | ||
raise(RSpec::Expectations::ExpectationNotMetError, 'abracadabra') | ||
end | ||
|
||
describe '#expect_no_deprecations' do | ||
shared_examples_for 'expects no deprecations' do | ||
it 'passes when there were no deprecations' do | ||
expectation | ||
end | ||
|
||
it 'fails when there was a deprecation warning' do | ||
in_sub_process do | ||
expect { | ||
expectation | ||
deprecate!('foo') | ||
}.to fail_with(/received: 1 time/) | ||
end | ||
end | ||
|
||
it 'fails with a MockExpectationError when there was also an ExpectationNotMetError' do | ||
in_sub_process do | ||
expect { | ||
expectation | ||
deprecate!('bar') | ||
raise_unrelated_expectation! | ||
}.to fail_with(/received: 1 time/) | ||
end | ||
end | ||
end | ||
|
||
it_behaves_like 'expects no deprecations' do | ||
def expectation | ||
expect_no_deprecations | ||
end | ||
end | ||
|
||
# Alias | ||
it_behaves_like 'expects no deprecations' do | ||
def expectation | ||
expect_no_deprecation | ||
end | ||
end | ||
end | ||
|
||
describe '#expect_warn_deprecation' do | ||
it 'passes when there was a deprecation warning' do | ||
in_sub_process do | ||
expect_warn_deprecation(/bar/) | ||
deprecate!('bar') | ||
end | ||
end | ||
|
||
pending 'fails when there were no deprecations' do | ||
in_sub_process do | ||
expect { | ||
expect_warn_deprecation(/bar/) | ||
}.to raise_error(/received: 0 times/) | ||
end | ||
end | ||
|
||
it 'fails with a MockExpectationError when there was also an ExpectationNotMetError' do | ||
in_sub_process do | ||
expect { | ||
expect_warn_deprecation(/bar/) | ||
deprecate!('bar') | ||
raise_unrelated_expectation! | ||
}.to raise_error(RSpec::Expectations::ExpectationNotMetError) | ||
end | ||
end | ||
|
||
it 'fails when deprecation message is different' do | ||
in_sub_process do | ||
expect { | ||
expect_warn_deprecation(/bar/) | ||
deprecate!('foo') | ||
}.to raise_error(%r{match /bar/}) | ||
end | ||
end | ||
|
||
it 'fails when deprecation message is different and an ExpectationNotMetError was raised' do | ||
in_sub_process do | ||
expect { | ||
expect_warn_deprecation(/bar/) | ||
deprecate!('foo') | ||
raise_unrelated_expectation! | ||
}.to raise_error(%r{match /bar/}) | ||
end | ||
end | ||
end | ||
end |