You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a method which receives a non-empty array. I call array.clear after the method is called, but the expectation seems to believe the method was called with an empty array.
class TestClass
def test_method_1(string)
array = []
array << string
test_method_2(array)
array.clear
end
def test_method_2(array); end
end
RSpec.describe TestClass do
let(:test_class) { TestClass.new }
let(:test_string) { 'some string' }
it "method 1 calls method 2 with array" do
allow(test_class).to receive(:test_method_2).with([test_string])
test_class.test_method_1(test_string)
expect(test_class).to have_received(:test_method_2).with([test_string])
end
end
The text was updated successfully, but these errors were encountered:
Congratulations, you found a bug! This is happening because the array is being mutated and we're not preventing that. See rspec/rspec-mocks#1183, closing as this is an rspec-mocks issue.
I have a method which receives a non-empty array. I call array.clear after the method is called, but the expectation seems to believe the method was called with an empty array.
The text was updated successfully, but these errors were encountered: