Rspec fails with “bad value for range”

假如想象 提交于 2020-01-06 15:13:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!