Rspec does not work with "bad value for range"

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 does not work with the message ArgumentError: bad value for range

But if I pass "desc" or "asc" and change the wait, it will work fine.

I also tried this on irb, just passing swap (''), it gives me "asc" not sure why rspec is not working

0
source share
1 answer

Try to be 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 
+2
source

Source: https://habr.com/ru/post/972934/


All Articles