Skip to content

Commit

Permalink
clarify deprecation warnings for not_to raise_error(with, args)
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed May 16, 2013
1 parent f45b6a6 commit b956215
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 8 additions & 3 deletions lib/rspec/matchers/built_in/raise_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ def initialize(expected_error_or_message=Exception, expected_message=nil, &block

def matches?(given_proc, negative_expectation = false)
if negative_expectation && (expecting_specific_exception? || @expected_message)
RSpec.deprecate("`expect { }.not_to raise_error(SpecificErrorClass)`",
"`expect { }.not_to raise_error()`",
"3.0.0")
what_to_deprecate = if expecting_specific_exception? && @expected_message
"`expect { }.not_to raise_error(SpecificErrorClass, message)`"
elsif expecting_specific_exception?
"`expect { }.not_to raise_error(SpecificErrorClass)`"
elsif @expected_message
"`expect { }.not_to raise_error(message)`"
end
RSpec.deprecate(what_to_deprecate, "`expect { }.not_to raise_error()`", "3.0.0")
end
@raised_expected_error = false
@with_expected_message = false
Expand Down
6 changes: 3 additions & 3 deletions spec/rspec/matchers/raise_error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
end

it "is deprecated" do
expect(RSpec).to receive(:deprecate)
expect(RSpec).to receive(:deprecate).with(/not_to raise_error\(message\)/, /not_to raise_error\(\)/, "3.0.0")
expect {raise 'blarg'}.not_to raise_error('blah')
end

Expand Down Expand Up @@ -205,7 +205,7 @@
end

it "is deprecated" do
expect(RSpec).to receive(:deprecate)
expect(RSpec).to receive(:deprecate).with(/not_to raise_error\(SpecificErrorClass\)/, /not_to raise_error\(\)/, "3.0.0")
expect { }.not_to raise_error(NameError)
end

Expand Down Expand Up @@ -254,7 +254,7 @@
end

it "is deprecated" do
expect(RSpec).to receive(:deprecate)
expect(RSpec).to receive(:deprecate).with(/not_to raise_error\(SpecificErrorClass, message\)/, /not_to raise_error\(\)/, "3.0.0")
expect {}.not_to raise_error(RuntimeError, "example message")
end

Expand Down

1 comment on commit b956215

@fables-tales
Copy link
Member

Choose a reason for hiding this comment

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

I like this 👍

Please sign in to comment.