On Fri, Aug 14, 2009 at 10:35 AM, Denis Haskin<denis at
haskinferguson.net> wrote:>
> (in application_helper_spec.rb)
> ??? it "should return false and set the cookie to true if it is not
set" do
> ????? cookies[:fp_skip_hp_video].should == nil
> ????? skip_hp_video.should == false
> ????? cookies[:fp_skip_hp_video].should include({:value => true})
> ??? end
Theory: I don''t know the RSpec internals well enough to say for sure,
but the fact that you''re testing cookies[] twice in one example looks
weird to me. If the cookies[] RSpec helper is memoizing a shallow
copy of the real cookies object the first time you access it, then
your second call to it isn''t going to reflect any changes.
I''d suggest splitting this out into multiple examples. Test the
initial cookie state, test the result of your method call, and then
test the final cookie state (which implies calling the method again in
that example, but not testing it.) I can''t guarantee it''d
solve your
problem, but it''s worth trying.
This is more a matter of style than necessity, but I personally try
not to have more than one "should" or expectation per example. It
makes for more verbose testing, but also clearer testing. As a fringe
benefit, it also reinforces a coding style where side effects of
methods are kept to a minimum, and where blocks of code do Just One
Thing to the fullest practical extent. (I.e., clearer and more
maintainable code.) >8->
--
Have Fun,
Steve Eley (sfeley at gmail.com)
ESCAPE POD - The Science Fiction Podcast Magazine
http://www.escapepod.org