Skip to content

Instantly share code, notes, and snippets.

@jtimberman
Last active December 10, 2015 02:48
Show Gist options
  • Save jtimberman/4370569 to your computer and use it in GitHub Desktop.
Save jtimberman/4370569 to your computer and use it in GitHub Desktop.
Starting to add rspec tests for runit_service LWRP.
champagne:~OPSCODE_COOKBOOKS/runit (1.9.3-p327)
CHEF-154 ✗ % rake spec
bundle exec rspec -c -f d spec.rb
Chef::Provider::RunitService
load_current_resource
should create a current resource with the name of the new resource
Finished in 0.00362 seconds
1 example, 0 failures
require 'rspec'
require 'chef/platform'
require 'chef/run_context'
require 'chef/resource'
require 'chef/provider'
require 'chef/cookbook/metadata'
require 'chef/event_dispatch/dispatcher'
describe "Chef::Provider::RunitService" do
before(:each) do
md = Chef::Cookbook::Metadata.new
md.from_file(File.join(File.dirname(__FILE__), 'metadata.rb'))
@node = Chef::Node.new
@events = Chef::EventDispatch::Dispatcher.new
@run_context = Chef::RunContext.new(@node, {}, @events)
Chef::Resource.build_from_file(md.name, File.join(File.dirname(__FILE__), 'resources', 'service.rb'), @run_context)
Chef::Provider.build_from_file(md.name, File.join(File.dirname(__FILE__), 'providers', 'service.rb'), @run_context)
@new_resource = Chef::Resource::RunitService.new('getty.service')
@provider = Chef::Provider::RunitService.new(@new_resource, @run_context)
end
describe "load_current_resource" do
before(:each) do
@current_resource = Chef::Resource::RunitService.new('getty.service')
Chef::Resource::RunitService.stub!(:new).and_return(@current_resource)
@provider.stub!(:running?).and_return(false)
@provider.stub!(:enabled?).and_return(false)
end
it 'should create a current resource with the name of the new resource' do
Chef::Resource::RunitService.should_receive(:new).and_return(@current_resource)
@provider.load_current_resource
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment