Today I Learned

2 posts by przemekpełszyński

Different values with every call from stubbed method

Today I needed to get two different responses from called client to test it. To do this you just stub method classic way but you provide multiple arguments:

allow(Service).to receive(:call).and_return('1', '2')

When service is called for first time it returns '1' and for second time it’s returning '2'.

It also works with WebMock :

stub_request(:get, "").to_return({body: "abc"}, {body: "def"})

Find real error messages in Rails

Today after messing with some gems I wanted to run rspec but i was getting strange error

  can't modify frozen Array

Failure/Error: require File.expand_path('../config/environment', __dir__)

I tried to find solution in Google but those weren’t working. I found that running bundle exec rails c reveals true error messages. In my case I got this after running this command:

JSONAPI: Could not find resource 'api/v1/creators'. (Class Api::V1::CreatorResource not found) (NameError)

And I was finally able to solve this problem :)