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

Could not find class #395

Closed
wenzhengjiang opened this issue Jul 11, 2016 · 10 comments · Fixed by #494
Closed

Could not find class #395

wenzhengjiang opened this issue Jul 11, 2016 · 10 comments · Fixed by #494
Labels
Milestone

Comments

@wenzhengjiang
Copy link

The is the module directory.

➜   tree
.
├── Gemfile
├── Gemfile.lock
├── manifests
│   └── init.pp
├── metadata.json
├── Rakefile
├── README.md
├── spec
│   ├── classes
│   │   └── certs_spec.rb
│   ├── defines
│   ├── fixtures
│   │   ├── manifests
│   │   │   └── site.pp
│   │   └── modules
│   │       └── certs
│   │           └── manifests -> ../../../../manifests
│   ├── functions
│   ├── hosts
│   └── spec_helper.rb
└── tests
    └── init.pp

12 directories, 10 files

manifests/init.pp

class certs {}

spec/classes/certs_spec.rb

require 'spec_helper'

describe 'certs' do
  it { is_expected.to compile }
end
➜   rake rspec
/home/wjiang/.rvm/rubies/ruby-2.1.5/bin/ruby -I/home/wjiang/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.5.1/lib:/home/wjiang/.rvm/gems/ruby-2.1.5/gems/rspec-support-3.5.0/lib /home/wjiang/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.5.1/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb
F

Failures:

  1) certs should compile into a catalogue without dependency cycles
     Failure/Error: it { is_expected.to compile }
       error during compilation: Evaluation Error: Error while evaluating a Function Call, Could not find class ::certs for wjiang.engineering.syd2.internal at line 1:1 on node wjiang.engineering.syd2.internal
     # ./spec/classes/certs_spec.rb:4:in `block (2 levels) in <top (required)>'

Finished in 0.10328 seconds (files took 0.53017 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/classes/certs_spec.rb:4 # certs should compile into a catalogue without dependency cycles

/home/wjiang/.rvm/rubies/ruby-2.1.5/bin/ruby -I/home/wjiang/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.5.1/lib:/home/wjiang/.rvm/gems/ruby-2.1.5/gems/rspec-support-3.5.0/lib /home/wjiang/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.5.1/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb failed
@josh-cain
Copy link

josh-cain commented Oct 7, 2016

exact same issue here. Just to sanity check, I did this:

puppet module generate jcain-demoError

But when I run rspec, I still get this:

 # ------------------
 # --- Caused by: ---
 # Puppet::Error:
 #   Could not find class ::demoerror for localhost.bleh.com
 #   /home/jcain/.gem/ruby/gems/puppet-4.7.0/lib/puppet/parser/compiler.rb:382:in `block in evaluate_classes'

Here are some versions I'm running if that helps:

rspec (3.5.0)
rspec-core (3.5.4)
rspec-expectations (3.5.0)
rspec-helpers (1.2.0)
rspec-mocks (3.5.0)
rspec-puppet (2.4.0)
rspec-support (3.5.0)

@dandunckelman
Copy link

When you run rake spec_prep, it simply installs all the modules from .fixtures.yml. So, could you share the content of your .fixtures.yml? And is the missing module appearing in spec/fixtures/modules/MODULE_NAME as expected?

When you run rake spec, it deletes the modules from that folder as a cleanup phase.

@josh-cain
Copy link

I seem to have the MODULE_NAME as expected, but I don't have a .fixtures.yml. Is that a requirement? rspec-puppet-init doesn't seem to add that file, do I need it?

demoError/
├── examples
│   └── init.pp
├── Gemfile
├── manifests
│   └── init.pp
├── metadata.json
├── Rakefile
├── README.md
└── spec
    ├── classes
    │   └── init_spec.rb
    ├── defines
    ├── fixtures
    │   ├── manifests
    │   │   └── site.pp
    │   └── modules
    │       └── demoError
    │           └── manifests -> ../../../../manifests
    ├── functions
    ├── hosts
    └── spec_helper.rb

12 directories, 9 files

@dandunckelman
Copy link

@cainj13 maybe .fixtures.yml isn't required. I've always used it. Here's one of mine:

fixtures:
  forge_modules:
    apache:
      ref: '1.10.0'
      repo: 'puppetlabs/apache'
    apt:
      ref: '2.3.0'
      repo: 'puppetlabs/apt'
    chocolatey:
      ref: '1.2.6'
      repo: 'chocolatey/chocolatey'
    concat:
      ref: '2.2.0'
      repo: 'puppetlabs/concat'
    download_file:
      ref: '2.0.0'
      repo: 'puppet/download_file'
    extlib:
      ref: '1.0.0'
      repo: 'puppet/extlib'
    logrotate:
      ref: '1.4.0'
      repo: 'yo61/logrotate'
    powershell:
      ref: '2.0.2'
      repo: 'puppetlabs/powershell'
    puppet:
      ref: '6.0.0'
      repo: 'theforeman/puppet'
    registry:
      ref: '1.1.3'
      repo: 'puppetlabs/registry'
    stdlib:
      ref: '4.12.0'
      repo: 'puppetlabs/stdlib'
    windows_env:
      ref: '2.2.2'
      repo: 'badgerious/windows_env'
  repositories:
    newrelic:
      branch: 'specify_windows_provider'
      repo: 'https://github.com/dandunckelman/puppet-newrelic'
    wsus_client:
      ref: '7fcc3b37a3ae665c2f8502081f904a3eea28b2a0'
      repo: 'https://github.com/puppetlabs/puppetlabs-wsus_client.git'
  symlinks:
    ta_base: "#{source_dir}"
    ta_linux: "#{source_dir}/../ta_linux"
    ta_windows: "#{source_dir}/../ta_windows"

So, you can see how this can be helpful in testing various version of modules as well as specifying specific commit hashes or branches.

Could you share the *_spec.rb you're running?

@josh-cain
Copy link

josh-cain commented Oct 7, 2016

@dandunckelman Sure, I can share some code that will reproduce the error for you. Just:

puppet module generate jcain-demoError && cd demoError && rm spec/spec_helper.rb Rakefile && rspec-puppet-init && rake rspec

Note sure how a .fixtures.yml would help me for something like this^. Aren't those just for locating referenced modules?

@dandunckelman
Copy link

@cainj13 Thanks. I just ran the list of commands and reproduced the same error.

I think there may be an issue w/ rspec-puppet-init. When I tried the manual setup (from here), it worked as expected.

I also suspect some weirdness w/ the module being named w/ camel-case (as you can see in the error, it's looking for demoerror, not demoError); although, I'm not sure that's really the issue.

Regardless, try the manual setup where the key difference in the spec/spec_helper.rb being this:

require 'rspec-puppet'

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')
end

@josh-cain
Copy link

josh-cain commented Oct 7, 2016

@dandunckelman I think you're right, this gave me a clean run:

puppet module generate jcain-demoerror && cd demoerror && rm spec/spec_helper.rb Rakefile && rspec-puppet-init && echo "require 'rspec-puppet'

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')
end" > spec/spec_helper.rb && echo "require 'rake'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec) do |t|
  t.pattern = 'spec/*/*_spec.rb'
end" > Rakefile && rake spec

I'm fairly new to the rspec-puppet world, can you tell my why these diffs are significant/breaking?

@dandunckelman
Copy link

dandunckelman commented Oct 7, 2016

@cainj13 Ultimately, the updated spec/spec_helper.rb is explicitly telling RSpec to look for puppet modules/manifests in the spec/fixtures/modules and spec/fixtures/manifests dirs, respectively. Without that setting, rspec runs w/o knowing where to get the Puppet class to test, resulting in the erorr you see. Maybe @rodjek can explain more about rspec-puppet-init and why your class isn't be auto-loaded.

In my case, I use https://github.com/puppetlabs/puppetlabs_spec_helper which helps w/ that and many other things. A bonus from that, that I didn't know until looking now, is that it can parallelize the downloading of dependent modules (correction: it only downloads modules in parallel when they're sourced from repositories). This should speed up my tests in CI.

@josh-cain
Copy link

@dandunckelman Gotcha. That popped up while I was googling about this - looks like a very promising module, should probably look at what it's got going on. Thanks for the quick responses and the help!

@dandunckelman
Copy link

@cainj13 no problem. I went thru a lot of pain getting my setup to where it is today; so, I'm glad to help.

@rodjek rodjek added this to the 2.6.0 milestone Apr 5, 2017
@rodjek rodjek added the pr open label Apr 5, 2017
@rodjek rodjek added bug and removed pr open labels Aug 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants