Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
a-chernykh opened this issue Mar 19, 2014 · 8 comments

Comments

@a-chernykh
Copy link

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
Copy link

thoughts on providing a fix?

@a-chernykh
Copy link
Author

Yeah, I'll give it a look.

@michaelglass
Copy link

thanks! 🐛 👍 ⭐

a-chernykh added a commit to a-chernykh/chefspec that referenced this issue Mar 19, 2014
Chef automatically requires all files in `libraries` directory. This happens before the node's runner is even created.

Fixes edelight/chef-solo-search#59
@a-chernykh
Copy link
Author

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
Copy link

do you think this should be an addition to chefspec?

@a-chernykh
Copy link
Author

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 chefspec/chefspec#394)

@michaelglass
Copy link

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
Copy link

rmoriz commented Oct 26, 2015

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'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants