On Tue, 12 Apr 2011 08:39:57 -0700, Markus Roberts wrote:
> 
> I'm currrently looking at the specs for the ssh_authorized_key provider.
> >> There are two tests that give me a headache:
> >>
> >>    it "should create the directory if it doesn't exist" do
> >>      File.stubs(:exist?).with(@dir).returns false
> >>      Dir.expects(:mkdir).with(@dir,0700)
> >>      @provider.flush
> >>    end
> >>
> >>    it "should not create or chown the directory if it already exist" do
> >>      File.stubs(:exist?).with(@dir).returns false
> >>      Dir.expects(:mkdir).never
> >>      @provider.flush
> >>    end
> >>
> >> Both tests stub exist? to return false (which is obviously wrong in the
> >> second case) but both tests are expecting different results. Nevertheless
> >> both tests will pass. Am I overlooking something? How can this happen?
> >>
> >
> > Wow.  I'll deffer to Luke on the "what to do about it" issue but apart from
> > that this look like another rspec bug (along the lines of the
> > be_any/all/none... bug, http://www.ruby-forum.com/topic/197643) but I'm
> > not seeing the mechanism off the top of my head.
> >
> > It's probably worth figuring out if only to identify other tests that might
> > not be doing what they look like,
> >
> 
> It looks like 1) the tests are stubbing Dir.mkdir and 2) expects are
> silently ignored on stubs so 3) the problematic lines simply aren't doing
> what they look like.
> 

If Dir.mkdir is being stubbed, then this is almost certainly the
problem.  I ran into this scenario recently, which was the entire reason
for removing the stubbing of save_last_run_summary in
http://projects.puppetlabs.com/issues/4339#note-20

Expecting a stubbed method never wasn't working, however expecting a
stubbed method >= once behaved as expected.  Definitely an rspec bug.

-- 
Jacob Helwig

Attachment: signature.asc
Description: Digital signature

Reply via email to