Ask Your Question
1

rspec ArgumentError: wrong number of arguments (2 for 1)

asked 2017-06-19 01:23:56 -0500

updated 2017-06-20 08:43:05 -0500

DarylW gravatar image

I have used simple test case to write Rspec. but while executing i am getting the below error.

Code:

require 'spec_helper'

describe "nginx" do
 it do
     is_expected.to contain_file('/var/www/index.html').with({
      'ensure' => 'present',
      'require' => 'Package[nginx]',
    })
  end
end

On execution: I am getting the below error.

root@puppet:/etc/puppet/modules/development# rspec spec/classes/init_spec.rb --format documentation

nginx
  should contain Class[nginx] (FAILED - 1)

Failures:

  1) nginx should contain Class[nginx]
     Failure/Error: should contain_class('nginx')

 ArgumentError:
   wrong number of arguments (2 for 1)
 # /var/lib/gems/1.9.1/gems/puppet-4.10.1/lib/puppet/indirector/catalog/compiler.rb:71:in `initialize'
 # /var/lib/gems/1.9.1/gems/rspec-puppet-2.5.0/lib/rspec-puppet/adapters.rb:74:in `catalog'
 # /var/lib/gems/1.9.1/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:203:in `build_catalog_without_cache'
 # /var/lib/gems/1.9.1/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:212:in `block in build_catalog'
 # /var/lib/gems/1.9.1/gems/rspec-puppet-2.5.0/lib/rspec-puppet/cache.rb:17:in `call'
 # /var/lib/gems/1.9.1/gems/rspec-puppet-2.5.0/lib/rspec-puppet/cache.rb:17:in `get'
 # /var/lib/gems/1.9.1/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:211:in `build_catalog'
 # /var/lib/gems/1.9.1/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:30:in `block in load_catalogue'
 # /var/lib/gems/1.9.1/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:178:in `with_vardir'
 # /var/lib/gems/1.9.1/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:19:in `load_catalogue'
 # /var/lib/gems/1.9.1/gems/rspec-puppet-2.5.0/lib/rspec-puppet/example/class_example_group.rb:7:in `catalogue'
 # /var/lib/gems/1.9.1/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:11:in `block in subject'
 # /var/lib/gems/1.9.1/gems/rspec-puppet-2.5.0/lib/rspec-puppet/matchers/create_generic.rb:82:in `call'
 # /var/lib/gems/1.9.1/gems/rspec-puppet-2.5.0/lib/rspec-puppet/matchers/create_generic.rb:82:in `matches?'
 # ./spec/classes/init_spec.rb:12:in `block (2 levels) in <top (required)>'

Finished in 0.00835 seconds (files took 0.81628 seconds to load)
1 example, 1 failure
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-06-20 12:04:53 -0500

DevOpsProDude gravatar image

When doing unit testing of Puppet code with rspec, attributes of a resource will be kept separate from ordering metaparameters for a resource. Your rspec code should actually look like this:

require 'spec_helper'
describe "nginx" do
  it {
    is_expected.to contain_file('/var/www/index.html').with(
      ensure: 'present',
    ).that_requires('Package[nginx]')
  }
end

You can read more about relationship testing here https://github.com/rodjek/rspec-puppe...

edit flag offensive delete link more

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: 2017-06-19 01:23:56 -0500

Seen: 22 times

Last updated: Jun 20