Stubbing of block style guards seems to work for me:
before do
allow(File).to receive(:exists?).and_call_original
allow(File).to receive(:exists?).with('/tmp/guard').and_return(true)
end
But that was not this issue I was describing. I was wondering if
there was a way to run some code after the runner processed
“execute[refresh]” but before “execute[reconfigure]”.
Joe
On Oct 29, 2014, at 4:17 PM, Ranjib Dey
<
<mailto: >>
wrote:
chefspec does not allow stubbing block style guards, it does allow
command / string style gurards. If you change the guard to use `test
-e file` (and from your example, it looks you can) then you use
stub_command("test -e file").and_return(true) or false depending upon
your use case
On Wed, Oct 29, 2014 at 3:21 PM, Joe Nuspl
<
<mailto: >>
wrote:
I’m automating some 3rd party code. What I have is something like:
execute ‘refresh’ do
only_if { CONDITION }
end
execute ‘reconfigure' do
only_if { ::File.exists?(GUARD) }
end
Sometimes refresh creates GUARD. GUARD could also be created by
an admin. reconfigure removes GUARD upon success.
I am try to write chefspec tests to cover all the cases:
1) no-existing-guard refresh-creates-gaurd
2) no-existing-guard refresh-does-not-create-guard
3) existing-guard refresh-creates-guard
4) existing-guard refresh-does-not-create-guard
5) no-existing-guard no-refresh
6) exisiting-guard no-refresh
What I want to do is to “hook” into execute[refresh] and
conditionally update the ::File.exists? stub to return true.
If I update the stub before the run, I’ve collapsed #1 and #4
into one case.
Is it possible to hook into a resource? I tried :step_into but
that did not seem to do the trick. Any guidance would be
appreciated.
Thanks.
Joe
Archive powered by MHonArc 2.6.16.