[chef] Re: Re: Re: chefspec and yum


Chronological Thread 
  • From: Ranjib Dey < >
  • To:
  • Subject: [chef] Re: Re: Re: chefspec and yum
  • Date: Sun, 29 Sep 2013 13:40:22 -0700

you should be able to assert on the file also, because you are stepping inside the yum_repository resource, chefspec should evaluate the provider. yum_repository provider uses a template [1], you should be able to assert using standard  expect(runner).to create_file('/etc/yum.repos.d/something') also,.

https://github.com/opscode-cookbooks/yum/blob/master/providers/repository.rb#L100


On Sun, Sep 29, 2013 at 12:19 PM, Rilindo Foster < " target="_blank"> > wrote:
Thanks, Dewey! That got it working. Here is the first iteration, sort of copied from Dewey's example:

  before do
    @chef_run = ::ChefSpec::ChefRunner.new.converge 'x2go::default'
  end
  
  it 'should create a repo if it does not exists' do
    
    resource = @chef_run.find_resource("yum_repository", "x2go").to_hash
    
    expect(resource).to include(
      :repo_name => 'x2go',
      :description => 'x2go (replaces NX)',
     :action =">" [:add]
    )
  end


Because I don't want to completely copy other people's code, here is my version:

  let(:chef_run) {
    ChefSpec::ChefRunner.new.converge 'x2go::default'
  }
   
  it 'should create a repo if it does not exists' do
    
    expect(chef_run.find_resource('yum_repository','x2go').to_hash).to include(
      :repo_name => 'x2go',
      :description => 'x2go (replaces NX)',
      :action =">" [:add]
    )
  end




On Sep 28, 2013, at 11:23 PM, John Dewey < " target="_blank"> > wrote:

I don't believe there is a matcher for it. However, you should be able to assert the LWRP syntax via #find_resource.

On Saturday, September 28, 2013 at 9:19 PM, Rilindo Foster wrote:

Is there a way to to write a chef spec assertion to see if the repo will be created? Here is my default.rb:

yum_repository "x2go" do
 repo_name "x2go"
 description "x2go (replaces NX)"
 url "http://download.opensuse.org/repositories/X11:/RemoteDesktop:/x2go/RHEL_6/"
 key "http://download.opensuse.org/repositories/X11:/RemoteDesktop:/x2go/RHEL_6/repodata/repomd.xml.key"
 action :add
end


And here is my current chef spec at this point:

require 'chefspec'

describe 'x2go::default' do
 let(:chef_run) {
   ChefSpec::ChefRunner.new(:step_into => ['yum_repository']).converge 'x2go::default'
 }

 it 'should create a repo if it does not exists' do
   chef_run.converge "x2go::default"
   expect(chef_run).to create_file("x2go")
 end
end

Doesn't work, which is probably because "create_file" is used with the "file" resource, not yum_repository LWRP.

It doesn't look like chef spec supports the yum_repository LWRP (or at least that I can see), so I am not sure what direction I should take from here. What approach should I take?

- Rilindo






Archive powered by MHonArc 2.6.16.

§