diff --git a/lib/mspec/expectations/should.rb b/lib/mspec/expectations/should.rb index ca061748..ce0852a1 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 + MSpec.deprecate('->{}.should_not raise_error', 'a matcher to verify the result') + 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..141d2fbf 100644 --- a/spec/expectations/should_spec.rb +++ b/spec/expectations/should_spec.rb @@ -6,7 +6,7 @@ path = RbConfig::CONFIG['bindir'] exe = RbConfig::CONFIG['ruby_install_name'] file = File.dirname(__FILE__) + '/should.rb' - @out = `#{path}/#{exe} #{file}` + @out = `#{path}/#{exe} #{file} 2>&1` end describe "#should" do @@ -45,6 +45,11 @@ 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 "->{}.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 it "prints status information" do @@ -52,10 +57,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