0

I'm running a Chef Inspec exec profile in a Jenkins job and it returns Rspec deprecation warnings. The problem is that these warnings are included in the json output that inspec exec command creates and I've tried sed/awk to remove all characters outside of the json object using begin and end pattern /{/ , /}/ but nothing is working, every time the text is still in the file. I added an rspec exception to the spec_helper.rb file to allow syntax for both but the warnings still appear. I'm left with a file that contains :

Invalid expiration date or inactive date or both
Invalid expiration date or inactive date or both

1 deprecation warning total
{"version":"0.30.0","profiles":{  ..... }- this part is actually valid json, excluding from this post to keep it short.

Using Inspec 0.30.0, Ruby 2.0.0p645, Rspec 3.5.2.

Here is the command I'm using to execute the inspec profiles on a local target via ssh :

    VmIp=$(vmrun getGuestIPAddress output-vmware-iso/${templateName}.vmx -wait)
    inspec exec  ./inspecRepo/ --format json-min -t ssh://vagrant@${VmIp} --password vagrant --sudo | tee Test_Results.json

Here is a snippet of the Jenkins job output :

+ VmPath=/app_2/jenkins-work/workspace/xl-release/output-vmware-iso/rhel7.vmware.template.vmx
++ vmrun getGuestIPAddress output-vmware-iso/rhel7.vmware.template.vmx -wait
+ VmIp=172.16.81.159
+ inspec exec ./inspecRepo/ --format json -t ssh://vagrant@172.16.81.159 --password vagrant --sudo
+ tee Test_Results.json
./inspecRepo/controls/filesystem.rb:60: warning: already initialized constant #<Class:0x00000001a25ac0>::BASELINE
./inspecRepo/controls/filesystem.rb:60: warning: previous definition of BASELINE was here
./inspecRepo/controls/filesystem.rb:60: warning: already initialized constant #<Class:0x00000001a25ac0>::BASELINE
./inspecRepo/controls/filesystem.rb:60: warning: previous definition of BASELINE was here
./inspecRepo/controls/filesystem.rb:60: warning: already initialized constant #<Class:0x00000001a25ac0>::BASELINE
./inspecRepo/controls/filesystem.rb:60: warning: previous definition of BASELINE was here

Deprecation Warnings:

Using `should` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` with `config.expect_with(:rspec) { |c| c.syntax = :should }` instead. Called from ./inspecRepo/controls/app_config.rb:466:in `block (4 levels) in load'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
Invalid expiration date or inactive date or both
Invalid expiration date or inactive date or both

1 deprecation warning total
{"version":"0.30.0","profiles":{"rhel7-baseline":{ ..............

Here is a snippet of the spec_helper.rb where I have added :should & :expect syntax inclusion :

   Spec_helper.rb :
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
config.expect_with(:rspec){|c| c.syntax = [:should, :expect]}
  # rspec-expectations config goes here. You can use an alternate
  # assertion/expectation library such as wrong or the stdlib/minitest
  # assertions if you prefer.
  config.expect_with :rspec do |expectations|

Here is the test that is generating the syntax warnings: \

    control 'password-inactive' do

  impact 0.5

  title "Ensure password inactivity is configured"

  desc "The password inactive in /etc/shadow is configured"



  DATE_FMT = '%b %d, %Y' # date format used by chage(1) as specified by strptime(3)

  command('egrep ^[^:]+:[^\!*] /etc/shadow | cut -d: -f1').stdout.each_line do |line|   # extract all users(username) with password



    pwExipre = command("chage --list #{line}").stdout.split("\n")[1].split(":")[1].strip  # extract date and convert to right format

    pwInactive = command("chage --list #{line}").stdout.split("\n")[2].split(":")[1].strip

    if pwExipre == 'never' || pwInactive == 'never'

      puts "Invalid expiration date or inactive date or both"

      describe true do

        it { should eq false }

      end

    else

      expire = Date.strptime(pwExipre, DATE_FMT) # convert to desired format

      inactive = Date.strptime(pwInactive, DATE_FMT)

      describe (inactive - expire) do

        it { should eq 30 } # 30 days' difference

      end

    end

  end

end
StephenKing
  • 36,187
  • 11
  • 83
  • 112
hedda
  • 51
  • 1
  • 8

1 Answers1

0

Just fix your code to use the new expect() or is_expected syntax instead. Seems easier and that's the standard moving forward anyway. If you include the actual test code that fails I could be more specific.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • I've updated the question to include the test but the test is using the standard Inspec dsl. – hedda Aug 22 '16 at 17:03
  • Replace `should` with `is_expected.to` or `expect(subject).to`. This is unrelated to InSpec, it's normal RSpec stuffs. – coderanger Aug 22 '16 at 20:23
  • Hmm, but there are hundreds of tests in that profile using this Inspec dsl syntax 'should' and they aren't throwing this error. – hedda Aug 22 '16 at 21:21
  • You aren't really using InSpec correctly to start with, so I'm unshocked you are having inconsistent results :) – coderanger Aug 22 '16 at 22:42