<commit_before>#! /usr/bin/env ruby
require 'spec_helper'
require 'puppet/type'
require 'puppet/provider/iis_powershell'

describe Puppet::Provider::IIS_PowerShell do
  let (:subject) { Puppet::Provider::IIS_PowerShell }<commit_msg>(MODULES-4378) Add unit tests for PowerShell 2 support<commit_after>#! /usr/bin/env ruby
require 'spec_helper'
require 'puppet/type'
require 'puppet/provider/iis_powershell'

describe Puppet::Provider::IIS_PowerShell do
  let (:subject) { Puppet::Provider::IIS_PowerShell }

  describe "run" do
    let(:ps_manager) { double("PSManager") }
    let(:command) { 'command' }
    let(:execute_response) {{
      :stdout => nil, :stderr => nil, :exitcode => 0
    }}

    before(:each) do
      allow(subject).to receive(:ps_manager).and_return(ps_manager)
      allow(ps_manager).to receive(:execute).and_return(execute_response)
    end

    describe "When on PowerShell 2.0" do
      before(:each) do
        expect(subject).to receive(:ps_major_version).and_return(2)
      end

      it 'should append Importing the WebAdministration module' do
        expect(ps_manager).to receive(:execute).with(/Import-Module WebAdministration/,nil,nil).and_return(execute_response)
        subject.run(command)
      end

      it 'should append changing the working directory to IIS' do
        expect(ps_manager).to receive(:execute).with(/cd iis:/,nil,nil).and_return(execute_response)
        subject.run(command)
      end

      it 'should append a JSON converter' do
        expect(ps_manager).to receive(:execute).with(/ConvertTo\-JSON/,nil,nil).and_return(execute_response)
        subject.run(command)
      end

      it 'should set Confirmation Preference' do
        expect(ps_manager).to receive(:execute).with(/\$ConfirmPreference = 'high'/,nil,nil).and_return(execute_response)
        subject.run(command)
      end

      it 'should append the original command at the end' do
        expect(ps_manager).to receive(:execute).with(/#{command}$/,nil,nil).and_return(execute_response)
        subject.run(command)
      end
    end

    [3,4,5,6].each do |testcase|
      describe "When on PowerShell #{testcase}.0" do
        before(:each) do
          expect(subject).to receive(:ps_major_version).and_return(testcase)
        end

        it 'should not modify the command' do
          expect(ps_manager).to receive(:execute).with(command,nil,nil).and_return(execute_response)
          subject.run(command)
        end
      end
    end
  end
{'fraction_non_alphanumeric': 0.12011285771866183, 'fraction_numerical': 0.005642885933091495, 'mean_word_length': 3.5209471766848814, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3131312', 'n_tokens_mistral': 778, 'n_tokens_neox': 752, 'n_words': 162}