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.32.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.31.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.30.1 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.30.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.29.1 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.29.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.28.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.27.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.26.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.25.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.24.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.23.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.22.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.21.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.20.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.19.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.18.3 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.18.2 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.18.1 spec/beaker/dsl/helpers/facter_helpers_spec.rb
beaker-2.18.0 spec/beaker/dsl/helpers/facter_helpers_spec.rb