Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

No need for !! here. #2295

Merged
merged 1 commit into from
Jul 18, 2016
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
2 changes: 1 addition & 1 deletion lib/rspec/core/metadata_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def filter_applies?(key, filter_value, metadata)

meta_value = metadata.fetch(key) { return false }

return true if TrueClass === filter_value && !!meta_value
return true if TrueClass === filter_value && meta_value
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated, but Is there a reason why this isn't filter_value == true?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because filter_value could be anything, and we can't count on it's == being defined properly. We've repeatedly gotten bug reports from users when we've called == on their objects where they defined == to assume the passed object was of the same type, and tried to access specific attributes on it that did not exist. Calling a method on TrueClass instead of filter_value avoids that issue.

It could be true == filter_value but TrueClass === is in keeping with the style of the rest of the method which repeatedly uses SomeClass === value.

return proc_filter_applies?(key, filter_value, metadata) if Proc === filter_value
return filter_applies_to_any_value?(key, filter_value, metadata) if Array === meta_value

Expand Down