cmp different from the string representation
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Ruby
- Sterne
- 32
- Forks
- 24
- Ø Merge
- 13 Std. 2 Min.
- Gemergte PRs (30 T.)
- 1
Beschreibung
There's an ordering difference when using the built-in <=> vs the string representation one:
> Pathname.new(File.expand_path('.')).glob('**/*.rb').sort.first(5)
=> [#<Pathname:/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance/chain.rb>,
#<Pathname:/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance/error_generator.rb>,
#<Pathname:/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance/expect_chain_chain.rb>,
#<Pathname:/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance/expectation_chain.rb>,
#<Pathname:/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance/message_chains.rb>]
> Pathname.new(File.expand_path('.')).glob('**/*.rb').sort_by(&:to_s).first(5)
=> [#<Pathname:/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks.rb>,
#<Pathname:/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance.rb>,
#<Pathname:/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance/chain.rb>,
#<Pathname:/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance/error_generator.rb>,
#<Pathname:/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance/expect_chain_chain.rb>]
And the latter corresponds to the classic alternative:
> Dir[File.expand_path('**/*.rb')].sort.first(5)
=> ["/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks.rb",
"/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance.rb",
"/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance/chain.rb",
"/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance/error_generator.rb",
"/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance/expect_chain_chain.rb"]
Just by looking at the cmp implementation and tests I couldn't understand, is this the designed behaviour, or the behaviour is undefined?
Semantically, it would make sense to load rspec/mocks.rb first, and then rspec/mocks/any_instance.rb, not the other way around.
Some discussion in rspec-rails regarding the issues it may cause.
rspec-rails PR to change the helper template to use Pathname#glob instead of Dir.[].
A workaround rspec-rails plans to take is to sort_by(&:to_s) to get back to the string representation-like ordering.
(semi-)Related cops:
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Lesen Sie die cmp-Implementierung in ext/pathname/pathname.c und die zugehörigen Fälle in test/pathname/test_pathname.rb, und reproduzieren Sie die im Issue beschriebenen unterschiedlichen Ergebnisse der Pathname#<=>- und String-Reihenfolge. Die Aufgabe ist erledigt, wenn das beabsichtigte Ordnungsverhalten festgestellt ist und die relevanten Tests oder die Dokumentation dieses Ergebnis eindeutig widerspiegeln.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- ruby
- Bereich
- operating-systems
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 35/100