dalen / puppet-puppetdbquery

Query functions for PuppetDB

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

query_nodes spec.

israelriibeiro opened this issue · comments

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

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

@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

Ah thanks, will try

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.

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