<commit_before>require 'spec_helper'

describe 'nssm_test::remove_service' do
  context 'windows' do
    let(:chef_run) do
      ChefSpec::SoloRunner.new(platform: 'windows', version: '2008R2', step_into: ['nssm']).converge(described_recipe)
    end

    let(:fake_class) { Class.new }

    before do
      obj = double
      if ENV['APPVEYOR'] # Fix ArgumentError: wrong number of arguments (1 for 0)
        require 'win32ole'
        allow(WIN32OLE).to receive(:connect).with('winmgmts://').and_return(obj)
      else
        stub_const('::WIN32OLE', fake_class)
        allow(fake_class).to receive(:connect).and_return(obj)
      end
      allow(obj).to receive(:ExecQuery).and_return([''])
      ENV['SYSTEMDRIVE'] = 'C:'
    end

    it 'calls nssm remove resource' do
      expect(chef_run).to remove_nssm('service name')
    end

    it 'executes batch command to remove service' do
      expect(chef_run).to run_batch('Remove service service name').with(
        code: /%WINDIR%\\nssm.exe remove "service name" confirm/
      )
    end
  end

  context 'linux' do
    let(:chef_run) do
      ChefSpec::SoloRunner.new(platform: 'centos', version: '7.0', step_into: ['nssm']).converge(described_recipe)
    end

    it 'writes a log with warning' do
      expect(chef_run).to write_log('NSSM service can only be removed from Windows platforms!').with(level: :warn)
    end
  end
end
<commit_msg>More testing of win32ole mock<commit_after>require 'spec_helper'

describe 'nssm_test::remove_service' do
  context 'windows' do
    let(:chef_run) do
      ChefSpec::SoloRunner.new(platform: 'windows', version: '2008R2', step_into: ['nssm']).converge(described_recipe)
    end

    let(:fake_class) { Class.new }

    before do
      obj = double
      # if ENV['APPVEYOR'] # Fix ArgumentError: wrong number of arguments (1 for 0)
      #   require 'win32ole'
      #   allow(WIN32OLE).to receive(:connect).with('winmgmts://').and_return(obj)
      # else
        stub_const('::WIN32OLE', fake_class)
        allow(fake_class).to receive(:connect).with('winmgmts://').and_return(obj)
      # end
      allow(obj).to receive(:ExecQuery).and_return([''])
      ENV['SYSTEMDRIVE'] = 'C:'
    end

    it 'calls nssm remove resource' do
      expect(chef_run).to remove_nssm('service name')
    end

    it 'executes batch command to remove service' do
      expect(chef_run).to run_batch('Remove service service name').with(
        code: /%WINDIR%\\nssm.exe remove "service name" confirm/
      )
    end
  end

  context 'linux' do
    let(:chef_run) do
      ChefSpec::SoloRunner.new(platform: 'centos', version: '7.0', step_into: ['nssm']).converge(described_recipe)
    end

    it 'writes a log with warning' do
      expect(chef_run).to write_log('NSSM service can only be removed from Windows platforms!').with(level: :warn)
    end
  end
end

{'fraction_non_alphanumeric': 0.13008415147265076, 'fraction_numerical': 0.011220196353436185, 'mean_word_length': 3.329286798179059, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5374035', 'n_tokens_mistral': 991, 'n_tokens_neox': 959, 'n_words': 230}