Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions capistrano-chef.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion lib/capistrano/dsl/chef.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
30 changes: 30 additions & 0 deletions spec/lib/capistrano/dsl/chef_spec.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions spec/lib/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rspec'

RSpec.configure do |c|
c.mock_with :rspec
end