Giter Club home page Giter Club logo

Comments (7)

ghoneycutt avatar ghoneycutt commented on August 16, 2024

Thanks for reporting this! Could you send us a PR to fix the docs?

from rspec-puppet-facts.

towo avatar towo commented on August 16, 2024

Hah, you assume I've found a solution yet. 🙁 That would be nice, still looking.

from rspec-puppet-facts.

nabertrand avatar nabertrand commented on August 16, 2024

You would need to use os_facts[:osfamily] instead of facts[:osfamily] since that's what you've called the facts variable in on_supported_os.each do |os, os_facts|. Notice that the example actually calls the facts variable facts, not os_facts:

  on_supported_os.each do |os, facts|
    context "on #{os}" do
...
      # If you need to specify any operating system specific tests
      case facts[:osfamily]

Also note that let definitions are only available within an example, e.g. it { ... } and not example groups, e.g. context .... So facts[:osfamily] would work for you within an it block, but not within a context block.

I have run into this confusion myself as the Puppet Development Kit spec templates use os_facts while the examples in this documentation use facts, e.g. https://github.com/puppetlabs/pdk-templates/blob/2b3320584b8d6ceb9027b441582bb4e16c3d6350/object_templates/class_spec.erb#L4 and https://github.com/puppetlabs/pdk-templates/blob/2b3320584b8d6ceb9027b441582bb4e16c3d6350/object_templates/defined_type_spec.erb#L9. Would it make sense to update this documentation to match the PDK templates?

from rspec-puppet-facts.

ghoneycutt avatar ghoneycutt commented on August 16, 2024

Perhaps it would be better to update PDK's templates to use facts as that makes more sense than their implementation using os_facts

from rspec-puppet-facts.

rodjek avatar rodjek commented on August 16, 2024

No, in this case it's the rspec-puppet-facts documentation that is wrong. The facts local variable is actually a memoised helper expected to be created by let(:facts) as standard practice in rspec-puppet. The docs for rspec-puppet-facts set up a rather confusing situation where one of the facts values ends up shadowed, which while it technically works it should not be encouraged.

on_supported_os.each do |os, facts| # <-- facts hash added to scope
  let(:facts) do # <-- facts hash now shadowed by the memoised facts helper
    facts # <-- Want to guess what this value will be at a specific time of evaluation?
  end

from rspec-puppet-facts.

ghoneycutt avatar ghoneycutt commented on August 16, 2024

@rodjek you seem to know what's going on with this, could you send a PR to the docs?

from rspec-puppet-facts.

threepistons avatar threepistons commented on August 16, 2024

@towo rodjek/rspec-puppet#774 (comment) describes correct syntax.

from rspec-puppet-facts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.