Skip to content

Commit

Permalink
Deprecate usage of should_not raise_error
Browse files Browse the repository at this point in the history
  • Loading branch information
andrykonchin committed Dec 5, 2020
1 parent b58e665 commit eafaf6e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/mspec/expectations/should.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def should_not(matcher = NO_MATCHER_GIVEN)
raise "should_not outside example" unless state
MSpec.actions :expectation, state

if RaiseErrorMatcher === matcher
$stderr.puts "\nDeprecation: ->{}.should_not raise_error breaks code style and is deprecated"
end

if NO_MATCHER_GIVEN.equal?(matcher)
SpecNegativeOperatorMatcher.new(self)
else
Expand Down
4 changes: 4 additions & 0 deletions spec/expectations/should.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,8 @@ def finish
it "invokes the MSpec :expectation actions" do
1.should_not == 2
end

it "deprecates using `{}.should_not raise_error`" do
-> { }.should_not raise_error
end
end
6 changes: 5 additions & 1 deletion spec/expectations/should_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
before :all do
path = RbConfig::CONFIG['bindir']
exe = RbConfig::CONFIG['ruby_install_name']
file = File.dirname(__FILE__) + '/should.rb'
file = File.dirname(__FILE__) + '/should.rb 2>&1'
@out = `#{path}/#{exe} #{file}`
end

Expand Down Expand Up @@ -45,6 +45,10 @@
No behavior expectation was found in the example
EOS
end

it 'prints a deprecation message about using `{}.should_not raise_error`' do
@out.should include "Deprecation: ->{}.should_not raise_error breaks code style and is deprecated"
end
end

it "prints status information" do
Expand Down

0 comments on commit eafaf6e

Please sign in to comment.