我需要测试传入的参数类型是一个整数。这里是我的测试规范:RSpec如何测试传递给方法的参数数据类型
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
我的代码:
class BallSpin
def create_ball_spin n
"Created a ball spin #{n} times" if n.is_a? Integer
end
end
在此先感谢
UPDATE:
道歉使用旧RSpec的语法,下面我更新了我的代码使用最新的:
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
谢谢回答,我得到了一个错误NoMethodError你好:未定义的方法'收到”为#
@Kris MP,您使用的是什么版本Rspec的呢? –