From 95a2dcf23df021aa39d6d705db6c6ed433fd63c7 Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Sun, 6 Dec 2020 00:26:41 +0200 Subject: [PATCH 1/2] Deprecate usage of `should_not raise_error` --- lib/mspec/expectations/should.rb | 4 ++++ spec/expectations/should.rb | 4 ++++ spec/expectations/should_spec.rb | 10 +++++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/mspec/expectations/should.rb b/lib/mspec/expectations/should.rb index ca061748..047b05ce 100644 --- a/lib/mspec/expectations/should.rb +++ b/lib/mspec/expectations/should.rb @@ -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 diff --git a/spec/expectations/should.rb b/spec/expectations/should.rb index 48503b16..57d383ba 100644 --- a/spec/expectations/should.rb +++ b/spec/expectations/should.rb @@ -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 diff --git a/spec/expectations/should_spec.rb b/spec/expectations/should_spec.rb index b8bda8f8..eada033d 100644 --- a/spec/expectations/should_spec.rb +++ b/spec/expectations/should_spec.rb @@ -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 @@ -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 @@ -52,10 +56,10 @@ end it "prints out a summary" do - @out.should include "0 files, 8 examples, 6 expectations, 4 failures, 0 errors" + @out.should include "0 files, 9 examples, 7 expectations, 4 failures, 0 errors" end it "records expectations" do - @out.should include "I was called 6 times" + @out.should include "I was called 7 times" end end From 45bac48a33430b9a34fc38964669820acd85c13d Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Sun, 6 Dec 2020 20:21:31 +0200 Subject: [PATCH 2/2] Use `MSpec.deprecate` helper --- lib/mspec/expectations/should.rb | 2 +- spec/expectations/should_spec.rb | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/mspec/expectations/should.rb b/lib/mspec/expectations/should.rb index 047b05ce..ce0852a1 100644 --- a/lib/mspec/expectations/should.rb +++ b/lib/mspec/expectations/should.rb @@ -24,7 +24,7 @@ def should_not(matcher = NO_MATCHER_GIVEN) MSpec.actions :expectation, state if RaiseErrorMatcher === matcher - $stderr.puts "\nDeprecation: ->{}.should_not raise_error breaks code style and is deprecated" + MSpec.deprecate('->{}.should_not raise_error', 'a matcher to verify the result') end if NO_MATCHER_GIVEN.equal?(matcher) diff --git a/spec/expectations/should_spec.rb b/spec/expectations/should_spec.rb index eada033d..141d2fbf 100644 --- a/spec/expectations/should_spec.rb +++ b/spec/expectations/should_spec.rb @@ -5,8 +5,8 @@ before :all do path = RbConfig::CONFIG['bindir'] exe = RbConfig::CONFIG['ruby_install_name'] - file = File.dirname(__FILE__) + '/should.rb 2>&1' - @out = `#{path}/#{exe} #{file}` + file = File.dirname(__FILE__) + '/should.rb' + @out = `#{path}/#{exe} #{file} 2>&1` end describe "#should" do @@ -47,7 +47,8 @@ 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" + @out.should include "->{}.should_not raise_error is deprecated, use a matcher to verify the result instead." + @out.should =~ /from .+spec\/expectations\/should.rb:75:in `block \(2 levels\) in
'/ end end