Skip to content

Instantly share code, notes, and snippets.

@a-leung
Created February 8, 2016 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-leung/c960d220a3528f4c7c7b to your computer and use it in GitHub Desktop.
Save a-leung/c960d220a3528f4c7c7b to your computer and use it in GitHub Desktop.
rspec mocking issue
def refund
self.items
ActiveRecord::Base.transaction do
self.items.each { |i| i.update!(refund: true) }
end
end
def refund_v2
refundable_items = self.items.where(refund: false)
ActiveRecord::Base.transaction do
refundable_items.each { |i| i.update!(refund: true) }
end
end
self.items.first.stub(:create_or_update).and_return false
expect(refund).to eq false # passes
expect(refund_v2).to eq false # fails
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment