Fixes #166. See that issue for the relevant context.
Upon studying the definition of MIME::Type#eql?, I determined that we shouldn't include self.class in the hash. #eql? uses an #is_a? check, which will succeed even on subclasses of MIME::Type. So #eql? doesn't require self and other be of the exact same class. If we were to include self.class in the hash, then it would erroneously make the hashes different for two #eql? objects of different classes (since different classes generally hash to different values). I added an extra test around MIME::Type#eql? to codify this behavior. While I was in there, I also fixed a typo in an existing MIME::Type#eql? test. π
Note that there aren't many generic tests we can make around #hash itself. Even two distinct MIME::Type instances could still hash to the same value, in principle. So there are only really tests around instances that should be #eql? to each other.
One clue we have that this PR addresses the randomness of warnings seen in #163 is when I run rake with/without these changes locally. :)
On main, I see no warnings about the duplicate application/netcdf data, because the Set treats the two instances as distinct (unless we get lucky, which has also happened to me intermittently):
On the topic branch, I see all the warnings βΌοΈ now that the two instances hash the same:
With hash definition
```console
$ git branch
* define-mime-type-hash
main
$ rake
Type application/netcdf is already registered as a variant of application/netcdf.
Run options: --seed 24550
# Running:
.......Type application/netcdf is already registered as a variant of application/netcdf.
.Type application/netcdf is already registered as a variant of application/netcdf.
.Type application/netcdf is already registered as a variant of application/netcdf.
.Type application/netcdf is already registered as a variant of application/netcdf.
.Type application/netcdf is already registered as a variant of application/netcdf.
............................Type application/netcdf is already registered as a variant of application/netcdf.
.................Type application/netcdf is already registered as a variant of application/netcdf.
.Type application/netcdf is already registered as a variant of application/netcdf.
.Type application/netcdf is already registered as a variant of application/netcdf.
.Type application/netcdf is already registered as a variant of application/netcdf.
.Type application/netcdf is already registered as a variant of application/netcdf.
.Type application/netcdf is already registered as a variant of application/netcdf.
.Type application/netcdf is already registered as a variant of application/netcdf.
.Type application/netcdf is already registered as a variant of application/netcdf.
................Type application/netcdf is already registered as a variant of application/netcdf.
.Type application/netcdf is already registered as a variant of application/netcdf.
.Type application/netcdf is already registered as a variant of application/netcdf.
.Type application/netcdf is already registered as a variant of application/netcdf.
........Type application/netcdf is already registered as a variant of application/netcdf.
.Type application/netcdf is already registered as a variant of application/netcdf.
.Type application/netcdf is already registered as a variant of application/netcdf.
.Type application/netcdf is already registered as a variant of application/netcdf.
.Type application/netcdf is already registered as a variant of application/netcdf.
.Type application/netcdf is already registered as a variant of application/netcdf.
.........Type application/netcdf is already registered as a variant of application/netcdf.
Type application/netcdf is already registered as a variant of application/netcdf.
...............................................
Finished in 3.228527s, 46.7706 runs/s, 92.3022 assertions/s.
151 runs, 298 assertions, 0 failures, 0 errors, 0 skips
rm -rf doc
rm -r pkg
```
Fixes #166. See that issue for the relevant context.
Upon studying the definition of
MIME::Type#eql?
, I determined that we shouldn't includeself.class
in the hash.#eql?
uses an#is_a?
check, which will succeed even on subclasses ofMIME::Type
. So#eql?
doesn't requireself
andother
be of the exact same class. If we were to includeself.class
in the hash, then it would erroneously make the hashes different for two#eql?
objects of different classes (since different classes generally hash to different values). I added an extra test aroundMIME::Type#eql?
to codify this behavior. While I was in there, I also fixed a typo in an existingMIME::Type#eql?
test. πNote that there aren't many generic tests we can make around
#hash
itself. Even two distinctMIME::Type
instances could still hash to the same value, in principle. So there are only really tests around instances that should be#eql?
to each other.One clue we have that this PR addresses the randomness of warnings seen in #163 is when I run
rake
with/without these changes locally. :)On main, I see no warnings about the duplicate
application/netcdf
data, because theSet
treats the two instances as distinct (unless we get lucky, which has also happened to me intermittently):Without hash definition
```console $ git branch define-mime-type-hash * main $ rake Run options: --seed 63590 # Running: ................................................................................................................................................... Finished in 2.143452s, 68.5810 runs/s, 137.1619 assertions/s. 147 runs, 294 assertions, 0 failures, 0 errors, 0 skips rm -rf doc rm -r pkg ```On the topic branch, I see all the warnings βΌοΈ now that the two instances hash the same:
With hash definition
```console $ git branch * define-mime-type-hash main $ rake Type application/netcdf is already registered as a variant of application/netcdf. Run options: --seed 24550 # Running: .......Type application/netcdf is already registered as a variant of application/netcdf. .Type application/netcdf is already registered as a variant of application/netcdf. .Type application/netcdf is already registered as a variant of application/netcdf. .Type application/netcdf is already registered as a variant of application/netcdf. .Type application/netcdf is already registered as a variant of application/netcdf. ............................Type application/netcdf is already registered as a variant of application/netcdf. .................Type application/netcdf is already registered as a variant of application/netcdf. .Type application/netcdf is already registered as a variant of application/netcdf. .Type application/netcdf is already registered as a variant of application/netcdf. .Type application/netcdf is already registered as a variant of application/netcdf. .Type application/netcdf is already registered as a variant of application/netcdf. .Type application/netcdf is already registered as a variant of application/netcdf. .Type application/netcdf is already registered as a variant of application/netcdf. .Type application/netcdf is already registered as a variant of application/netcdf. ................Type application/netcdf is already registered as a variant of application/netcdf. .Type application/netcdf is already registered as a variant of application/netcdf. .Type application/netcdf is already registered as a variant of application/netcdf. .Type application/netcdf is already registered as a variant of application/netcdf. ........Type application/netcdf is already registered as a variant of application/netcdf. .Type application/netcdf is already registered as a variant of application/netcdf. .Type application/netcdf is already registered as a variant of application/netcdf. .Type application/netcdf is already registered as a variant of application/netcdf. .Type application/netcdf is already registered as a variant of application/netcdf. .Type application/netcdf is already registered as a variant of application/netcdf. .........Type application/netcdf is already registered as a variant of application/netcdf. Type application/netcdf is already registered as a variant of application/netcdf. ............................................... Finished in 3.228527s, 46.7706 runs/s, 92.3022 assertions/s. 151 runs, 298 assertions, 0 failures, 0 errors, 0 skips rm -rf doc rm -r pkg ```This change isβ