Je dois tester le type d'argument passé est un nombre entier. Voici mon spec test:RSpec comment tester un type de données d'argument passé à une méthode
require 'ball_spin'
RSpec.describe BallSpin do
describe '#create_ball_spin' do
subject(:ball_spin) { BallSpin.new }
it 'should accept an integer argument' do
expect(ball_spin).to receive(:create_ball_spin).with(an_instance_of(Integer))
ball_spin.create_ball_spin(5)
end
end
end
Mon code:
class BallSpin
def create_ball_spin n
"Created a ball spin #{n} times" if n.is_a? Integer
end
end
Merci à l'avance
MISE À JOUR:
Apologize pour l'utilisation de l'ancienne syntaxe RSpec, ci-dessous, je mis à jour mon code pour utiliser la dernière:
it 'should accept an integer argument' do
expect(ball_spin).to receive(:create_ball_spin).with(an_instance_of(Integer))
ball_spin.create_ball_spin(5)
end
Salut, merci pour répondre, je suis une erreur NoMethodError: méthode non définie recevoir » pour #
@Kris MP, quelle version de Rspec vous utilisez? –