Sha256: 596ceb063b6c58336de1456f29bb97b7a78ac8de94c68482c609a335628d8238

Contents?: true

Size: 1.74 KB

Versions: 2

Compression:

Stored size: 1.74 KB

Contents

require 'spec_helper'
require 'natives/app'

describe Natives::App do
  describe "#install" do
    let(:app) { Natives::App.new }

    it "forces packages argument to be an Array" do
      app.should_receive(:run_chef_solo)
      app.should_receive(:create_tmp_attrs_file).with([]).and_call_original

      app.install(nil)
    end
  end

  describe "#create_tmp_attrs_file" do
    let(:app) { Natives::App.new }

    it "generates a valid Chef JSON attrs file" do
      json = nil
      app.create_tmp_attrs_file(['foo', 'bar']) do |file|
        json = JSON.parse(file.read)
      end
      expect(json).to eq({
        "natives" => {
          "install_list" => {
            "rubygems" => ["foo", "bar"]
          },
          "config" => {
            "working_dir" => Dir.pwd
          }
        }
      })
    end

    it "handles empty package list" do
      json = nil
      app.create_tmp_attrs_file([]) do |file|
        json = JSON.parse(file.read)
      end
      expect(json).to eq({
        "natives" => {
          "install_list" => {
            "rubygems" => []
          },
          "config" => {
            "working_dir" => Dir.pwd
          }

        }
      })
    end
  end

  describe "#run_chef_solo" do
    let(:app) { Natives::App.new }

    it "rewrites ARGV with Chef Solo options and run Chef Solo Application" do
      attrs_file = double()
      attrs_file.stub(:to_path) { '/path/to/attrs_file' }

      Chef::Application::Solo.any_instance.should_receive(:run)

      app.run_chef_solo(attrs_file)

      expect(ARGV).to eq([
        '-c',
        File.absolute_path(File.join(
          File.dirname(__FILE__), '..', '..', 'chef-solo', 'config.rb')),
        '-o', 'natives',
        '-j', '/path/to/attrs_file'
      ])
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
natives-0.1.3 spec/natives/app_spec.rb
natives-0.1.2 spec/natives/app_spec.rb