I’m seeing unusual behavior when i place an "expect().to receive” on an element of a struct. Specifically, with the following code:
describe 'test example of struct' do let!(:subscription) { Sub = Struct.new(:canceled_at) ; Sub.new(canceled_at: 2.weeks.from_now) } it 'behaves okay with no expectation set' do value = 2.weeks.ago subscription.canceled_at = value puts subscription.inspect expect(subscription.canceled_at).to eq value end it 'misbehaves if I place an expecation on the element' do expect(subscription).to receive(:canceled_at) value = 2.weeks.ago subscription.canceled_at = value puts subscription.inspect expect(subscription.canceled_at).to eq value end end Here is the result of running those examples: Run options: include {:locations=>{"./spec/models/user/stripe_customer_spec.rb"=>[362]}} #<struct Sub canceled_at=Thu, 11 Feb 2021 21:24:19 UTC +00:00> ./Users/jackrg/Documents/Novelty-Stats/spec/models/user/stripe_customer_spec.rb:363: warning: already initialized constant Sub /Users/jackrg/Documents/Novelty-Stats/spec/models/user/stripe_customer_spec.rb:363: warning: previous definition of Sub was here #<struct Sub canceled_at=Thu, 11 Feb 2021 21:24:19 UTC +00:00> F Failures: 1) User::StripeCustomer test example of struct misbehaves if I place an expecation on the element Failure/Error: expect(subscription.canceled_at).to eq value expected: 2021-02-11 21:24:19.601491000 +0000 got: nil (compared using ==) # ./spec/models/user/stripe_customer_spec.rb:377:in `block (3 levels) in <top (required)>' Finished in 0.0432 seconds (files took 7.91 seconds to load) 2 examples, 1 failure The only difference between the two examples is the addition of the highlights line in the second example. That expectation causes the retrieval process to not work, returning nil instead of the current value (or even the initial value). Is this a known issue? I can’t find it documented anywhere. -- You received this message because you are subscribed to the Google Groups "rspec" group. To unsubscribe from this group and stop receiving emails from it, send an email to rspec+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/0ED673A5-17B0-4C3B-9E0B-9C0E862279BB%40pobox.com.