Sha256: d3f08c190ec958fc98c7f1b66809a4e230d1e170ab012636a29c3f40dfd753f3

Contents?: true

Size: 1.95 KB

Versions: 7

Compression:

Stored size: 1.95 KB

Contents

require File.join(File.dirname(__FILE__), 'test_helper')
require File.join(File.dirname(__FILE__), 'apipie_resource_mock')


describe HammerCLIForeman::CommonParameter do

  extend CommandTestHelper

  let(:resource_mock) { ApipieResourceMock.new(cmd.class.resource.resource_class) }

  before :each do
    cmd.class.resource resource_mock
  end

  context "ListCommand" do

    let(:cmd) { HammerCLIForeman::CommonParameter::ListCommand.new("", ctx) }

    context "parameters" do
      it_should_accept "no arguments"
      it_should_accept_search_params
    end

    context "output" do
      let(:expected_record_count) { cmd.resource.call(:index)[0].length }

      it_should_print_n_records
      it_should_print_columns  ["Name", "Value"]
    end

  end


  context "SetCommand" do

    let(:cmd) { HammerCLIForeman::CommonParameter::SetCommand.new("", ctx) }
    before :each do
      resource_mock.stub_method(:index, [])
    end

    context "parameters" do
      it_should_accept "name and value", ["--name=param", "--value=val"]
      it_should_fail_with "name missing", ["--value=val"]
      it_should_fail_with "value missing", ["--name=param"]
    end

    context "adding params" do
      with_params ["--name=param", "--value=val"] do
        it_should_call_action :create, {'common_parameter' => {'name' => 'param', 'value' => 'val'}, 'id' => 'param'}
      end
    end

    context "updating params" do
      before :each do
        resource_mock.stub_method(:index, [{'common_parameter' => {'name' => 'param'}}])
      end

      with_params ["--name=param", "--value=val"] do
        it_should_call_action :update, {'common_parameter' => {'name' => 'param', 'value' => 'val'}, 'id' => 'param'}
      end
    end

  end


  context "DeleteCommand" do

    let(:cmd) { HammerCLIForeman::CommonParameter::DeleteCommand.new("", ctx) }

    context "parameters" do
      it_should_accept "name", ["--name=arch"]
      it_should_fail_with "name missing", []
    end

  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hammer_cli_foreman-0.0.17 test/unit/common_parameter_test.rb
hammer_cli_foreman-0.0.16 test/unit/common_parameter_test.rb
hammer_cli_foreman-0.0.15 test/unit/common_parameter_test.rb
hammer_cli_foreman-0.0.14 test/unit/common_parameter_test.rb
hammer_cli_foreman-0.0.13 test/unit/common_parameter_test.rb
hammer_cli_foreman-0.0.12 test/unit/common_parameter_test.rb
hammer_cli_foreman-0.0.11 test/unit/common_parameter_test.rb