Sha256: d27f45e6605f2f24cc2321bb2c2233bed725488a22110bf9fcb98e5bcebe6ac0

Contents?: true

Size: 1.82 KB

Versions: 72

Compression:

Stored size: 1.82 KB

Contents

require 'spec_helper'

class ClassMixedWithDSLHelpers
  include Beaker::DSL::Helpers
  include Beaker::DSL::Wrappers
  include Beaker::DSL::Roles
  include Beaker::DSL::Patterns

  def logger
    RSpec::Mocks::Double.new('logger').as_null_object
  end

end

describe ClassMixedWithDSLHelpers do
  let( :command ){ 'ls' }
  let( :host )   { double.as_null_object }
  let( :result ) { Beaker::Result.new( host, command ) }

  let( :master ) { make_host( 'master',   :roles => %w( master agent default)    ) }
  let( :agent )  { make_host( 'agent',    :roles => %w( agent )           ) }
  let( :custom ) { make_host( 'custom',   :roles => %w( custom agent )    ) }
  let( :dash )   { make_host( 'console',  :roles => %w( dashboard agent ) ) }
  let( :db )     { make_host( 'db',       :roles => %w( database agent )  ) }
  let( :hosts )  { [ master, agent, dash, db, custom ] }


  describe '#fact_on' do
    it 'retrieves a fact on a single host' do
      result.stdout = "family\n"
      expect( subject ).to receive(:facter).with('osfamily',{}).once
      expect( subject ).to receive(:on).and_return(result)

      expect( subject.fact_on('host','osfamily') ).to be === result.stdout.chomp
    end

    it 'retrieves an array of facts from multiple hosts' do
      allow( subject ).to receive( :hosts ).and_return( hosts )
      times = hosts.length
      result.stdout = "family\n"
      hosts.each do |host|
        expect( host ).to receive(:exec).and_return(result)
      end

      expect( subject.fact_on(hosts,'osfamily') ).to be === [result.stdout.chomp] * hosts.length

    end
  end

  describe '#fact' do
    it 'delegates to #fact_on with the default host' do
      allow( subject ).to receive(:hosts).and_return(hosts)
      expect( subject ).to receive(:fact_on).with(master,"osfamily",{}).once

      subject.fact('osfamily')
    end
  end

end

Version data entries

72 entries across 72 versions & 1 rubygems

Version Path
beaker-2.48.1 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.48.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.47.1 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.47.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.46.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.45.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.44.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.43.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.42.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.41.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.40.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.39.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.38.1 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.38.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.37.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.36.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.35.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.34.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.33.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.32.1 spec/beaker/dsl/helpers/facter_helpers_spec.rb