iA


Bundle update causes havoc

by Administrator. Average Reading Time: less than a minute.

You know the feeling – you do a quick “bundle update” and all hell breaks loose? I knew you do.

I updated rspec from 2.5 to 2.6 in one of my projects, and it also updated the nifty faker gem we use for generating test data.

Of course, this broke a couple of hundred tests with the following message:


NoMethodError:
       private method `rand' called for ["DE", "FR", "IT", "AT"]:Array

I used to select a random country from an array, like thus:


Address.blueprint do
  address_1 { Faker::Address.street_address }
  address_2 { Faker::Address.secondary_address }
  city { Faker::Address.city }
  country { %w{ DE FR IT AT }.rand }
  postal_code { Faker::Address.zip_code }
  state { "new" }
end

A bit of looking at the faker gems source code, showed me the error of my ways. I shouldn’t use the rand method, but either choice or sample instead.

Here’s the code that works:


Address.blueprint do
  address_1 { Faker::Address.street_address }
  address_2 { Faker::Address.secondary_address }
  city { Faker::Address.city }
  country { %w{ DE FR IT AT }.sample }
  postal_code { Faker::Address.zip_code }
  state { "new" }
end

No comments on ‘Bundle update causes havoc’

Leave a Reply