{"action":"closed","issue":{"url":"https://api.github.com/repos/burtlo/chefspec-ohai/issues/2","repository_url":"https://api.github.com/repos/burtlo/chefspec-ohai","labels_url":"https://api.github.com/repos/burtlo/chefspec-ohai/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/burtlo/chefspec-ohai/issues/2/comments","events_url":"https://api.github.com/repos/burtlo/chefspec-ohai/issues/2/events","html_url":"https://github.com/burtlo/chefspec-ohai/issues/2","id":232639992,"number":2,"title":"How to test plugins that depend on other plugins","user":{"login":"mhedgpeth","id":3209401,"avatar_url":"https://avatars0.githubusercontent.com/u/3209401?v=3","gravatar_id":"","url":"https://api.github.com/users/mhedgpeth","html_url":"https://github.com/mhedgpeth","followers_url":"https://api.github.com/users/mhedgpeth/followers","following_url":"https://api.github.com/users/mhedgpeth/following{/other_user}","gists_url":"https://api.github.com/users/mhedgpeth/gists{/gist_id}","starred_url":"https://api.github.com/users/mhedgpeth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhedgpeth/subscriptions","organizations_url":"https://api.github.com/users/mhedgpeth/orgs","repos_url":"https://api.github.com/users/mhedgpeth/repos","events_url":"https://api.github.com/users/mhedgpeth/events{/privacy}","received_events_url":"https://api.github.com/users/mhedgpeth/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-05-31T17:33:36Z","updated_at":"2017-06-01T01:50:27Z","closed_at":"2017-06-01T01:50:27Z","body":"I'm trying to test this plugin:\r\n\r\n```ruby\r\nOhai.plugin :company do\r\n  provides 'company/datacenter'\r\n  depends 'hostname'\r\n\r\n  collect_data :default do\r\n    company(Mash.new)\r\n    host = hostname[:hostname]\r\n    match = /(\\D\\D\\D\\d\\d)-.*/.match(host)\r\n      if !match.nil?\r\n       company[:datacenter] = match[0]\r\n     else\r\n      company[:datacenter] = 'CORP'\r\n     end\r\n  end\r\nend\r\n```\r\n\r\nWith this test:\r\n\r\n```ruby\r\nrequire 'spec_helper'\r\n\r\ndescribe_ohai_plugin :Ncr do\r\n  let(:plugin_file) { 'files/default/ncr_datacenter.rb' }\r\n\r\n  it 'provides ncr/datacenter' do\r\n    expect(plugin).to provides_attribute('ncr/datacenter')\r\n  end\r\n\r\n  let(:command) { double('Fake Command', stdout: 'OUTPUT') }\r\n\r\n  it 'correctly parses machine name from ATL32' do\r\n    allow(plugin).to receive(:shell_out).with('hostname').and_return('ATL32-mysql01')\r\n    expect(plugin_attribute('company/datacenter')).to eq('ATL32')\r\n  end\r\n\r\n  it 'parses machine name with no prefix to be CORP' do\r\n    allow(plugin).to receive(:shell_out).with('hostname').and_return('labweb01')\r\n    expect(plugin_attribute('company/datacenter')).to eq('CORP')\r\n  end\r\nend\r\n```\r\n\r\nAnd when I run it I get the following error:\r\n\r\n```\r\n  1) company correctly parses machine name from ATL32\r\n     Failure/Error: expect(plugin_attribute('company/datacenter')).to eq('ATL32')\r\n\r\n     NoMethodError:\r\n       undefined method `[]' for nil:NilClass\r\n     # files/default:7:in `block (2 levels) in <main>'\r\n     # /Users/mh185122/.chefdk/gem/ruby/2.3.0/gems/chefspec-ohai-0.1.0/lib/chefspec/ohai.rb:92:in `plugin_attribute'\r\n     # ./spec/unit/ohai_plugins/company_datacenter_spec.rb:14:in `block (2 levels) in <top (required)>'\r\n```\r\n\r\nIt works fine until I add the hostname dependency. How would I refer to the active hostname built into ohai?"}}
{"actor":{"display_login":"mhedgpeth"}}