Skip to content

Commit

Permalink
Add rspec tests for no options situation
Browse files Browse the repository at this point in the history
  • Loading branch information
eherot committed Apr 28, 2015
1 parent 39b743b commit e25422a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
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

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

0 comments on commit e25422a

Please sign in to comment.