edelight / chef-solo-search

Data bag search for Chef Solo
Apache License 2.0
177 stars 2 forks source link

"undefined method `step_into?' for nil:NilClass" when used with chefspec #59

Open a-chernykh opened 10 years ago

a-chernykh commented 10 years ago

I am not sure if this issue should be filed here or in chefspec project, but I am getting the following error when my cookbook depends on chef-solo-search:

chef/chef-solo-search-bug  % rspec                                                                                                                                                             (ruby-2.1.0)

================================================================================
Recipe Compile Error in /var/folders/yc/vm5xq0yx2354q7t1n3ldzsy00000gn/T/d20140319-38302-hjb4xf/cookbooks/chef-solo-search/libraries/search.rb
================================================================================

NoMethodError
-------------
undefined method `step_into?' for nil:NilClass

Cookbook Trace:
---------------
  /var/folders/yc/vm5xq0yx2354q7t1n3ldzsy00000gn/T/d20140319-38302-hjb4xf/cookbooks/chef-solo-search/libraries/search.rb:37:in `rescue in <top (required)>'
  /var/folders/yc/vm5xq0yx2354q7t1n3ldzsy00000gn/T/d20140319-38302-hjb4xf/cookbooks/chef-solo-search/libraries/search.rb:31:in `<top (required)>'

Relevant File Content:
----------------------
/var/folders/yc/vm5xq0yx2354q7t1n3ldzsy00000gn/T/d20140319-38302-hjb4xf/cookbooks/chef-solo-search/libraries/search.rb:

 30:    # Ensure the treetop gem is installed and available
 31:    begin
 32:      require 'treetop'
 33:    rescue LoadError
 34:      run_context = Chef::RunContext.new(Chef::Node.new, {}, Chef::EventDispatch::Dispatcher.new)
 35:      chef_gem = Chef::Resource::ChefGem.new("treetop", run_context)
 36:      chef_gem.version('>= 1.4')
 37>>     chef_gem.run_action(:install)
 38:    end
 39:
 40:    require 'search/overrides'
 41:    require 'search/parser'
 42:
 43:    module Search; class Helper; end; end
 44:
 45:    # The search and data_bag related methods moved form `Chef::Mixin::Language`
 46:    # to `Chef::DSL::DataQuery` in Chef 11.

F

Failures:

  1) chef-solo-search-bug::efault
     Failure/Error: let(:converge) { chef_run.converge described_recipe }
     NoMethodError:
       undefined method `step_into?' for nil:NilClass
     # /var/folders/yc/vm5xq0yx2354q7t1n3ldzsy00000gn/T/d20140319-38302-hjb4xf/cookbooks/chef-solo-search/libraries/search.rb:37:in `rescue in <top (required)>'
     # /var/folders/yc/vm5xq0yx2354q7t1n3ldzsy00000gn/T/d20140319-38302-hjb4xf/cookbooks/chef-solo-search/libraries/search.rb:31:in `<top (required)>'
     # ./spec/default_spec.rb:5:in `block (2 levels) in <top (required)>'
     # ./spec/default_spec.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.72692 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/default_spec.rb:7 # chef-solo-search-bug::efault

Randomized with seed 46101

This error happens when chef-solo-search tries to install treetop gem using ChefGem resource. chefspec overrides Resource#run_action with it's own version which executes node.runner.step_into?(self), but node.runner does not exists at the moment when chef-solo-cookbook is included.

I've created repository to reproduce the problem: https://github.com/andreychernih/chef-solo-search-bug

michaelglass commented 10 years ago

thoughts on providing a fix?

a-chernykh commented 10 years ago

Yeah, I'll give it a look.

michaelglass commented 10 years ago

thanks! :bug: :+1: :star:

a-chernykh commented 10 years ago

Alright, unfortunately it can not be fixed on the chefspec side. It looks like we need to put chef_gem 'treetop' into a separate recipe and ask users to include it into runlist. @michaelglass I can wrap this in PR if it sounds good for you.

michaelglass commented 10 years ago

do you think this should be an addition to chefspec?

a-chernykh commented 10 years ago

It was my first thought, that's why I've sent PR to chefspec in the first place, but @sethvargo convinced me that it should belong to chef-solo-search (see https://github.com/sethvargo/chefspec/issues/394)

michaelglass commented 10 years ago

I kind of agree with @sethvargo that it's not worth ensuring all of this works because of Zero. But feel free to PR the fix.

rmoriz commented 9 years ago

That 'treetop' issue is a bit annoying. The code at https://github.com/edelight/chef-solo-search/blob/master/libraries/search.rb#L32-L43 seems to be broken.

When Chef with a version not equal 10 is found, treetop '=1.5.3' is required, however the rescue block below installs '=1.5.1'.