Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query_nodes spec. #79

Open
israelriibeiro opened this issue Nov 25, 2015 · 5 comments
Open

query_nodes spec. #79

israelriibeiro opened this issue Nov 25, 2015 · 5 comments

Comments

@israelriibeiro
Copy link

Hi, guys.

I'm trying to test a module which there's many query_nodes functions. I wanna know how to test this with rspec, when i run rspec, it returns something like this:

  cannot load such file -- puppet/util/puppetdb

Do i have to install something?

This is Gemfile:

source 'https://rubygems.org'

gem 'rake'
gem 'puppet-lint'
gem 'rspec-puppet'
gem 'rspec-system-puppet'
gem 'puppetlabs_spec_helper'
gem 'travis'
gem 'travis-lint'
gem 'puppet-syntax'
gem 'puppet', ENV['PUPPET_VERSION'] || '~> 3.8.0'
gem 'vagrant-wrapper'
gem 'puppet-blacksmith'
gem 'beaker'
gem 'beaker-rspec'
gem 'ruby-puppetdb'

This is my rspec_helper:

require 'rspec-puppet'
require 'hiera'
require 'puppetlabs_spec_helper/puppetlabs_spec_helper'
require 'puppetlabs_spec_helper/module_spec_helper'

fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))

RSpec.configure do |c|
  c.module_path = File.join(fixture_path, 'modules')
  c.manifest_dir = File.join(fixture_path, 'manifests')
  c.hiera_config = 'spec/fixtures/hiera/hiera.yaml'
end

Att,

Israel Ribeiro

@andrea-capri
Copy link

I'm having the same issue, was there any solution?

@israelriibeiro
Copy link
Author

israelriibeiro commented Aug 18, 2016

@andrea-capri , if i remember correctly, i did this:

I added this two lines in spec_helper.rb

$LOAD_PATH.push(File.join(fixture_path, 'modules', 'puppetdb','puppet', 'lib'))
$LOAD_PATH.push(File.join(fixture_path, 'modules', 'puppetdbquery','lib'))

It looks like this:

require 'rspec-puppet'
require 'puppetlabs_spec_helper/puppetlabs_spec_helper'
require 'puppetlabs_spec_helper/module_spec_helper'
require 'hiera'
require 'rspec-puppet-utils'

fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))

$LOAD_PATH.push(File.join(fixture_path, 'modules', 'puppetdb','puppet', 'lib'))
$LOAD_PATH.push(File.join(fixture_path, 'modules', 'puppetdbquery','lib'))

RSpec.configure do |c|
  c.module_path = File.join(fixture_path, 'modules')
  c.manifest_dir = File.join(fixture_path, 'manifests')
  c.hiera_config = 'spec/fixtures/hiera/hiera.yaml'
end

And i installed a gem whose name i can't remember. I think it was ruby-puppetdb

Att,

Israel Ribeiro

@andrea-capri
Copy link

Ah thanks, will try

@dalen
Copy link
Owner

dalen commented Sep 14, 2016

A bit late reply here, but I would prefer to just mock the function. It can for example be done by putting something like this in your spec file:

before(:each) do
  Puppet::Parser::Functions.newfunction(:query_nodes, :type => :rvalue) { |args| ['host1.example.com', 'host2.example.com'] }
end

Hopefully rspec-puppet will include some functionality to do this in a simpler way in the future.

@andrea-capri
Copy link

Thanks Dalen, I did end up using mocks for my unit tests, just forgot to post it back here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants