Testing a library which has node attributes #68

Closed
retr0h opened this Issue Oct 27, 2012 · 8 comments

Projects

None yet

4 participants

@retr0h

Any suggestions on how to test the following?
https://github.com/retr0h/cookbook-reboot-handler/blob/tests/spec/reboot_spec.rb

Since it has node attributes, I was hoping chefspec would mock it out, just like it does for resources.
Any idea what I am missing?

1) Reboot starting to get annoyed
   Failure/Error: @subject.report
   NoMethodError:
     undefined method `node' for nil:NilClass
   # ./cookbooks/reboot-handler/files/default/reboot.rb:9:in `report'
   # ./cookbooks/reboot-handler/spec/reboot_spec.rb:16:in `block (2 levels) in <top (required)>'
@jimhopp-lookout

Sorry, John, nothing apparent to me. I take it you can confirm that the recipe is indeed being converged?

@retr0h

Appears to be. Obviously I am doing something wrong, and would rather not stub node myself. Hopefully, someone has done this before, can shed some light on this. :)

@jimhopp
Collaborator
@retr0h

Hi Jim. I am sorry, but I don't see anything in your repo that tests what I am trying to do.
Thanks for the reply, hoping someone has tested an external file with node attributes before.
Maybe @acrmp can chime in 👍

@acrmp
Collaborator

Hi John,

Here's a modified example that should get you going:
https://gist.github.com/3984500

@retr0h

You are good! :) Thank you very much. Was looking for what I was doing wrong. Thanks for helping me with this.

@retr0h retr0h closed this Oct 31, 2012
@retr0h

Hi @acrmp. My apologies, I had one more question. I was looking to test that the command was executed. That seems like a valid test, and also wanted to make sure the node.run_list was reset as per some new requirements in my implementation.

Do you have any recommendations on testing the last 2 tests. Again, my apologies for the silly questions, trying to avoid a bunch of manual stubbing.

@retr0h retr0h reopened this Oct 31, 2012
@retr0h

Ended up figuring it out. Thanks again for your help.

@retr0h retr0h closed this Oct 31, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment