我试图测试这种方法,该方法可以只是把整数作为参数,但我不能使它的工作;不幸。 感谢你的时间。 我不理解这一错误日志:使用kind_of?与红宝石Rspec
1)DownloadingData interval_data需要2个整数作为参数来设置的时间间隔 故障/错误:bag.should_receive(:interval_data)。随着(2,kind_of(数字) (#),kind_of?(Numeric),2) (#)。interval_data(2,#,false,2) 预计:1次带参数:(2,#,false,2) 收到0次带参数:(2,#,假的,2)
我的代码:
class DownloadingData
attr_accessor :today
def initialize
@today = Date.today
end
def interval_data(point_a, point_b)
start_point = @today - point_a
end_point = @today + point_b
(start_point..end_point).each do |week_day|
puts week_day #checking the week day
end
end
end
我的测试:
describe DownloadingData do
let(:bag) { DownloadingData.new }
describe 'interval_data' do
it 'responds to interval_data' do
expect(bag).to respond_to(:interval_data)
end
it 'takes 2 integers as parameters to set up the time-interval' do
bag.should_receive(:interval_data).with(2, kind_of(Numeric), kind_of?(Numeric), 2)
end
end
你可能不想在这里使用should_receive。而是调用方法并指定返回值应该是什么(或者应该发生什么样的副作用) – 2014-09-22 16:44:20