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

Add specs for Coverage.supported? #1039

Merged
merged 1 commit into from
May 25, 2023
Merged
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
32 changes: 32 additions & 0 deletions library/coverage/supported_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require_relative '../../spec_helper'
require 'coverage'

describe "Coverage.supported?" do
ruby_version_is "3.2" do
it "returns true or false if coverage measurement is supported for the given mode" do
[true, false].should.include?(Coverage.supported?(:lines))
[true, false].should.include?(Coverage.supported?(:branches))
[true, false].should.include?(Coverage.supported?(:methods))
[true, false].should.include?(Coverage.supported?(:eval))
end

it "returns false for not existing modes" do
Coverage.supported?(:foo).should == false
Coverage.supported?(:bar).should == false
end
Copy link
Member

@andrykonchin andrykonchin May 24, 2023

Choose a reason for hiding this comment

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

I meant something like this:

[true, false].should.include?(Coverage.supported?(:lines))

or

(Coverage.supported?(:lines) == true || Coverage.supported?(:lines) == false).should == true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For arbitrary Symbols that are not lines, branches, methods nor eval it should always return false?

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 so.


it "raise TypeError if argument is not Symbol" do
-> {
Coverage.supported?("lines")
}.should raise_error(TypeError, "wrong argument type String (expected Symbol)")

-> {
Coverage.supported?([])
}.should raise_error(TypeError, "wrong argument type Array (expected Symbol)")

-> {
Coverage.supported?(1)
}.should raise_error(TypeError, "wrong argument type Integer (expected Symbol)")
end
end
Copy link
Member

@andrykonchin andrykonchin May 23, 2023

Choose a reason for hiding this comment

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

minor: It's kind of feature discovering mechanism so it doesn't make sense to require in specs some specific result (true or false).

IMHO the only thing that could be checked is that this method:

  • returns true or false (for existing modes and arbitrary Symbols)
  • converts its argument to Symbol

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does it converts argument to Symbol? Isn't it raising an error?

Copy link
Member

Choose a reason for hiding this comment

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

TBH I haven't checked. I meant handling of not Symbol arguments in general.

end