Ask Your Question

"" is not a Hash. It looks to be a String

asked 2016-02-04 06:38:20 -0600

karthikeayan gravatar image

updated 2016-02-09 09:14:32 -0600

I have init.pp as below:

class mymodule {

  include mymodule::users
  include mymodule::install
  include mymodule::config
  include mymodule::service

  Class[mymodule::users] -> Class[mymodule::install] -> Class[mymodule::config] -> Class[mymodule::service]


I have install.pp as below:

class mymodule::install (
  $artifacts = undef,
) inherits mymodule::params {


  create_resources('different_module::artifact', $artifacts)

And I am creating specs for these classes as below:


require 'spec_helper'
require 'hiera'
describe 'mymodule', :type => :class do
  let(:pre_condition) { '
    include mymodule::install
    include mymodule::users
    include mymodule::service
    include mymodule::config
  ' }

  it { should contain_class('mymodule') }



require 'spec_helper'
require 'hiera'

describe 'mymodule::install', :type => :class do

        let(:pre_condition) {'include different_module'

        let(:hiera_config) { 'spec/fixtures/hiera/hiera.yaml' }
        hiera = => 'spec/fixtures/hiera/hiera.yaml')
        artifacts = hiera.lookup('mymodule::install::artifacts', nil, nil)
        let(:params) { { :artifacts => artifacts } }

        it { should contain_class('mymodule::install') }
        it { should contain_different_module__artifact('mymodule') }


  - yaml
  :datadir: spec/fixtures/hieradata
  - common


    groupid:     ''
    artifactid:  'mymodule'
    version:     'r1.0'
    type:        'tgz'
    destination: '/tmp/mymodule_r1.0.tar.gz'
    timeout: '0'

When I run rspec I am getting the below error:

"" is not a Hash.  It looks to be a String at /tmp/mymodule/spec/fixtures/modules/mymodule/manifests/install.pp:6

EDIT: When I add Alex's fail statement before validate_hash all the specs have been failed. Interestingly, I can see the below, only for should contain_class, it is empty:

  1) mymodule should contain Class[mymodule]
     Failure/Error: it { should contain_class('mymodule') }

       I got  for artifacts at /tmp/mymodule/spec/fixtures/modules/mymodule/manifests/install.pp:6 on node debian-vm.localdomain

And for other specs I can see the value of artifacts as below:

  3) mymodule::install should contain Class[mymodule::install]
     Failure/Error: it { should contain_class('mymodule::install')  }

       I got {"mymodule"=>{"groupid"=>"", "artifactid"=>"mymodule", "version"=>"r4", "type"=>"tgz", "destination"=>"/tmp/mymodule_r49.tar.gz", "timeout"=>"0"}} for artifacts at /tmp/mymodule_r4/spec/fixtures/modules/mymodule_r4/manifests/install.pp:6 on node debian-vm.localdomain
edit retag flag offensive close merge delete


Can you see what's different about your init_spec and the ones that are working, with respect to Hiera?

Alex Harvey gravatar imageAlex Harvey ( 2016-02-09 09:15:15 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2016-02-04 08:09:48 -0600

Firstly, do you really have spaces in your class names like

  include mymodule ::users

I think you've done some search & replace to redact class names, so could you fix that?

Secondly, could you insert a line before the validate_hash line in your manifest:

fail("I got $artifacts for artifacts")

Then run it again, and update your post with this info.

edit flag offensive delete link more


Sorry for replying late, Alex.

karthikeayan gravatar imagekarthikeayan ( 2016-02-09 03:15:56 -0600 )edit

I waited 5 days for you! Just kidding. :)

Alex Harvey gravatar imageAlex Harvey ( 2016-02-09 09:21:48 -0600 )edit

Thanks Alex, with your help am able to resolve it.

karthikeayan gravatar imagekarthikeayan ( 2016-02-11 07:09:27 -0600 )edit

answered 2016-02-11 07:08:56 -0600

karthikeayan gravatar image

updated 2016-02-11 09:19:13 -0600

Moving the let(:hiera_config) to spec_helper solves this issue.


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'

As hiera_config was in inside each spec rb, for init spec it is not able to find the value for artifacts.

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


Asked: 2016-02-04 06:38:20 -0600

Seen: 624 times

Last updated: Feb 11 '16