我有这段代码
require_relative 'die'
describe Die do
describe '#initialize' do
it 'expects a single argument' do
expect(Die.instance_method(:initialize).arity).to eq 1
end
it 'raises ArgumentError if sides are < 1' do
expect { #####line 10
Die.new(-1)
}.to raise_error(ArgumentError)
expect {
Die.new(0)
}.to raise_error(ArgumentError)
end
end
我收到以下错误
> Die#initialize raises ArgumentError if sides are < 1
Failure/Error: expect {
expected ArgumentError but nothing was raised
# ./spec.rb:10:in `block (3 levels) in <top (required)>'
我已标记第10行。可以帮助我删除此错误吗?
这是我的DIE课程
class Die
def initialize(sides)
end
def num_of_sides()
end
def roll()
end
end
答案 0 :(得分:4)
将此行放在initialize
方法中:
raise ArgumentError if sides < 1