Skip to content

Commit eafaf6e

Browse files
committed
Deprecate usage of should_not raise_error
1 parent b58e665 commit eafaf6e

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

lib/mspec/expectations/should.rb

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ def should_not(matcher = NO_MATCHER_GIVEN)
2323
raise "should_not outside example" unless state
2424
MSpec.actions :expectation, state
2525

26+
if RaiseErrorMatcher === matcher
27+
$stderr.puts "\nDeprecation: ->{}.should_not raise_error breaks code style and is deprecated"
28+
end
29+
2630
if NO_MATCHER_GIVEN.equal?(matcher)
2731
SpecNegativeOperatorMatcher.new(self)
2832
else

spec/expectations/should.rb

+4
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,8 @@ def finish
7070
it "invokes the MSpec :expectation actions" do
7171
1.should_not == 2
7272
end
73+
74+
it "deprecates using `{}.should_not raise_error`" do
75+
-> { }.should_not raise_error
76+
end
7377
end

spec/expectations/should_spec.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
before :all do
66
path = RbConfig::CONFIG['bindir']
77
exe = RbConfig::CONFIG['ruby_install_name']
8-
file = File.dirname(__FILE__) + '/should.rb'
8+
file = File.dirname(__FILE__) + '/should.rb 2>&1'
99
@out = `#{path}/#{exe} #{file}`
1010
end
1111

@@ -45,6 +45,10 @@
4545
No behavior expectation was found in the example
4646
EOS
4747
end
48+
49+
it 'prints a deprecation message about using `{}.should_not raise_error`' do
50+
@out.should include "Deprecation: ->{}.should_not raise_error breaks code style and is deprecated"
51+
end
4852
end
4953

5054
it "prints status information" do

0 commit comments

Comments
 (0)