Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate usage of should_not raise_error #50

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
MSpec.deprecate('->{}.should_not raise_error', 'a matcher to verify the result')
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
11 changes: 8 additions & 3 deletions spec/expectations/should_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -45,17 +45,22 @@
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 <main>'/
end
end

it "prints status information" do
@out.should include ".FF..FF."
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