Chefspec link-matcher problem


#1

Hi,

after quite some changes to adopt the munin-cookbook to our needs, I am
coming back to checking my stuff with rspec/chefspec.

And especially I want to check that the recipe creates the links for
the munin-plugins as needed (depending on other factors like recipes on
the own node).

But I somehow fail to test that with chefspec. My very minimal
test-case is:

= recipe “munin::plugin_test”:

link ‘/tmp/tmp’ do
to '/bin/bash’
action 'create’
end

====

= spec-file:

describe ‘munin::plugin_test’ do
it “should create a link for a plugin” do
chef_run = ChefSpec::ChefRunner.new()

chef_run.converge 'munin::plugin_test'

chef_run.link '/tmp/tmp'
chef_run.link '/completely fake'

end
end

====

And altough the last test should be false, chefspec doesn’t complain at
all. I also tried to write it as:
chef_run.should link_to '/tmp/tmp’
but that gives errors that there is no method ‘to’ on ‘link’…

I am using chefspec 1.3.1 and just updated all the local gems (inside
the used rbenv).

What am I doing wrong? Can anyone point me to a working example how to
check filesystem-links with chefspec?

Thanks in advance,

Arnold


#2

expect(chef_run.link(’/tmp/tmp’)).to_not be_nil

so you are checking that there a link resource present with name /tmp/tmp

to check the to attribute
expect(chef_run.link(’/tmp/tmp’).to).to eq(’/foo/abr’)

On Tue, Jul 16, 2013 at 12:34 PM, Arnold Krille arnold@arnoldarts.dewrote:

Hi,

after quite some changes to adopt the munin-cookbook to our needs, I am
coming back to checking my stuff with rspec/chefspec.

And especially I want to check that the recipe creates the links for
the munin-plugins as needed (depending on other factors like recipes on
the own node).

But I somehow fail to test that with chefspec. My very minimal
test-case is:

= recipe “munin::plugin_test”:

link ‘/tmp/tmp’ do
to '/bin/bash’
action 'create’
end

====

= spec-file:

describe ‘munin::plugin_test’ do
it “should create a link for a plugin” do
chef_run = ChefSpec::ChefRunner.new()

chef_run.converge 'munin::plugin_test'

chef_run.link '/tmp/tmp'
chef_run.link '/completely fake'

end
end

====

And altough the last test should be false, chefspec doesn’t complain at
all. I also tried to write it as:
chef_run.should link_to '/tmp/tmp’
but that gives errors that there is no method ‘to’ on ‘link’…

I am using chefspec 1.3.1 and just updated all the local gems (inside
the used rbenv).

What am I doing wrong? Can anyone point me to a working example how to
check filesystem-links with chefspec?

Thanks in advance,

Arnold


#3

Ranjib: that looks a lot more complicated than most asserts should be.

This commit 1 added support for link resources. Here’s some syntax
examples and assertions:
https://github.com/acrmp/chefspec/blob/master/spec/chefspec/matchers/link_spec.rb#L7-L16

-M

On Tue, Jul 16, 2013 at 3:55 PM, Ranjib Dey dey.ranjib@gmail.com wrote:

expect(chef_run.link(’/tmp/tmp’)).to_not be_nil

so you are checking that there a link resource present with name /tmp/tmp

to check the to attribute
expect(chef_run.link(’/tmp/tmp’).to).to eq(’/foo/abr’)

On Tue, Jul 16, 2013 at 12:34 PM, Arnold Krille arnold@arnoldarts.de
wrote:

Hi,

after quite some changes to adopt the munin-cookbook to our needs, I am
coming back to checking my stuff with rspec/chefspec.

And especially I want to check that the recipe creates the links for
the munin-plugins as needed (depending on other factors like recipes on
the own node).

But I somehow fail to test that with chefspec. My very minimal
test-case is:

= recipe “munin::plugin_test”:

link ‘/tmp/tmp’ do
to '/bin/bash’
action 'create’
end

====

= spec-file:

describe ‘munin::plugin_test’ do
it “should create a link for a plugin” do
chef_run = ChefSpec::ChefRunner.new()

chef_run.converge 'munin::plugin_test'

chef_run.link '/tmp/tmp'
chef_run.link '/completely fake'

end
end

====

And altough the last test should be false, chefspec doesn’t complain at
all. I also tried to write it as:
chef_run.should link_to '/tmp/tmp’
but that gives errors that there is no method ‘to’ on ‘link’…

I am using chefspec 1.3.1 and just updated all the local gems (inside
the used rbenv).

What am I doing wrong? Can anyone point me to a working example how to
check filesystem-links with chefspec?

Thanks in advance,

Arnold


#4

On Tue, 16 Jul 2013 16:05:50 -0400 Mike miketheman@gmail.com wrote:

Ranjib: that looks a lot more complicated than most asserts should be.

This commit 1 added support for link resources. Here’s some syntax
examples and assertions:
https://github.com/acrmp/chefspec/blob/master/spec/chefspec/matchers/link_spec.rb#L7-L16

Ah, thats what I was failing to grasp from the commits. (I am not a
ruby guy.) I just wondered why there was no example for testing links in
chefspec’s README…

Thanks Mike!

Have fun,

Arnold