问题
My method:
def swap (order)
order = order == 'asc' ? 'desc' : 'asc'
end
Spec:
let(:order) { 'wrong_order'}
it 'swaps the order' do
expect(swap(order)).to eq('asc')
end
This rspec is failing with the message ArgumentError: bad value for range
But if i pass 'desc' or 'asc' and change the expect it works fine.
Also i tried this on irb with just passing swap(' ') it gives me 'asc' not sure why rspec is failing
回答1:
Try being a bit more explicit with the test:
let(:order) { 'wrong_order'}
it 'swaps the order' do
swapped_order = swap(order)
expect(swapped_order).to eq('asc')
end
来源:https://stackoverflow.com/questions/20200655/rspec-fails-with-bad-value-for-range