Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

action: nothing/end.run_action(:create) examples? #107

Closed
jimhopp opened this Issue · 4 comments

3 participants

@jimhopp
Collaborator

I'm trying to figure out a way to test resources that use the "action: nothing/end.run_action(:create)" pattern. I don't think they're currently testable with chefspec as chefspec expects "action :create".

Three questions:
1. Is my understanding correct?
2. Would it be possible to test these by writing specs against the state of the resources (rather than using the chefspec matchers)?
3. Is it feasible to add matchers for this pattern? If it is and someone can point me in the right direction I'm willing to take a crack at it.

Thanks.

@ranjib
Collaborator
@sethvargo
Owner

My first instinct - this isn't possible with chefspec. Because chefspec actually runs a converge (combined with some magical monkey patching), and resource.run_action(:blah) happens at compile time, I'm not sure we could capture that.

You could, however, unit test this directly with rspec:

before do
  Chef::Provider::RemoteFile.stub(:action_create).and_return(my_stub)
end

it 'does something' do
  Chef::Provider::RemoteFile.should_receive(:action_create).and_return(my_stub)
  my_stub.should_receive(:run_action).with(:create)
end

Disclaimer: Totally untested and highly theoretical.

@sethvargo
Owner

@jimhopp any luck on this?

@sethvargo sethvargo closed this
@jimhopp
Collaborator

Apologies @sethvargo. I missed your question.

I couldn't get the stubbing to work (I think it needed to be Chef::Resource::GemPackage anyway) so I reverted to this

 it 'installs lookout-stats in pre-0.10.10' do
   chef_run
   chef_run.resources.each do |resource|
     resource.package_name.should == "lookout-statsd" if resource.class == Chef::Resource::GemPacka
ge
     resource.action.should == [:nothing] if resource.class == Chef::Resource::GemPackage
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.