Class: MCollective::Test::ApplicationTest

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/mcollective/test/application_test.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#create_config_mock, #create_connector_mock, #create_facts_mock, #create_logger_mock, #create_response, #load_agent, #load_application, #mock_validators

Constructor Details

#initialize(application, options = {}) ⇒ ApplicationTest

Returns a new instance of ApplicationTest.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mcollective/test/application_test.rb', line 8

def initialize(application, options={})
  config = options[:config] || {}
  facts = options[:facts] || {"fact" => "value"}

  ARGV.clear

  @config = create_config_mock(config)
  @application = application.to_s
  @logger = create_logger_mock
  @plugin = load_application(@application, options[:application_file])

  @plugin.stubs(:printrpcstats)
  @plugin.stubs(:puts)
  @plugin.stubs(:printf)

  make_create_client
end

Instance Attribute Details

#applicationObject (readonly)

Returns the value of attribute application.



4
5
6
# File 'lib/mcollective/test/application_test.rb', line 4

def application
  @application
end

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/mcollective/test/application_test.rb', line 4

def config
  @config
end

#loggerObject (readonly)

Returns the value of attribute logger.



4
5
6
# File 'lib/mcollective/test/application_test.rb', line 4

def logger
  @logger
end

#pluginObject (readonly)

Returns the value of attribute plugin.



4
5
6
# File 'lib/mcollective/test/application_test.rb', line 4

def plugin
  @plugin
end

Instance Method Details

#make_create_clientObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mcollective/test/application_test.rb', line 26

def make_create_client
  @plugin.instance_eval "
    def create_client(client)
        mock_client = Mocha::Mock.new
        mock_client.stubs(:progress=)
        mock_client.stubs(:progress)

        yield(mock_client) if block_given?

        MCollective::Application::Facts.any_instance.expects(:rpcclient).with(client).returns(mock_client)

        mock_client
    end
  "
end