class Object
Public Class Methods
environment(&block)
click to toggle source
# File lib/templates/resource_pack/spec/spec_helper.rb, line 43 def self.environment(&block) environment_builder(DoubleBuilder.new(&block)) # Create a backend helper which will generate a backend double # based on the definitions that have been building up in # all the environment builders in th current context and their # parent contexts. let(:backend) do # For all the possible platforms assign a false result unless the platform name matches possible_platforms = %w{aix redhat debian suse bsd solaris linux unix windows hpux darwin} os_platform_mock_results = possible_platforms.inject({}) { |acc, elem| acc["#{elem}?"] = (elem == platform.to_s) ; acc } platform_builder = DoubleBuilder.new { os.returns(os_platform_mock_results) } env_builders = [ platform_builder ] + self.class.parent_groups.map(&:environment_builder).compact starting_double = RSpec::Mocks::Double.new('backend') env_builders.inject(starting_double) { |acc, elem| elem.evaluate(self, acc) } end end
environment_builder(builder = nil)
click to toggle source
# File lib/templates/resource_pack/spec/spec_helper.rb, line 35 def self.environment_builder(builder = nil) if builder @environment_builder = builder else @environment_builder end end
Public Instance Methods
backend()
click to toggle source
This is a no-op backend that should be overridden.
Below is a helper method #environment which provides some shortcuts for hiding some of the RSpec mocking/stubbing double language.
# File lib/templates/resource_pack/spec/spec_helper.rb, line 79 def backend double( <<~BACKEND A mocked underlying backend has not been defined. This can be done through the environment helper method. Which enables you to specify how the mock envrionment will behave to all requests. environment do command('which ohai').returns(stdout: '/path/to/ohai') command('/path/to/ohai').returns(stdout: '{ "os": "mac_os_x" }') end BACKEND ) end
resource(*args)
click to toggle source
Create an instance of the resource with the mock backend and the resource name
# File lib/templates/resource_pack/spec/spec_helper.rb, line 63 def resource(*args) resource_class.new(backend, resource_name, *args) end