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

Node attributes are not being set. #55

Closed
joestump opened this issue Dec 21, 2013 · 4 comments
Closed

Node attributes are not being set. #55

joestump opened this issue Dec 21, 2013 · 4 comments

Comments

@joestump
Copy link

I'm a bit perplexed on this one. I'm using the node setting of attributes in other chefspec w/o issue. This is the first time I've used Fauxhai and I'm seeing oddness in that I can't get node[:platform] nor node[:kernel][:machine] to budge from chefspec and i386 for the life of me.

Here's a gist:

https://gist.github.com/joestump/045969db1928537807d9

When I puts my node[:platform] (or node[:kernel][:machine]) they are never set as I'd expect (should be ubuntu and x86_64).

I was trying to add tests to my rstudio cookbook.

@joestump
Copy link
Author

Also getting this, which might be related. I can't set an attribute that is set as default['some']['attribute'] without an exception being thrown.

/usr/local/Cellar/ruby/2.0.0-p353/bin/ruby -S rspec ./spec/cran_spec.rb
F

Failures:

  1) rstudio::server should include the r cookbook
     Failure/Error: node['rstudio']['cran']['packages'] = 'aadsf'
     NoMethodError:
       undefined method `[]' for nil:NilClass
     # ./spec/cran_spec.rb:12:in `block (3 levels) in <top (required)>'
     # ./spec/cran_spec.rb:11:in `new'
     # ./spec/cran_spec.rb:11:in `block (2 levels) in <top (required)>'
     # ./spec/cran_spec.rb:17:in `block (2 levels) in <top (required)>'

Finished in 1.22 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/cran_spec.rb:16 # rstudio::server should include the r cookbook
/usr/local/Cellar/ruby/2.0.0-p353/bin/ruby -S rspec ./spec/cran_spec.rb failed

Here's the spec

require 'spec_helper'

describe 'rstudio::server' do
#  before do
#    Fauxhai.mock(platform: 'ubuntu', version: '12.04') do |node|
#      # node['rstudio']['cran']['packages'] = 'aadsf'
#      node['languages']['ruby']['version'] = 'ree'
#    end
#  end
  let(:chef_run) do
    ChefSpec::Runner.new do |node|
      node['rstudio']['cran']['packages'] = 'aadsf'
    end.converge(described_recipe)
  end

  it('should include the r cookbook') do
    expect(chef_run).to include_recipe('r')
  end
end

@sethvargo
Copy link
Contributor

That cookbook you posted is a 404. Since ChefSpec 2.0, you don't ever call fauxhai directly - it's used under the covers. Make a new Chef runner with the platform you want:

describe 'rstudio::server' do
  let(:chef_run) { ChefSpec::Runner.new(platform: 'ubuntu', version: '12.04').converge(described_recipe) }

  it 'includes the r cookbook' do
    expect(chef_run).to include_recipe('r')
  end
end

You can also configure these options globally. All of this is explained in the ChefSpec configuration documentation and ChefSpec attribute setting documentation.

@joestump
Copy link
Author

Ah, got it. 👍

@dasomx77
Copy link

Hey there Seth, I pretty much have the same issue as the one above and your solution doesn't seem to help solve the issue. I get

Failure/Error: ChefSpec::Runner.new do |node|
     ArgumentError:
       Cannot find a platform for node[fauxhai.local]

when trying to run:

let(:dummy_class) {
    Class.new {include Cookbook_name::Helper_module }
    ChefSpec::Runner.new(platform: 'ubuntu', version: '12.04') do |node|
      node.default.set['Cookbook_name']['attribute_name'] = '/aaa/va/files/'
    end.converge(described_recipe)
}

and given the stack trace, this is where it fails:

it 'should have the directory we are looking for' do
  expect(chef_run).to create_directory('/aaa/va/files/')
end

any idea what I might be doing wrong?
Thanks

@lock lock bot locked as resolved and limited conversation to collaborators Aug 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants