Skip to content

Commit 95a2dcf

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

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

Diff for: 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

Diff for: 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

Diff for: spec/expectations/should_spec.rb

+7-3
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,17 +45,21 @@
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
5155
@out.should include ".FF..FF."
5256
end
5357

5458
it "prints out a summary" do
55-
@out.should include "0 files, 8 examples, 6 expectations, 4 failures, 0 errors"
59+
@out.should include "0 files, 9 examples, 7 expectations, 4 failures, 0 errors"
5660
end
5761

5862
it "records expectations" do
59-
@out.should include "I was called 6 times"
63+
@out.should include "I was called 7 times"
6064
end
6165
end

0 commit comments

Comments
 (0)