我有这样的代码
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
把这行放到你的initialize
方法中:
raise ArgumentError if sides < 1