diff --git a/capistrano-chef.gemspec b/capistrano-chef.gemspec index 5ae8d33..71a1d25 100644 --- a/capistrano-chef.gemspec +++ b/capistrano-chef.gemspec @@ -19,5 +19,6 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.add_dependency 'capistrano', '>= 3' s.add_dependency 'chef', '>= 0.10.10' + s.add_development_dependency 'rspec', '~> 3.0' end diff --git a/lib/capistrano/dsl/chef.rb b/lib/capistrano/dsl/chef.rb index 4c1f70c..b6e82f8 100644 --- a/lib/capistrano/dsl/chef.rb +++ b/lib/capistrano/dsl/chef.rb @@ -1,7 +1,7 @@ module Capistrano module DSL module Chef - def chef_role(name, query = '*:*', options) + def chef_role(name, query = '*:*', **options) arg = options.delete(:attribute) || :ipaddress search_proc = case arg diff --git a/spec/lib/capistrano/dsl/chef_spec.rb b/spec/lib/capistrano/dsl/chef_spec.rb new file mode 100644 index 0000000..28a11b0 --- /dev/null +++ b/spec/lib/capistrano/dsl/chef_spec.rb @@ -0,0 +1,30 @@ +require_relative '../../spec_helper' +require 'chef/knife' +require 'chef/node' +require 'chef/search/query' +require 'capistrano/dsl/chef' + +describe Capistrano::DSL::Chef do + let(:cap) { Class.new { extend Capistrano::DSL::Chef } } + context 'search without args' do + before do + @role_name = :app + @user = 'test_user' + @search_str = 'roles:test_search_role' + + # server_1 = double('nodes', ipaddress: '1.1.1.1') + server_1 = { 'ipaddress' => '1.1.1.1' } + + expect(cap).to receive(:fetch).with(:user).and_return(@user) + expect(Chef::Search::Query).to receive_message_chain(:new, :search).with( + :node, + @search_str + ).and_return([[server_1]]) + end + + it 'gets a list of node ips' do + expect(cap).to receive(:role).with([@role_name], ["#{@user}@1.1.1.1"]) + cap.chef_role(@role_name, @search_str) + end + end +end diff --git a/spec/lib/spec_helper.rb b/spec/lib/spec_helper.rb new file mode 100644 index 0000000..bdb9c46 --- /dev/null +++ b/spec/lib/spec_helper.rb @@ -0,0 +1,5 @@ +require 'rspec' + +RSpec.configure do |c| + c.mock_with :rspec +end