Advertisement
SilverMysth

Untitled

Jun 1st, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.58 KB | None | 0 0
  1. danbooru@linux:~/danbooru$ cat vendor/bundle/ruby/2.1.0/gems/capistrano-3.4.0/spec/lib/capistrano/configuration_spec.rb
  2. require 'spec_helper'
  3.  
  4. module Capistrano
  5. describe Configuration do
  6. let(:config) { Configuration.new }
  7. let(:servers) { stub }
  8.  
  9. describe '.new' do
  10. it 'accepts initial hash' do
  11. configuration = described_class.new(custom: 'value')
  12. expect(configuration.fetch(:custom)).to eq('value')
  13. end
  14. end
  15.  
  16. describe '.env' do
  17. it 'is a global accessor to a single instance' do
  18. Configuration.env.set(:test, true)
  19. expect(Configuration.env.fetch(:test)).to be_truthy
  20. end
  21. end
  22.  
  23. describe '.reset!' do
  24. it 'blows away the existing `env` and creates a new one' do
  25. old_env = Configuration.env
  26. Configuration.reset!
  27. expect(Configuration.env).not_to be old_env
  28. end
  29. end
  30.  
  31. describe 'roles' do
  32. context 'adding a role' do
  33. subject { config.role(:app, %w{server1 server2}) }
  34.  
  35. before do
  36. Configuration::Servers.expects(:new).returns(servers)
  37. servers.expects(:add_role).with(:app, %w{server1 server2}, {})
  38. end
  39.  
  40. it 'adds the role' do
  41. expect(subject)
  42. end
  43. end
  44. end
  45.  
  46. describe 'setting and fetching' do
  47. subject { config.fetch(:key, :default) }
  48.  
  49. context 'value is set' do
  50. before do
  51. config.set(:key, :value)
  52. end
  53.  
  54. it 'returns the set value' do
  55. expect(subject).to eq :value
  56. end
  57. end
  58.  
  59. context 'set_if_empty' do
  60. it 'sets the value when none is present' do
  61. config.set_if_empty(:key, :value)
  62. expect(subject).to eq :value
  63. end
  64.  
  65. it 'does not overwrite the value' do
  66. config.set(:key, :value)
  67. config.set_if_empty(:key, :update)
  68. expect(subject).to eq :value
  69. end
  70. end
  71.  
  72. context 'value is not set' do
  73. it 'returns the default value' do
  74. expect(subject).to eq :default
  75. end
  76. end
  77.  
  78. context 'value is a proc' do
  79. subject { config.fetch(:key, Proc.new { :proc } ) }
  80. it 'calls the proc' do
  81. expect(subject).to eq :proc
  82. end
  83. end
  84.  
  85. context 'value is a lambda' do
  86. subject { config.fetch(:key, lambda { :lambda } ) }
  87. it 'calls the lambda' do
  88. expect(subject).to eq :lambda
  89. end
  90. end
  91.  
  92. context 'value inside proc inside a proc' do
  93. subject { config.fetch(:key, Proc.new { Proc.new { "some value" } } ) }
  94. it 'calls all procs and lambdas' do
  95. expect(subject).to eq "some value"
  96. end
  97. end
  98.  
  99. context 'value inside lambda inside a lambda' do
  100. subject { config.fetch(:key, lambda { lambda { "some value" } } ) }
  101. it 'calls all procs and lambdas' do
  102. expect(subject).to eq "some value"
  103. end
  104. end
  105.  
  106. context 'value inside lambda inside a proc' do
  107. subject { config.fetch(:key, Proc.new { lambda { "some value" } } ) }
  108. it 'calls all procs and lambdas' do
  109. expect(subject).to eq "some value"
  110. end
  111. end
  112.  
  113. context 'value inside proc inside a lambda' do
  114. subject { config.fetch(:key, lambda { Proc.new { "some value" } } ) }
  115. it 'calls all procs and lambdas' do
  116. expect(subject).to eq "some value"
  117. end
  118. end
  119.  
  120. context 'lambda with parameters' do
  121. subject { config.fetch(:key, lambda { |c| c }).call(42) }
  122. it 'is returned as a lambda' do
  123. expect(subject).to eq 42
  124. end
  125. end
  126.  
  127. context 'block is passed to fetch' do
  128. subject { config.fetch(:key, :default) { fail 'we need this!' } }
  129.  
  130. it 'returns the block value' do
  131. expect { subject }.to raise_error
  132. end
  133. end
  134. end
  135.  
  136. describe 'keys' do
  137. subject { config.keys }
  138.  
  139. before do
  140. config.set(:key1, :value1)
  141. config.set(:key2, :value2)
  142. end
  143.  
  144. it 'returns all set keys' do
  145. expect(subject).to match_array [:key1, :key2]
  146. end
  147. end
  148.  
  149. describe 'deleting' do
  150. before do
  151. config.set(:key, :value)
  152. end
  153.  
  154. it 'deletes the value' do
  155. config.delete(:key)
  156. expect(config.fetch(:key)).to be_nil
  157. end
  158. end
  159.  
  160. describe 'asking' do
  161. let(:question) { stub }
  162. let(:options) { Hash.new }
  163.  
  164. before do
  165. Configuration::Question.expects(:new).with(:branch, :default, options).
  166. returns(question)
  167. end
  168.  
  169. it 'prompts for the value when fetching' do
  170. config.ask(:branch, :default, options)
  171. expect(config.fetch(:branch)).to eq question
  172. end
  173. end
  174.  
  175. describe 'setting the backend' do
  176. it 'by default, is SSHKit' do
  177. expect(config.backend).to eq SSHKit
  178. end
  179.  
  180. it 'can be set to another class' do
  181. config.backend = :test
  182. expect(config.backend).to eq :test
  183. end
  184.  
  185. describe "ssh_options for Netssh" do
  186. it 'merges them with the :ssh_options variable' do
  187. config.set :format, :pretty
  188. config.set :log_level, :debug
  189. config.set :ssh_options, { user: 'albert' }
  190. SSHKit::Backend::Netssh.configure do |ssh| ssh.ssh_options = { password: 'einstein' } end
  191. config.configure_backend
  192. expect(config.backend.config.backend.config.ssh_options).to eq({ user: 'albert', password: 'einstein' })
  193. end
  194. end
  195. end
  196. end
  197. end
  198. danbooru@linux:~/danbooru$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement