Ask Your Question
0

equal sign not working in serverspec for if condition

asked 2015-12-17 05:21:05 -0500

Chutki gravatar image

Hi,

I have written below serverspec

if os[:release] == '6'

   describe file('/etc/test.conf') do
    it { should exist }
    it { should be_owned_by 'root' }
    it { should be_grouped_into 'root' }
    it { should be_mode 0644 }
  end

when I run getting

No examples found.

Finished in 0.00032 seconds (files took 11.07 seconds to load)
0 examples, 0 failures

why my test doesn't pass in spite of my 'osrelease' is 6. But if I change the option toif os[:release] < '7' its working.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-12-17 08:33:31 -0500

If the == sign was not working then ruby itself would be broken. :)

Here's how I debugged this:

$ irb
irb(main):001:0> os = {}
=> {}
irb(main):002:0> os['release'] = 6
=> 6
irb(main):003:0> os['release'] == '6'
=> false
irb(main):004:0> os['release'] == 6
=> true

So in ruby, == compares two numbers, whereas '6' is a string. No idea why < '7' worked - are you sure you didn't actually say < 7?

edit flag offensive delete link more

Comments

Thanks it worked :) by using "if os[:release] = 6". yes I am sure I tried option "if os[:release] < '7'" and its working

Chutki gravatar imageChutki ( 2015-12-17 22:04:13 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-12-17 05:21:05 -0500

Seen: 69 times

Last updated: Dec 17 '15