I find myself wanting to do something like this, and I'm curious to hear 
other opinions on this pattern.

describe "a hash with two values" do
  let(:hsh) {{ xxx: 1, yyy: 2 }}

  context "with a third value added" do
    alias _hsh hsh
    let(:hsh) { _hsh.merge(zzz: 3) }

    it "should contain all three values" do
      hsh.should == { xxx:1, yyy:2, zzz:3 }
    end
  end
end


The alternative would be to use a before block, but I dislike the mixing of 
let and before in this case. On the other hand the alias doesn't look that 
clean either. 

describe "a hash with two values" do
  let(:hsh) {{ xxx: 1, yyy: 2 }}

  context "with a third value added" do
    before { hsh.merge!(zzz: 3) }

    it "should contain all three values" do
      hsh.should == { xxx:1, yyy:2, zzz:3 }
    end
  end
end


Ideally I'd like to be able to simply reference the previous implementation 
when in the defining block, let(:hsh) { hsh.merge(zzz:3) }.

Are there better ways to do this? Would you consider this an anti-pattern?

- Arne

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msg/rspec/-/cZlaDWPn0UoJ.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to