bolt icon indicating copy to clipboard operation
bolt copied to clipboard

BoltSpec: `run_task` with `description` cannot be stubbed

Open jay7x opened this issue 2 years ago • 0 comments

Describe the Bug

I was unable to stub a run_task call with description parameter specified. As far as I see it should be part of .with_params() of the allow_task() but it doesn't work for me.

Expected Behavior

Either there should be .with_description() or description should be part of .with_params(). In any way there should be a way to specify the description in allow_task (and expect_taks I guess).. or to ignore it at least.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Create a module (I'm using lima module here as I hit the issue while working on the module).
  2. Store the plan into the plans/test.pp:
    plan lima::test {
      run_task('facts', ['localhost'], 'Test the BoltSpec issue', {})
      #run_task('facts', ['localhost'], {})
    }
    
  3. Setup your spec_helper.rb with BoltSpec as described here: https://www.puppet.com/docs/bolt/latest/testing_plans.html#include-boltspec-in-spec-helperrb
  4. Store the spec into the spec/plans/test_spec.rb:
    # frozen_string_literal: true
    
    require 'spec_helper'
    
    describe 'lima::test' do
      let(:params) { { description: 'Test the BoltSpec issue' } }
      #let(:params) { {} }
    
      it 'runs fine' do
        allow_task('facts').with_targets(['localhost']).with_params(params).always_return({})
    
        result = run_plan('lima::test', {})
    
        expect(result.ok?).to be(true)
      end
    end
    
  5. Run the tests (I'm using PDK here):
    pdk test unit --tests ./spec/plans/test_spec.rb -v
    

You should see Unexpected call to 'run_task(facts, ["localhost"], {:description=>"Test the BoltSpec issue"})' error message now.

If you remove the description from the run_task() in plan and from the allow_task() in spec it'll be fine..

Environment

  • Version 3.26.2
  • Platform:
    {
      architecture => "x86_64",
      family => "Darwin",
      hardware => "x86_64",
      macosx => {
        build => "21G419",
        product => "macOS",
        version => {
          full => "12.6.3",
          major => "12",
          minor => "6",
          patch => "3"
        }
      },
      name => "Darwin",
      release => {
        full => "21.6.0",
        major => "21",
        minor => "6"
      }
    }
    

jay7x avatar Feb 19 '23 11:02 jay7x