cuken 0.1.4 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.relish +2 -0
- data/Gemfile +4 -4
- data/Gemfile.lock +17 -23
- data/VERSION +1 -1
- data/cuken.gems +108 -0
- data/cuken.gemspec +33 -10
- data/features/about.md +15 -2
- data/features/chef_examples/cookbooks_cookbook.feature +38 -3
- data/features/chef_examples/cookbooks_remote_repo.feature +10 -0
- data/features/chef_examples/cookbooks_repo.feature +5 -5
- data/features/{chef_steps → chef_examples}/knife_admin_client.feature +4 -4
- data/features/chef_examples/knife_client_create.feature +13 -0
- data/features/chef_steps/common_steps.feature +2 -2
- data/features/chef_steps/cookbook_steps.feature +12 -5
- data/features/chef_steps/node_steps.feature +1 -1
- data/features/file_steps/file_steps.feature +11 -11
- data/lib/cuken/all.rb +4 -0
- data/lib/cuken/api/chef/common.rb +46 -8
- data/lib/cuken/api/chef/knife.rb +107 -0
- data/lib/cuken/api/chef.rb +21 -13
- data/lib/cuken/api/common.rb +12 -0
- data/lib/cuken/api/rvm.rb +501 -0
- data/lib/cuken/api/ssh-forever.rb +237 -0
- data/lib/cuken/chef.rb +2 -0
- data/lib/cuken/common.rb +1 -0
- data/lib/cuken/cucumber/chef/common.rb +4 -2
- data/lib/cuken/cucumber/chef/cookbook.rb +87 -12
- data/lib/cuken/cucumber/chef/data_bag.rb +27 -0
- data/lib/cuken/cucumber/chef/knife.rb +10 -0
- data/lib/cuken/cucumber/chef/node.rb +20 -8
- data/lib/cuken/cucumber/chef/role.rb +18 -1
- data/lib/cuken/cucumber/chef.rb +5 -3
- data/lib/cuken/cucumber/cmd.rb +1 -1
- data/lib/cuken/cucumber/file.rb +18 -2
- data/lib/cuken/cucumber/rvm.rb +4 -0
- data/lib/cuken/rvm.rb +3 -0
- data/spec/api/knife_spec.rb +94 -0
- data/spec/api/rvm_spec.rb +274 -0
- data/spec/api/rvmrc_processor_spec.rb +288 -0
- data/spec/spec_helper.rb +58 -2
- metadata +67 -30
@@ -0,0 +1,94 @@
|
|
1
|
+
require Pathname(__FILE__).ascend { |d| h=d+'spec_helper.rb'; break h if h.file? }
|
2
|
+
|
3
|
+
module ::Cuken::Api::Chef
|
4
|
+
|
5
|
+
describe Knife do
|
6
|
+
before :all do
|
7
|
+
::Chef::Config[:node_name] = "webmonkey.example.com"
|
8
|
+
@knife = ::Chef::Knife::ClientCreate.new
|
9
|
+
@knife.config = {
|
10
|
+
:file => nil
|
11
|
+
}
|
12
|
+
@client = ::Chef::ApiClient.new
|
13
|
+
end
|
14
|
+
describe "#create_client(data)" do
|
15
|
+
it "should create a new named admin Client" do
|
16
|
+
data = {:name => 'Im_new_here',
|
17
|
+
:config_file => '/some/knife.rb',
|
18
|
+
:admin => true,
|
19
|
+
:file => '/some/sekret.pem',
|
20
|
+
:no_editor => true}
|
21
|
+
any_instance_of(::Chef::ApiClient) do |u|
|
22
|
+
stub(u).name.with(data[:name]).times(1)
|
23
|
+
stub(u).name.with("").times(1) # some json creation routine
|
24
|
+
stub(u).admin.with(data[:admin]).times(1)
|
25
|
+
stub(u).admin.with(false).times(1) # some json creation routine
|
26
|
+
stub(u).save{ { 'private_key' => 'sekret' } }
|
27
|
+
end
|
28
|
+
stub(Chef::Config).from_file.with(is_a(String))
|
29
|
+
FakeFS do
|
30
|
+
chef.knife.create_client(data)
|
31
|
+
File.read(data[:file]).should == 'sekret'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
it "should create a new named non-admin Client" do
|
35
|
+
data = {:name => 'Im_new_here',
|
36
|
+
:config_file => '/some/knife.rb',
|
37
|
+
:admin => false,
|
38
|
+
:file => '/some/sekret2.pem',
|
39
|
+
:no_editor => true}
|
40
|
+
any_instance_of(::Chef::ApiClient) do |u|
|
41
|
+
stub(u).name.with(data[:name]).times(1)
|
42
|
+
stub(u).name.with("").times(1) # some json creation routine
|
43
|
+
stub(u).admin.with(nil).times(1)
|
44
|
+
stub(u).admin.with(false).times(1) # some json creation routine
|
45
|
+
stub(u).save{ { 'private_key' => 'sekret2' } }
|
46
|
+
end
|
47
|
+
stub(Chef::Config).from_file.with(is_a(String))
|
48
|
+
FakeFS do
|
49
|
+
chef.knife.create_client(data)
|
50
|
+
File.read(data[:file]).should == 'sekret2'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
describe "#show_client(data)" do
|
55
|
+
it "should show a named Client" do
|
56
|
+
data = {:name => 'Im_new_here',
|
57
|
+
:config_file => '/some/knife.rb',
|
58
|
+
:file => '/some/sekret.pem',
|
59
|
+
:no_editor => true}
|
60
|
+
stub(Chef::Config).from_file.with(is_a(String))
|
61
|
+
stub(Chef::ApiClient).load.with(data[:name]){['somthing: displayed']}
|
62
|
+
FakeFS do
|
63
|
+
chef.knife.show_client(data).should be_nil
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
# describe "#check_client(data)" do
|
69
|
+
# it "should check a named Client" do
|
70
|
+
# data = {:name => 'Im_new_here',
|
71
|
+
# :file => '/some/sekret.pem',
|
72
|
+
# :no_editor => true}
|
73
|
+
# stub(Chef::Config).from_file.with(is_a(String))
|
74
|
+
# stub(Chef::ApiClient).load.with(data[:name]){['somthing: displayed']}
|
75
|
+
# FakeFS do
|
76
|
+
# chef.knife.check_client(data).should match /somthing: displayed/
|
77
|
+
# end
|
78
|
+
# end
|
79
|
+
# end
|
80
|
+
describe "#delete_client(data)" do
|
81
|
+
it "should delete a named Client" do
|
82
|
+
data = {:name => 'Im_new_here',
|
83
|
+
:config_file => '/some/knife.rb',
|
84
|
+
:file => '/some/sekret.pem',
|
85
|
+
:no_editor => true}
|
86
|
+
stub(Chef::Config).from_file.with(is_a(String))
|
87
|
+
stub(Chef::ApiClient).load.with(data[:name]){stub!.destroy{true}}
|
88
|
+
FakeFS do
|
89
|
+
chef.knife.delete_client(data).should be_nil
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,274 @@
|
|
1
|
+
require Pathname(__FILE__).ascend { |d| h=d+'spec_helper.rb'; break h if h.file? }
|
2
|
+
|
3
|
+
#Reference:
|
4
|
+
# http://www.metaskills.net/2010/07/30/the-rvm-ruby-api/
|
5
|
+
|
6
|
+
module ::Cuken::Api
|
7
|
+
describe Rvm do
|
8
|
+
before(:all) do
|
9
|
+
include ::Cuken::Api::Rvm
|
10
|
+
# ::FakeFS.activate!
|
11
|
+
# ::FakeFS::FileSystem.clear
|
12
|
+
@rvmrc_root = setup_rvmrc_gems_files(1)
|
13
|
+
@rvmrc_file = Dir.glob(@rvmrc_root + '/**' + '/.rvmrc')[-1]
|
14
|
+
end
|
15
|
+
before(:each) do
|
16
|
+
puts self.class
|
17
|
+
@rvmrc_processor= ::Cuken::Api::Rvm::RvmrcProcessor.new(@rvmrc_file)
|
18
|
+
end
|
19
|
+
after(:all) do
|
20
|
+
# ::FakeFS.deactivate!
|
21
|
+
end
|
22
|
+
# context ".b3_setup" do
|
23
|
+
# it "should set the path to BigBlueButton's sources root" do
|
24
|
+
# ::Cuken::Api::Rvm.rvm_setup.directory?.should be_true
|
25
|
+
# end
|
26
|
+
# it "should raise an error if the path to BigBlueButton's sources root does not exist" do
|
27
|
+
# FakeFS { lambda{ ::B3::Bdd::Helpers.b3_setup}.should raise_error(RuntimeError, /Could not find BigBlueButton's sources root./) }
|
28
|
+
# end
|
29
|
+
# end
|
30
|
+
|
31
|
+
describe ".rvm_current_name" do
|
32
|
+
it "should return the full rubie and gemset name" do
|
33
|
+
::Cuken::Api::Rvm.rvm_current_name.should =~ /ruby(.*)@(.*)/
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe ".rvm_path" do
|
38
|
+
it "should return a Pathname of the rvm_path environment variable" do
|
39
|
+
::Cuken::Api::Rvm.rvm_path.should be_kind_of Pathname
|
40
|
+
end
|
41
|
+
it "should return the path to RVM's install root if it exists" do
|
42
|
+
::Cuken::Api::Rvm.rvm_path.directory?.should be_true
|
43
|
+
end
|
44
|
+
it "should raise an error if RVM's install root does not exist" do
|
45
|
+
FakeFS { lambda{ ::Cuken::Api::Rvm.rvm_path}.should raise_error(RuntimeError, /Could not find RVM's .rvm folder/) }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
describe ".rvm_local_install?" do
|
49
|
+
it "should indicate RVM is installed locally" do
|
50
|
+
::Cuken::Api::Rvm.rvm_local_install?.should be_true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context ".rvm_loaded? with RVM" do
|
55
|
+
it "should return true when RVM is installed locally" do
|
56
|
+
::Cuken::Api::Rvm.rvm_loaded?.should be_true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context ".rvm_loaded? without RVM" do
|
61
|
+
it "should return false when RVM is not installed locally" do
|
62
|
+
FakeFS do
|
63
|
+
::Cuken::Api::Rvm.rvm_loaded?.should be_false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context ".rvm_gemset_paths with root path argument" do
|
69
|
+
it "should return default paths requiring RVM gemsets be loaded" do
|
70
|
+
FakeFS do
|
71
|
+
root_path = setup_rvmrc_gems_files(8)
|
72
|
+
::Cuken::Api::Rvm.rvm_gemset_paths(root_path).should have(9).items
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context ".rvmrc_rubies_gemsets without root path argument" do
|
78
|
+
it "should return a hash whose keys are rubies (in the .rvmrc files)" do
|
79
|
+
FakeFS do
|
80
|
+
root_path = setup_rvmrc_gems_files(1)
|
81
|
+
::Cuken::Api::Rvm.rvmrc_rubies_gemsets(root_path).should be_kind_of(Hash)
|
82
|
+
::Cuken::Api::Rvm.rvmrc_rubies_gemsets(root_path).keys.each {|k| k.should match /ruby/ }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
it "should return a hash whose values are array of gemsets (in the .rvmrc files)" do
|
86
|
+
::Cuken::Api::Rvm.rvmrc_rubies_gemsets.each do |k, v|
|
87
|
+
k.should match /ruby/
|
88
|
+
v.should be_kind_of(Array)
|
89
|
+
v.each{|elem| elem.should be_kind_of(Hash) }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
it "should return RVM gemsets names that exist in the .rvmrc files" do
|
93
|
+
FakeFS do
|
94
|
+
root_path = setup_rvmrc_gems_files(8)
|
95
|
+
res = ::Cuken::Api::Rvm.rvmrc_rubies_gemsets(root_path)
|
96
|
+
res.should have(1).item
|
97
|
+
res.first.last.should have(9).items
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context ".rvmrc_rubies without root path argument" do
|
103
|
+
it "should return RVM Ruby names that exist in the .rvmrc files" do
|
104
|
+
::Cuken::Api::Rvm.rvm_install_rubies = {'ruby-1.9.2-p136' => {:alias => 'cuken192'}}
|
105
|
+
res = ::Cuken::Api::Rvm.rvmrc_rubies
|
106
|
+
res.should have(1).item
|
107
|
+
res.first.should have(2).items
|
108
|
+
end
|
109
|
+
it "should contain an alias with prefix cuken-" do
|
110
|
+
::Cuken::Api::Rvm.rvmrc_rubies.each do |k, v|
|
111
|
+
v[:alias].should match /\Acuken-/
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context ".rvm_rubies_setup without root path argument" do
|
117
|
+
it "should raise an error if RVM's install root does not exist" do
|
118
|
+
FakeFS { lambda{ ::Cuken::Api::Rvm.rvm_rubies_setup}.should raise_error(RuntimeError, /RVM library not loaded./) }
|
119
|
+
end
|
120
|
+
it "should not install existing RVM rubies that exists in the .rvmrc files" do
|
121
|
+
rvm_now=(`rvm current`)[/(.*)@/,1]
|
122
|
+
mock(::RVM).install(rvm_now,{}).times(0){true}
|
123
|
+
mock(::RVM).alias_create.with(is_a(String),/@vagrant/).times(1) { true }
|
124
|
+
::Cuken::Api::Rvm.rvm_rubies_setup.should have(1).item
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe ".rvm_install_gemspecs" do
|
129
|
+
it "should return an array of 2-element arrays with gem name and version" do
|
130
|
+
::Cuken::Api::Rvm.rvm_install_gemspecs << ['gem_a', '1.0.0']
|
131
|
+
::Cuken::Api::Rvm.rvm_install_gemspecs << ['gem_b', '2.0.0']
|
132
|
+
::Cuken::Api::Rvm.rvm_install_gemspecs.should == [["bundler", "1.0.10"], ["gem_a", "1.0.0"], ["gem_b", "2.0.0"]]
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe ".rvm_create_gemsets" do
|
137
|
+
it "should return an array of gemsets names" do
|
138
|
+
::Cuken::Api::Rvm.rvm_create_gemsets << 'gemset_a'
|
139
|
+
::Cuken::Api::Rvm.rvm_create_gemsets << 'gemset_b'
|
140
|
+
::Cuken::Api::Rvm.rvm_create_gemsets.should == ["gemset_a", "gemset_b"]
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context ".rvmrc_gems_install" do
|
145
|
+
it "should require a directory path argument" do
|
146
|
+
lambda{::Cuken::Api::Rvm.rvmrc_gems_install}.should raise_error(ArgumentError, /wrong number of arguments \(0 for 1\)/)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context ".rvmrc_gems_install when gem is not installed" do
|
151
|
+
it "should install gems added to rvm_install_gemspecs" do
|
152
|
+
FakeFS do
|
153
|
+
root_path = setup_rvmrc_gems_files(8)
|
154
|
+
::Cuken::Api::Rvm.rvm_install_gemspecs << ['gem_a', '1.0.0']
|
155
|
+
::Cuken::Api::Rvm.rvm_install_gemspecs << ['gem_b', '2.0.0']
|
156
|
+
mock(::RVM).use.with("ruby-1.9.2-p136").times(2){true}
|
157
|
+
#mock(::RVM).gemset.stub!.create.with(is_a(String)).times(9){true}
|
158
|
+
mock(::RVM).gemset.times(27).stub!.use!.with(is_a(String)).times(27){true}
|
159
|
+
# mock(::RVM).gemset_import.with(is_a(String)).times(8) { true }
|
160
|
+
#mock(::RVM).perform_set_operation.with(is_a(Symbol),is_a(String),is_a(String),is_a(String),is_a(String)).times(4){ stub!.stdout{ "some progress messages" } }
|
161
|
+
#mock(::RVM).perform_set_operation.with(is_a(Symbol),is_a(String),is_a(String),is_a(String),is_a(String)).times(4){ stub!.stdout{ "some progress messages" } }
|
162
|
+
mock(::RVM).ruby_eval.with(is_a(String)).times(27){ stub!.stdout{'false'}}
|
163
|
+
mock(::RVM).run.with(is_a(String)).times(27){ stub!.stdout{'false'}}
|
164
|
+
::Cuken::Api::Rvm.rvmrc_gems_install(root_path).should be_true
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
context ".rvmrc_gems_install when gem is installed" do
|
170
|
+
it "should not install gems added to rvm_install_gemspecs" do
|
171
|
+
FakeFS do
|
172
|
+
root_path = setup_rvmrc_gems_files(8)
|
173
|
+
::Cuken::Api::Rvm.rvm_install_gemspecs << ['gem_a', '1.0.0']
|
174
|
+
::Cuken::Api::Rvm.rvm_install_gemspecs << ['gem_b', '2.0.0']
|
175
|
+
stub(::RVM).use.verbose.with(is_a(String))
|
176
|
+
#stub(::RVM).gemset.times(27).stub!.create.verbose.with(is_a(Array)).times(27){true}
|
177
|
+
stub(::RVM).gemset.times(27).stub!.use.verbose.with(is_a(String)).times(27){true}
|
178
|
+
# mock(::RVM).use.with(is_a(String)).times(1){true}
|
179
|
+
# mock(::RVM).gemset_import.with(is_a(String)).times(8) { true }
|
180
|
+
mock(::RVM).perform_set_operation.with(is_a(Symbol),is_a(String),is_a(String),is_a(String),is_a(String)).times(0){ stub!.stdout{ "some progress messages" } }
|
181
|
+
mock(::RVM).ruby_eval.with(is_a(String)).times(27){ stub!.stdout{'true'}}
|
182
|
+
::Cuken::Api::Rvm.rvmrc_gems_install(root_path).should be_true
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
# context ".rvmrc_gemsets_install when gemset is not installed" do
|
188
|
+
# it "should install gemsets found in .rvmrc files" do
|
189
|
+
# FakeFS do
|
190
|
+
# root_path = setup_rvmrc_gems_files(8)
|
191
|
+
# mock(::RVM).use.with(is_a(String)).times(1){true}
|
192
|
+
# mock(::RVM).gemset_import.with(is_a(String)).times(8) { true }
|
193
|
+
# #mock(::RVM).perform_set_operation.with(is_a(Symbol),is_a(String),is_a(String),is_a(String),is_a(String)).times(3){ stub!.stdout{ "some progress messages" } }
|
194
|
+
# #mock(::RVM).ruby_eval.with(is_a(String)).times(3){ stub!.stdout{'false'}}
|
195
|
+
# ::Cuken::Api::Rvm.rvmrc_gems_install(root_path).should be_true
|
196
|
+
# end
|
197
|
+
# end
|
198
|
+
# end
|
199
|
+
#
|
200
|
+
# context ".rvmrc_gemsets_install" do
|
201
|
+
# it "should require a directory path argument" do
|
202
|
+
# lambda{::Cuken::Api::Rvm.rvmrc_gemsets_install}.should raise_error(ArgumentError, /wrong number of arguments \(0 for 1\)/)
|
203
|
+
# end
|
204
|
+
# end
|
205
|
+
|
206
|
+
describe ".rvm_steup" do
|
207
|
+
it "should require RVM and the libraries this API requires"
|
208
|
+
end
|
209
|
+
|
210
|
+
describe "_rvm_current_rubie_name" do
|
211
|
+
it "should return the rubie name without any gemset"
|
212
|
+
end
|
213
|
+
describe "#rvm_gem_available?(spec)" do
|
214
|
+
it "should expect gem name and version as an array"
|
215
|
+
it "should return true if the gem can be required"
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
#module B3
|
221
|
+
# module Bdd
|
222
|
+
# module Helpers
|
223
|
+
#
|
224
|
+
# end
|
225
|
+
# end
|
226
|
+
#end
|
227
|
+
#describe ::B3::Bdd::Helpers do
|
228
|
+
# context ".b3_setup" do
|
229
|
+
# it "should set the path to BigBlueButton's sources root" do
|
230
|
+
# ::B3::Bdd::Helpers.b3_setup.directory?.should be_true
|
231
|
+
# end
|
232
|
+
# it "should raise an error if the path to BigBlueButton's sources root does not exist" do
|
233
|
+
# FakeFS { lambda{ ::B3::Bdd::Helpers.b3_setup}.should raise_error(RuntimeError, /Could not find BigBlueButton's sources root./) }
|
234
|
+
# end
|
235
|
+
# end
|
236
|
+
#
|
237
|
+
# context ".b3_bdd_feature_sets(hsh)" do
|
238
|
+
# it "should return the subset of hash having feature sets" do
|
239
|
+
# hsh = ::B3::Bdd::Helpers.b3_bdd_feature_sets
|
240
|
+
# hsh.first.last.should have(3).items
|
241
|
+
# hsh.should be_kind_of(Hash)
|
242
|
+
# hsh.each do |k, v|
|
243
|
+
# k.should match /ruby/
|
244
|
+
# v.each{|elem| elem.key? :feature_set_name }
|
245
|
+
# end
|
246
|
+
# end
|
247
|
+
# end
|
248
|
+
#
|
249
|
+
# context ".b3_bdd_features_parser" do
|
250
|
+
# it "should accept an empty hash and return default set_profile" do
|
251
|
+
# hsh = ::B3::Bdd::Helpers.b3_bdd_features_parser
|
252
|
+
# hsh.keys.should == [:set_profile]
|
253
|
+
# hsh[:set_profile].keys.should == ["bbb_bdd_app", "bbb_bdd_sys_os", "bbb_bdd_meta_bdd"]
|
254
|
+
# hsh.each do |k, v|
|
255
|
+
# k.should match /ruby/
|
256
|
+
# v.each do |elem|
|
257
|
+
# elem.key?(:feature_set_name).should be_true
|
258
|
+
# elem.key?(:profiles).should be_true
|
259
|
+
# elem.value(:profiles).should == ["default"]
|
260
|
+
# end
|
261
|
+
# end
|
262
|
+
# end
|
263
|
+
# end
|
264
|
+
#
|
265
|
+
# context ".b3_bdd_run :feature" do
|
266
|
+
# it "should run all feature sets with default Cucumber profile" do
|
267
|
+
# mock(::RVM).use.with(is_a(String)).times(8){true}
|
268
|
+
# mock(::RVM).use_from_path!.with(is_a(String)).times(3){true}
|
269
|
+
# mock(::Open4).popen4.with(is_a(String)).times(3) { true }
|
270
|
+
# ::B3::Bdd::Helpers.b3_bdd_run(:feature,{}).should be_true
|
271
|
+
# end
|
272
|
+
# end
|
273
|
+
#
|
274
|
+
#end
|
@@ -0,0 +1,288 @@
|
|
1
|
+
require Pathname(__FILE__).ascend { |d| h=d+'spec_helper.rb'; break h if h.file? }
|
2
|
+
|
3
|
+
|
4
|
+
module ::Cuken::Api::Rvm
|
5
|
+
describe RvmrcProcessor do
|
6
|
+
before(:all) do
|
7
|
+
::FakeFS.activate!
|
8
|
+
::FakeFS::FileSystem.clear
|
9
|
+
@rvmrc_root = setup_rvmrc_gems_files(1)
|
10
|
+
@rvmrc_file = Dir.glob(@rvmrc_root + '/**' + '/.rvmrc')[-1]
|
11
|
+
end
|
12
|
+
before(:each) do
|
13
|
+
@rvmrc_processor= ::Cuken::Api::Rvm::RvmrcProcessor.new(@rvmrc_file)
|
14
|
+
end
|
15
|
+
after(:all) do
|
16
|
+
::FakeFS.deactivate!
|
17
|
+
end
|
18
|
+
describe "#rvmrc_read" do
|
19
|
+
context "given the path to a .rvmrc file" do
|
20
|
+
it "should return the file contents" do
|
21
|
+
rvmrc_contents = @rvmrc_processor.rvmrc_read(@rvmrc_file)
|
22
|
+
rvmrc_contents.should be_true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
context "given the path to folder with a .rvmrc file" do
|
26
|
+
it "should read the file contents and return true on success" do
|
27
|
+
rvmrc_contents = @rvmrc_processor.rvmrc_read(File.dirname(@rvmrc_file))
|
28
|
+
rvmrc_contents.should be_true
|
29
|
+
end
|
30
|
+
describe "#rvmrc" do
|
31
|
+
it "should return the contents of the .rvmrc file" do
|
32
|
+
@rvmrc_processor.rvmrc_read(@rvmrc_file)
|
33
|
+
@rvmrc_processor.rvmrc.size.should == 544
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "having read the .rvmrc file" do
|
40
|
+
before(:all) do
|
41
|
+
@rvmrc_processor = ::Cuken::Api::Rvm::RvmrcProcessor.new(@rvmrc_file)
|
42
|
+
end
|
43
|
+
describe "#rvmrc_ruby_name" do
|
44
|
+
it "should return the rubie name from the .rvmrc file" do
|
45
|
+
@rvmrc_processor.rvmrc_ruby_name.should == "ruby-1.9.2-p136"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
describe "#rvmrc_gemset_name" do
|
49
|
+
it "should return the gemset name from the .rvmrc file" do
|
50
|
+
@rvmrc_processor.rvmrc_gemset_name.should == "1"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
describe "#find_rvmrc_files" do
|
54
|
+
it "should return an array of .rvmrc file paths found beneath a root folder" do
|
55
|
+
@rvmrc_processor.find_rvmrc_files(@rvmrc_root).should == ["/path/to/dir/.rvmrc", "/path/to/dir/1/.rvmrc"]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
describe "#find_rvmrc_paths" do
|
59
|
+
context "when given a folder path" do
|
60
|
+
it "should return an array of paths to .rvmrc files found beneath a root folder" do
|
61
|
+
@rvmrc_processor.find_rvmrc_paths(@rvmrc_root).should == ["/path/to/dir", "/path/to/dir/1"]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
context "when given a file path" do
|
65
|
+
it "should return an array of paths to .rvmrc files found beneath a root folder" do
|
66
|
+
@rvmrc_processor.find_rvmrc_paths(@rvmrc_root+'/.rvmrc').should == ["/path/to/dir", "/path/to/dir/1"]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
describe "#find_gems_files" do
|
71
|
+
it "should return an array of *.gems file paths found beneath a root folder" do
|
72
|
+
@rvmrc_processor.find_gems_files(@rvmrc_root).should == ["/path/to/dir/1/1.gems", "/path/to/dir/dir.gems"]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
describe "#all_rubies_gemsets" do
|
76
|
+
context "when passed a folder path" do
|
77
|
+
it "should return a hash whose keys are rubies (in the .rvmrc files)" do
|
78
|
+
@rvmrc_processor.all_rubies_gemsets(@rvmrc_root).should be_kind_of(Hash)
|
79
|
+
@rvmrc_processor.all_rubies_gemsets(@rvmrc_root).keys.each {|k| k.should match /ruby/ }
|
80
|
+
end
|
81
|
+
it "should return a hash whose values are array of gemsets (in the .rvmrc files)" do
|
82
|
+
@rvmrc_processor.all_rubies_gemsets(@rvmrc_root).each do |k, v|
|
83
|
+
k.should match /ruby/
|
84
|
+
v.should be_kind_of(Array)
|
85
|
+
v.each do |elem|
|
86
|
+
elem.keys.should == [:ruby_alias, :gemset_alias, :gemset_name,:gemset_path]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
it "should return RVM gemsets names that exist in the .rvmrc files" do
|
91
|
+
root_path = setup_rvmrc_gems_files(8)
|
92
|
+
res = @rvmrc_processor.all_rubies_gemsets(root_path)
|
93
|
+
res.should have(1).item
|
94
|
+
res.first.last.should have(9).items
|
95
|
+
res.first.last[0].keys.should == [:ruby_alias, :gemset_alias, :gemset_name, :gemset_path]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
context "when not passed a folder path it uses the path passed to new and" do
|
99
|
+
it "should return a hash whose keys are rubies (in the .rvmrc files)" do
|
100
|
+
@rvmrc_processor.all_rubies_gemsets.should be_kind_of(Hash)
|
101
|
+
@rvmrc_processor.all_rubies_gemsets.keys.each {|k| k.should match /ruby/ }
|
102
|
+
end
|
103
|
+
it "should return a hash whose values are array of gemsets (in the .rvmrc files)" do
|
104
|
+
@rvmrc_processor.all_rubies_gemsets.each do |k, v|
|
105
|
+
k.should match /ruby/
|
106
|
+
v.should be_kind_of(Array)
|
107
|
+
v.each do |elem|
|
108
|
+
elem.keys.should == [:ruby_alias, :gemset_alias, :gemset_name,:gemset_path]
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
it "should return RVM gemsets names that exist in the .rvmrc files" do
|
113
|
+
res = @rvmrc_processor.all_rubies_gemsets
|
114
|
+
res.should have(1).item
|
115
|
+
res.first.last.should have(8).items
|
116
|
+
res.first.last[0].keys.should == [:ruby_alias, :gemset_alias, :gemset_name, :gemset_path]
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
describe "#all_gemsets" do
|
121
|
+
context "when passed a folder path" do
|
122
|
+
it "should return an Hash" do
|
123
|
+
@rvmrc_processor.all_gemsets(@rvmrc_root).should be_kind_of Hash
|
124
|
+
end
|
125
|
+
it "should use as keys the rubies found in .rvmrc files beneath a root folder" do
|
126
|
+
@rvmrc_processor.all_gemsets(@rvmrc_root).keys.should == ["ruby-1.9.2-p136"]
|
127
|
+
end
|
128
|
+
it "should return the alias and gemsets per ruby found in .rvmrc files beneath a root folder" do
|
129
|
+
@rvmrc_processor.all_gemsets(@rvmrc_root)["ruby-1.9.2-p136"].keys.should == [:ruby_alias, :gemsets]
|
130
|
+
end
|
131
|
+
end
|
132
|
+
context "when not passed a folder path" do
|
133
|
+
it "should return an Hash" do
|
134
|
+
@rvmrc_processor.all_gemsets.should be_kind_of Hash
|
135
|
+
end
|
136
|
+
it "should use as keys the rubies found in .rvmrc files beneath a root folder" do
|
137
|
+
@rvmrc_processor.all_gemsets.keys.should == ["ruby-1.9.2-p136"]
|
138
|
+
end
|
139
|
+
it "should return the alias and gemsets per ruby found in .rvmrc files beneath a root folder" do
|
140
|
+
@rvmrc_processor.all_gemsets["ruby-1.9.2-p136"].keys.should == [:ruby_alias, :gemsets]
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
describe "#all_rubies" do
|
145
|
+
it "should return an Array" do
|
146
|
+
@rvmrc_processor.all_rubies(@rvmrc_root).should be_kind_of Array
|
147
|
+
end
|
148
|
+
it "should return the rubies found in .rvmrc files beneath a root folder" do
|
149
|
+
@rvmrc_processor.all_rubies(@rvmrc_root).should == ["ruby-1.9.2-p136"]
|
150
|
+
end
|
151
|
+
end
|
152
|
+
describe "#each_ruby" do
|
153
|
+
it "should use each of the installed rubies" do
|
154
|
+
@rvmrc_processor.all_rubies(@rvmrc_root).each do |rubie|
|
155
|
+
mock(::RVM).use.with(rubie).times(1){true}.should be_true
|
156
|
+
end
|
157
|
+
@rvmrc_processor.each_ruby do |rubie|
|
158
|
+
true
|
159
|
+
end
|
160
|
+
end
|
161
|
+
it "should yield a block in the environment of each in the installed rubies" do
|
162
|
+
@rvmrc_processor.all_rubies(@rvmrc_root).each do |rubie|
|
163
|
+
mock(::RVM).use.with(rubie).times(1){true}.should be_true
|
164
|
+
return_value = @rvmrc_processor.each_ruby do |rubie|
|
165
|
+
raise unless match /ruby/
|
166
|
+
end
|
167
|
+
return_value.should==[rubie]
|
168
|
+
end
|
169
|
+
end
|
170
|
+
it "should return current Ruby string even if the given block raises in the environment of each in the installed rubies" do
|
171
|
+
@rvmrc_processor.all_rubies(@rvmrc_root).each do |rubie|
|
172
|
+
mock(::RVM).use.with(rubie).times(1){true}.should be_true
|
173
|
+
lambda {
|
174
|
+
return_value = @rvmrc_processor.each_ruby do |rubie|
|
175
|
+
raise if match /ruby/
|
176
|
+
end
|
177
|
+
return_value.should==[rubie]
|
178
|
+
}.should_not raise_error RuntimeError
|
179
|
+
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
describe "#create_gemsets" do
|
184
|
+
it "should create gemsets parsed from all .rvmrc files beneath a root folder" do
|
185
|
+
mock(::RVM).use.with(is_a(String)).times(1){true}
|
186
|
+
mock(::RVM).gemset.times(8).stub!.create.with(is_a(Array)).times(8){true}
|
187
|
+
@rvmrc_processor.create_gemsets
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
describe "gemspecs_to_install" do
|
192
|
+
it "should always install Bundler 1.0.10" do
|
193
|
+
@rvmrc_processor.gemspecs_to_install == [["bundler", "1.0.10"]]
|
194
|
+
end
|
195
|
+
it "should return an array of 2-element arrays with gem name and version" do
|
196
|
+
@rvmrc_processor.gemspecs_to_install << ['gem_a', '1.0.0']
|
197
|
+
@rvmrc_processor.gemspecs_to_install << ['gem_b', '2.0.0']
|
198
|
+
@rvmrc_processor.gemspecs_to_install == [["bundler", "1.0.10"], ["gem_a", "1.0.0"], ["gem_b", "2.0.0"]]
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
# Some subtle issue with this spec it fails whenthe whole file is run,
|
203
|
+
# but passes when run in isolation.
|
204
|
+
describe "#gems_install" do
|
205
|
+
it "should install gems from install_gemspecs_list into gemsets parsed from all .rvmrc files beneath a root folder" do
|
206
|
+
stub(@rvmrc_processor).install_gem.with(is_a(String),is_a(Array)).times(1){true}
|
207
|
+
@rvmrc_processor.gems_install
|
208
|
+
end
|
209
|
+
end
|
210
|
+
describe "#gem_install_options" do
|
211
|
+
it "should return the options string for Ruby's `gem install...` CLI" do
|
212
|
+
@rvmrc_processor.gem_install_options.should == "--no_ri --no_rdoc"
|
213
|
+
end
|
214
|
+
end
|
215
|
+
# Some subtle issue with this spec it fails whenthe whole file is run,
|
216
|
+
# but passes when run in isolation.
|
217
|
+
describe "#install_gem(rubie, spec)" do
|
218
|
+
context "when the gem is not installed" do
|
219
|
+
# Some subtle issue with this spec it fails whenthe whole file is run,
|
220
|
+
# but passes when run in isolation.
|
221
|
+
it "should install given gem into all ruby+gemsets parsed from .rvmrc files beneath a root folder" do
|
222
|
+
#mock(::RVM).use.with(is_a(String)).times(1){true}
|
223
|
+
stub(@rvmrc_processor).gem_available?.with(is_a(Array)).times(1){false}
|
224
|
+
mock(::RVM).gemset.times(1).stub!.use.with(is_a(String)).times(1){true}
|
225
|
+
mock(::RVM).run.with(is_a(String)).times(1){true}
|
226
|
+
@rvmrc_processor.install_gem("ruby-1.9.2-p136",["bundler", "1.0.10"])
|
227
|
+
end
|
228
|
+
end
|
229
|
+
context "when the gem is installed" do
|
230
|
+
it "should not install given gem into all ruby+gemsets parsed from .rvmrc files beneath a root folder" do
|
231
|
+
#mock(::RVM).use.with(is_a(String)).times(1){true}
|
232
|
+
stub(@rvmrc_processor).gem_available?.with(is_a(Array)).times(8){true}
|
233
|
+
mock(::RVM).gemset.times(0).stub!.use.with(is_a(String)).times(0){true}
|
234
|
+
mock(::RVM).run.with(is_a(String)).times(0){true}
|
235
|
+
@rvmrc_processor.install_gem("ruby-1.9.2-p136",["bundler", "1.0.10"])
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
describe "#current_ruby_info" do
|
241
|
+
it "should return the parsed .rvmrc info for the current ruby" do
|
242
|
+
@rvmrc_processor.current_ruby_info('ruby-1.9.2-p136').each do |hsh|
|
243
|
+
hsh.keys.should == [:ruby_alias, :gemset_alias, :gemset_name, :gemset_path]
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
describe "#setup_rubies " do
|
249
|
+
it "should raise an error if RVM's install root does not exist" do
|
250
|
+
lambda{ ::Cuken::Api::Rvm::RvmrcProcessor.new('/junk') }.should raise_error(Errno::ENOENT, /No such file or directory/)
|
251
|
+
end
|
252
|
+
context "when RVM ruby exists " do
|
253
|
+
it "should not install a Ruby listed in the .rvmrc files" do
|
254
|
+
rvm_now=(`rvm current`)[/(.*)@/,1]
|
255
|
+
mock(::RVM).list_strings.times(1).stub!.include?.with(is_a(String)).times(1){true}
|
256
|
+
mock(::RVM).alias_create.with(/cuken_/,is_a(String)).times(1) { true }
|
257
|
+
stub(@rvmrc_processor).install_rubie.with(is_a(String)).times(0){true}
|
258
|
+
@rvmrc_processor.setup_rubies.should have(1).item
|
259
|
+
end
|
260
|
+
end
|
261
|
+
context "when RVM ruby does not exist " do
|
262
|
+
it "should install a Ruby listed in the .rvmrc files" do
|
263
|
+
rvm_now=(`rvm current`)[/(.*)@/,1]
|
264
|
+
mock(::RVM).list_strings.times(1).stub!.include?.with(is_a(String)).times(1){false}
|
265
|
+
mock(::RVM).alias_create.with(/cuken_/,is_a(String)).times(1) { true }
|
266
|
+
stub(@rvmrc_processor).install_rubie.with(is_a(String)).times(1){true}
|
267
|
+
@rvmrc_processor.setup_rubies.should have(1).item
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
271
|
+
describe "#rvm_path" do
|
272
|
+
it "should return a Pathname of the rvm_path environment variable" do
|
273
|
+
::FakeFS.deactivate!
|
274
|
+
@rvmrc_processor.rvm_path.should be_kind_of Pathname
|
275
|
+
::FakeFS.activate!
|
276
|
+
end
|
277
|
+
it "should return the path to RVM's install root if it exists" do
|
278
|
+
::FakeFS.deactivate!
|
279
|
+
@rvmrc_processor.rvm_path.directory?.should be_true
|
280
|
+
::FakeFS.activate!
|
281
|
+
end
|
282
|
+
it "should raise an error if RVM's install root does not exist" do
|
283
|
+
FakeFS { lambda{ @rvmrc_processor.rvm_path}.should raise_error(RuntimeError, /Could not find RVM's .rvm folder/) }
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|