Chefspec test failure due to the hash password/attribute #{password}


#1

Hi guys,

i am experiencing failure when running rspec unit tests. i noticed it’s complaining about the attribute #{password} in my tests. please see my code below.

password = ChefVault::Item.load('123', '456')[node['hostname']]

  execute 'install' do

     command "./wsadmin.sh -lang jython -f deployment.py -username wasserver -password **#{password}** instructions/$env/$inst cell=$cell node=$node"
  end

i would appreciate your help

Thanks,


#2

You would need to share your failing spec and the error message too.


#3

spec

require ‘spec_helper’
require ‘chef-vault’

describe ‘INT3_Backend::serverStop’ do
before do
allow(ChefVault::Item).to receive(:load).with(‘bol’, ‘automate’).and_return(‘automate’ => {})
allow(File).to receive(:exist?).and_call_original
allow(File).to receive(:exist?).with(’/udd001/app/WebSphere/AppServer/profiles/AppSrv01/logs/server1/server1.pid’).and_return(true)
end
context ‘When all attributes are default, on Ubuntu 16.04’ do
let(:chef_run) do
runner = ChefSpec::ServerRunner.new(platform: ‘ubuntu’, version: ‘16.04’)
runner.converge(described_recipe)
end

it 'converges successfully' do
  expect { chef_run }.to_not raise_error
end

it 'stop Server' do
  expect(chef_run).to run_execute("./wsadmin.sh -lang jython -f deployment.py -username wasserver -password #{password} instructions/$env/$inst cell=$cell node=$node").with(
    user: '123',
    group: '456',
    live_stream: true)
end

end
end

Error log

  1. INT3_Backend::serverStop When all attributes are default, on Ubuntu 16.04 stop Server
    Failure/Error:
    expect(chef_run).to run_execute("./wsadmin.sh -lang jython -f deployment.py -username wasserver -password #{password} instructions/$env/$inst cell=$cell node=$node").with(
    user: ‘123’,
    group: ‘456’,
    live_stream: true)

    NameError:
    undefined local variable or method `password’ for #RSpec::ExampleGroups::INT3BackendServerStop::WhenAllAttributesAreDefaultOnUbuntu1604:0x000000000523c8c8

    ./spec/unit/recipes/serverStop_spec.rb:26:in `block (3 levels) in <top (required)>’

Finished in 19.29 seconds (files took 1.56 seconds to load)
45 examples, 1 failure

Failed examples:

rspec ./spec/unit/recipes/serverStop_spec.rb:25 # INT3_Backend::serverStop When all attributes are default, on Ubuntu 16.04 stop Server


#4

Hi @coderanger

Will you be able to assist on this one?

Thanks.