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
{{ message }}
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.
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.
require_relative"./cloner"describeClonerdolet(:cloner){Cloner.new}let(:orig_ah){[{a: "A"},{b: "B"}]}let(:cloned_ah){cloner.clone_array_of_hashes(orig_ah)}it"passes"docloned_ah[0]#this is the only difference between the two testsorig_ah[0][:a]="AA"expect(orig_ah[0]).to_noteq(cloned_ah[0])endit"fails but should pass"doorig_ah[0][:a]="AA"expect(orig_ah[0]).to_noteq(cloned_ah[0])endend
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.
The text was updated successfully, but these errors were encountered:
This isn't a bug - let variables are lazily instantiated, so in your failing test cloned_ah is instantiated after you modify orig_ah. If you need to control the order of instantiation you should probably be explicit about the ordering using a before block.
Alternately you could probably get away with using let! for cloned_ah, which is functionally equivalent to initializing it in a before block.
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
File:
cloner_spec.rb
Notes:
cloned_ah
instaed ofcloned_ah[0]
works to pass the test as well.clone
ordup
is usedThe 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.
The text was updated successfully, but these errors were encountered: