lyang / braintree-rails

MIT License
65 stars 22 forks source link

Stubbing BraintreeRails::Persistence's #find then #new makes #new hang indefinitely #24

Closed n0nick closed 9 years ago

n0nick commented 10 years ago

This was a very difficult and strange problem to track down. I managed to create the following minimal test case:

require 'active_model'
require 'braintree_rails/persistence'

class Bob
  include BraintreeRails::Persistence
end

describe 'the problem' do
  it 'stubs "new"' do
    allow(Bob).to receive(:new)
  end

  it 'stubs "find"' do
    allow(Bob).to receive(:find)
  end

  it 'gets stuck' do
    Bob.new
  end
end

When you run this test using

$ rspec a_spec.rb --order defined

The third it block simply gets stuck when running Bob.new. It seems that the stubbing (in this particular order) creates some infinite loop in BraintreeRails::Persistence#find.

Adding the following lines to the describe block fixes the issue:

  after :each do
    allow(Bob).to receive(:new).and_call_original
  end

This is as far as I got on my own :) Let me know if you have any pointers, or if there's something else I can do.

lyang commented 10 years ago

Thank you for reporting this, @n0nick ! Apologize in advance that I won't be able to look at it right away. I'm crazy busy this and next week. But I'll definitely look at it when time allows. Thanks!

lyang commented 10 years ago

Hi @n0nick , I tried RSpec version 3.1.4 and 3.1.7 with ruby-2.0.0-p353 on OS X 10.9.5, against the master branch but couldn't reproduce it. What environment are you testing against? Do you mind clone this repo and try the same test in a fresh and clean env?

Thanks!

n0nick commented 9 years ago

I can't reproduce this either now (RSpec 3.3.1, Ruby 2.0.0-p594, OS X 10.10.4), so I'll close this.

Sorry it took me so long to response :) Thx!

lyang commented 9 years ago

Glad to hear it disappeared :)