Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

AmbiguousDemonstrationError when incorrectly using of_next vs replace and class has matching instance method

Aperta
#10 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
ruby
Ambito
testing

Direzione di ricerca

Run the ambiguous.rb reproduction and trace how Mocktail.of_next, Mocktail.replace, stubs, and verify determine mocked invocations. Compare the handling of matching class and instance methods; done means the incorrect demonstration reports that no mocked invocation is available, rather than raising AmbiguousDemonstrationError.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Given a class which has matching instance and class methods, if a test incorrectly calls Mocktail.of_next instead of Mocktail.replace then tries to demonstrate a call to the method, this error is raised:

`stubs` & `verify` expect exactly one invocation of a mocked method, but 2 were detected.
As a result, Mocktail doesn't know which invocation to stub or verify. 
(Mocktail::AmbiguousDemonstrationError)

I'd expect there to be 0 invocations detected, but even better I'd love to be told that I'm not demonstrating using anything that's been mocked yet.

Here's a basic reproduction:

ambiguous.rb:

require "mocktail"

class Fighter
  def self.weapon
    new.weapon
  end

  def weapon
    "sword"
  end
end

Mocktail.of_next(Fighter)

Mocktail.stubs { Fighter.weapon }.with { nil }

$ ruby ambiguous.rb

Lingua principale
Ruby
Stelle
276
Fork
12
Merge medio
2m
PR unite (30g)
3

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.