0

In my .rb file, I am attempting to write a spec test against this line of code (I did not write this code):

execute "lvcreate -L #{node['ami_base']['opt']} -n opt vgpool"

In my _spec.rb file, my test looks like this for this particular section of code:

it 'executes lvcreate... -n opt vgpool' do
  expect(chef_run).to run_execute("lvcreate -L #{node['ami_base']['opt']} -n opt vgpool")
end

When I attempt:

chef exec rspec....._spec.rb

I receive this error:

1) ami_base::lvm_drives executes lvcreate... -n opt vgpool
 Failure/Error: expect(chef_run).to run_execute("lvcreate -L #{node['ami_base']['opt']} -n opt vgpool")

 NameError:
   undefined local variable or method `node' for #<RSpec::ExampleGroups::AmiBaseLvmDrives:0x0000000005752268>
 # ./spec/unit/recipes/lvm_drives_spec.rb:33:in `block (2 levels) in <top (required)>'

I've written many tests against execute and they've all been successful. Do I need to modify the spec helper file? I feel like it being a command line input and creating a volume that the command should be something other than run_execute, but i am coming up empty handed in a my searches for anything that works.

Gabe
  • 1
  • 3
  • 2
    Please, post the text of the error message as text, not as a photograph of text. This is a programming site, not a photography site. We want to read, copy, and paste the error, not critique its use of color and perspective. (Although if I may offer a critique nonetheless: the dark red on black is completely unreadable on my screen.) – Jörg W Mittag Sep 04 '18 at 06:46
  • Will do. First post on the site, so I'm learning how it works. I'll get the text up – Gabe Sep 04 '18 at 08:06
  • error message text has been added. – Gabe Sep 04 '18 at 08:33

1 Answers1

1

You don’t use node attributes in your spec like that, the point of the test is to manually expand it to make sure your code worked.

coderanger
  • 52,400
  • 4
  • 52
  • 75