This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Description
When doing a customized deep clone, I ran across a situation where the test will fail unless the variable assigned by let is called first (see the spec code below).
The cloning does work, but the normal test case fails.
Code to reproduce:
File: cloner.rb
class Cloner
def clone_array_of_hashes(a)
a.map{|h| h.clone}
end
end
File: cloner_spec.rb
require_relative "./cloner"
describe Cloner do
let(:cloner) {Cloner.new}
let(:orig_ah) { [{a: "A"},{b: "B"}] }
let(:cloned_ah) { cloner.clone_array_of_hashes(orig_ah) }
it "passes" do
cloned_ah[0] #this is the only difference between the two tests
orig_ah[0][:a] = "AA"
expect(orig_ah[0]).to_not eq(cloned_ah[0])
end
it "fails but should pass" do
orig_ah[0][:a] = "AA"
expect(orig_ah[0]).to_not eq(cloned_ah[0])
end
end
Notes:
- Invoking
cloned_ah instaed of cloned_ah[0] works to pass the test as well.
- The issue exists whether
clone or dup is used
The issue occurs with RSpec 2.14 and 2.12, and Ruby 1.9.3 and 2.0.0
I had a similar issue a while ago with regexes (#820) with the variable needing to be invoked first, but I'm not sure if the similarities extend beyond that.