voxpupuli / onceover

Your gateway drug to automated infrastructure testing with Puppet
Apache License 2.0
142 stars 45 forks source link

Trouble using traditional Rspec tests with factsets #81

Closed fuero closed 6 years ago

fuero commented 7 years ago

Hi,

I'm trying to use traditional rspec tests with factsets. When dropping in traditional test files, onceover runs them, but accessing the facts doesn't work as documented:

Using Onceover::Controlrepo.facts.each do |facts| fails with

[...]/vendor/ruby/2.1.0/gems/onceover-3.1.0/lib/onceover/controlrepo.rb:72:in `facts': undefined method `facts' for nil:NilClass (NoMethodError)
        from [...]/.onceover/spec/classes/apache_spec.rb:10:in `block in <top (required)>'

Using Onceover::Controlrepo.new,facts.each do |facts| does work, but seems to ignore onceover.yaml and is thus running the test on all factsets available, not just the ones I set up for this repo.

Any ideas?

dylanratcliffe commented 7 years ago

Yeah that's definitely a bug. Investigating...

dylanratcliffe commented 7 years ago

Hmm so this works for me

require 'onceover/controlrepo'
Onceover::Controlrepo.facts

However you are right about the facts method returning all facts. This is because a Controlrepo object knows nothing about your config, it just represents the state of your controlrepo, ignoring onceover. (To a degree)

If you want the facts that are referenced you will need to create a Onceover::TestConfig object. You can do this by:

require 'onceover/controlrepo'
require 'onceover/testconfig'

repo = Onceover::Controlrepo.new
config = Onceover::TestConfig.new(repo.onceover_yaml)

config.nodes.each do |node| # List of node objects
  node.fact_set # The set of facts
end