Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
$stderr.puts "\nDeprecation: ->{}.should_not raise_error breaks code style and is deprecated"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should show the caller here, so it's easy to know where it comes from.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use MSpec.deprecate (

def self.deprecate(what, replacement)
)?
That will automatically include the caller.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replacement can be e.g. "a matcher to verify the result"

Copy link
Member Author

@andrykonchin andrykonchin Dec 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, will try. I saw this helper but decided not to use it because it has a little bit different purpose - to notify about changing in API or DSL. But here we have a code style issue.

Nevertheless it should work well for our case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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
10 changes: 7 additions & 3 deletions spec/expectations/should_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It prevents running MSpec specs on Windows. Not sure whether it's important.

It would be a little more difficult to check STDERR of the command in this test. Another option is to write a deprecation message to STDOUT instead of STDERR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 2>&1 might actually work on Windows, could you move it to the line below though, so file is still an actual file?

@out = `#{path}/#{exe} #{file}`
end

Expand Down Expand Up @@ -45,17 +45,21 @@
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
@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