ridley 4.2.0 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/Gemfile +1 -1
  4. data/README.md +4 -4
  5. data/lib/ridley/connection.rb +1 -2
  6. data/lib/ridley/errors.rb +1 -0
  7. data/lib/ridley/mixin/params_validate.rb +4 -0
  8. data/lib/ridley/version.rb +1 -1
  9. data/ridley.gemspec +2 -2
  10. data/spec/acceptance/client_resource_spec.rb +12 -12
  11. data/spec/acceptance/cookbook_resource_spec.rb +15 -15
  12. data/spec/acceptance/data_bag_item_resource_spec.rb +14 -14
  13. data/spec/acceptance/data_bag_resource_spec.rb +4 -4
  14. data/spec/acceptance/environment_resource_spec.rb +14 -14
  15. data/spec/acceptance/node_resource_spec.rb +15 -15
  16. data/spec/acceptance/role_resource_spec.rb +14 -14
  17. data/spec/acceptance/sandbox_resource_spec.rb +3 -3
  18. data/spec/acceptance/search_resource_spec.rb +6 -6
  19. data/spec/acceptance/user_resource_spec.rb +21 -21
  20. data/spec/support/each_matcher.rb +2 -2
  21. data/spec/support/filepath_matchers.rb +2 -2
  22. data/spec/support/shared_examples/ridley_resource.rb +39 -39
  23. data/spec/unit/ridley/chef/cookbook/metadata_spec.rb +8 -8
  24. data/spec/unit/ridley/chef/cookbook/syntax_check_spec.rb +15 -15
  25. data/spec/unit/ridley/chef/cookbook_spec.rb +124 -118
  26. data/spec/unit/ridley/chef/digester_spec.rb +2 -2
  27. data/spec/unit/ridley/chef_object_spec.rb +35 -35
  28. data/spec/unit/ridley/chef_objects/client_object_spec.rb +2 -2
  29. data/spec/unit/ridley/chef_objects/cookbook_object_spec.rb +12 -12
  30. data/spec/unit/ridley/chef_objects/data_bag_item_object_spec.rb +7 -7
  31. data/spec/unit/ridley/chef_objects/data_bag_object_spec.rb +4 -1
  32. data/spec/unit/ridley/chef_objects/environment_object_spec.rb +10 -10
  33. data/spec/unit/ridley/chef_objects/node_object_spec.rb +28 -28
  34. data/spec/unit/ridley/chef_objects/role_object_spec.rb +10 -10
  35. data/spec/unit/ridley/chef_objects/sandbox_object_spec.rb +6 -6
  36. data/spec/unit/ridley/client_spec.rb +59 -21
  37. data/spec/unit/ridley/connection_spec.rb +7 -7
  38. data/spec/unit/ridley/errors_spec.rb +3 -3
  39. data/spec/unit/ridley/middleware/chef_auth_spec.rb +2 -2
  40. data/spec/unit/ridley/middleware/chef_response_spec.rb +29 -29
  41. data/spec/unit/ridley/middleware/parse_json_spec.rb +14 -14
  42. data/spec/unit/ridley/mixins/from_file_spec.rb +3 -3
  43. data/spec/unit/ridley/resource_spec.rb +5 -5
  44. data/spec/unit/ridley/resources/cookbook_resource_spec.rb +10 -10
  45. data/spec/unit/ridley/resources/data_bag_item_resource_spec.rb +1 -1
  46. data/spec/unit/ridley/resources/data_bag_resource_spec.rb +6 -3
  47. data/spec/unit/ridley/resources/environment_resource_spec.rb +4 -4
  48. data/spec/unit/ridley/resources/role_resource_spec.rb +1 -1
  49. data/spec/unit/ridley/resources/sandbox_resource_spec.rb +7 -7
  50. data/spec/unit/ridley/resources/search_resource_spec.rb +22 -22
  51. data/spec/unit/ridley/sandbox_uploader_spec.rb +3 -3
  52. data/spec/unit/ridley_spec.rb +6 -6
  53. metadata +15 -18
  54. data/lib/ridley/middleware/gzip.rb +0 -18
  55. data/spec/unit/ridley/middleware/gzip_spec.rb +0 -59
@@ -9,42 +9,42 @@ describe Ridley::Middleware::ParseJson do
9
9
  describe "::response_type" do
10
10
  it "returns the first element of the response content-type" do
11
11
  env = double('env')
12
- env.stub(:[]).with(:response_headers).and_return(
12
+ allow(env).to receive(:[]).with(:response_headers).and_return(
13
13
  'content-type' => 'text/html; charset=utf-8'
14
14
  )
15
15
 
16
- subject.response_type(env).should eql("text/html")
16
+ expect(subject.response_type(env)).to eql("text/html")
17
17
  end
18
18
  end
19
19
 
20
20
  describe "::json_response?" do
21
21
  it "returns true if the value of content-type includes 'application/json' and the body looks like JSON" do
22
22
  env = double('env')
23
- env.stub(:[]).with(:response_headers).and_return(
23
+ allow(env).to receive(:[]).with(:response_headers).and_return(
24
24
  'content-type' => 'application/json; charset=utf8'
25
25
  )
26
- subject.should_receive(:looks_like_json?).with(env).and_return(true)
26
+ expect(subject).to receive(:looks_like_json?).with(env).and_return(true)
27
27
 
28
- subject.json_response?(env).should be_true
28
+ expect(subject.json_response?(env)).to be_truthy
29
29
  end
30
30
 
31
31
  it "returns false if the value of content-type includes 'application/json' but the body does not look like JSON" do
32
32
  env = double('env')
33
- env.stub(:[]).with(:response_headers).and_return(
33
+ allow(env).to receive(:[]).with(:response_headers).and_return(
34
34
  'content-type' => 'application/json; charset=utf8'
35
35
  )
36
- subject.should_receive(:looks_like_json?).with(env).and_return(false)
36
+ expect(subject).to receive(:looks_like_json?).with(env).and_return(false)
37
37
 
38
- subject.json_response?(env).should be_false
38
+ expect(subject.json_response?(env)).to be_falsey
39
39
  end
40
40
 
41
41
  it "returns false if the value of content-type does not include 'application/json'" do
42
42
  env = double('env')
43
- env.stub(:[]).with(:response_headers).and_return(
43
+ allow(env).to receive(:[]).with(:response_headers).and_return(
44
44
  'content-type' => 'text/plain'
45
45
  )
46
46
 
47
- subject.json_response?(env).should be_false
47
+ expect(subject.json_response?(env)).to be_falsey
48
48
  end
49
49
  end
50
50
 
@@ -52,15 +52,15 @@ describe Ridley::Middleware::ParseJson do
52
52
  let(:env) { double('env') }
53
53
 
54
54
  it "returns true if the given string contains JSON brackets" do
55
- env.stub(:[]).with(:body).and_return("{\"name\":\"jamie\"}")
55
+ allow(env).to receive(:[]).with(:body).and_return("{\"name\":\"jamie\"}")
56
56
 
57
- subject.looks_like_json?(env).should be_true
57
+ expect(subject.looks_like_json?(env)).to be_truthy
58
58
  end
59
59
 
60
60
  it "returns false if the given string does not contain JSON brackets" do
61
- env.stub(:[]).with(:body).and_return("name")
61
+ allow(env).to receive(:[]).with(:body).and_return("name")
62
62
 
63
- subject.looks_like_json?(env).should be_false
63
+ expect(subject.looks_like_json?(env)).to be_falsey
64
64
  end
65
65
  end
66
66
  end
@@ -7,9 +7,9 @@ module Ridley
7
7
  let(:instance) { Class.new { include Ridley::Mixin::FromFile }.new }
8
8
 
9
9
  before do
10
- File.stub(:exists?).and_return(true)
11
- File.stub(:readable?).and_return(true)
12
- IO.stub(:read).and_return('invalid Ruby code')
10
+ allow(File).to receive(:exists?).and_return(true)
11
+ allow(File).to receive(:readable?).and_return(true)
12
+ allow(IO).to receive(:read).and_return('invalid Ruby code')
13
13
  end
14
14
 
15
15
  it 'raises a FromFileParserError' do
@@ -22,7 +22,7 @@ describe Ridley::Resource do
22
22
  it "sets the resource_path attr on the class" do
23
23
  subject.set_resource_path("environments")
24
24
 
25
- subject.resource_path.should eql("environments")
25
+ expect(subject.resource_path).to eql("environments")
26
26
  end
27
27
  end
28
28
 
@@ -31,7 +31,7 @@ describe Ridley::Resource do
31
31
  before { subject.set_resource_path(nil) }
32
32
 
33
33
  it "returns the representation's chef type" do
34
- subject.resource_path.should eql(representation.chef_type)
34
+ expect(subject.resource_path).to eql(representation.chef_type)
35
35
  end
36
36
  end
37
37
 
@@ -40,7 +40,7 @@ describe Ridley::Resource do
40
40
  before { subject.set_resource_path(set_path) }
41
41
 
42
42
  it "returns the set value" do
43
- subject.resource_path.should eql(set_path)
43
+ expect(subject.resource_path).to eql(set_path)
44
44
  end
45
45
  end
46
46
  end
@@ -97,7 +97,7 @@ describe Ridley::Resource do
97
97
  end
98
98
 
99
99
  it "returns nil" do
100
- subject.find(id).should be_nil
100
+ expect(subject.find(id)).to be_nil
101
101
  end
102
102
  end
103
103
  end
@@ -135,7 +135,7 @@ describe Ridley::Resource do
135
135
 
136
136
  describe "::delete_all" do
137
137
  it "sends a delete request for every object in the collection" do
138
- pending
138
+ skip
139
139
  end
140
140
  end
141
141
 
@@ -42,7 +42,7 @@ describe Ridley::CookbookResource do
42
42
  end
43
43
 
44
44
  it "returns the latest version" do
45
- subject.latest_version(name).should eql("3.0.0")
45
+ expect(subject.latest_version(name)).to eql("3.0.0")
46
46
  end
47
47
  end
48
48
  end
@@ -58,16 +58,16 @@ describe Ridley::CookbookResource do
58
58
  end
59
59
 
60
60
  it "returns an array" do
61
- subject.versions(name).should be_a(Array)
61
+ expect(subject.versions(name)).to be_a(Array)
62
62
  end
63
63
 
64
64
  it "contains a version string for each cookbook version available" do
65
65
  result = subject.versions(name)
66
66
 
67
- result.should have(3).versions
68
- result.should include("1.0.0")
69
- result.should include("1.1.0")
70
- result.should include("1.2.0")
67
+ expect(result.size).to eq(3)
68
+ expect(result).to include("1.0.0")
69
+ expect(result).to include("1.1.0")
70
+ expect(result).to include("1.2.0")
71
71
  end
72
72
  end
73
73
 
@@ -90,11 +90,11 @@ describe Ridley::CookbookResource do
90
90
  end
91
91
 
92
92
  it "returns a CookbookObject" do
93
- subject.satisfy(name, ">= 2.0.0").should be_a(Ridley::CookbookObject)
93
+ expect(subject.satisfy(name, ">= 2.0.0")).to be_a(Ridley::CookbookObject)
94
94
  end
95
95
 
96
96
  it "is the best solution" do
97
- subject.satisfy(name, ">= 2.0.0").version.should eql("3.0.0")
97
+ expect(subject.satisfy(name, ">= 2.0.0").version).to eql("3.0.0")
98
98
  end
99
99
  end
100
100
 
@@ -102,7 +102,7 @@ describe Ridley::CookbookResource do
102
102
  before { chef_cookbook(name, "1.0.0") }
103
103
 
104
104
  it "returns nil" do
105
- subject.satisfy(name, ">= 2.0.0").should be_nil
105
+ expect(subject.satisfy(name, ">= 2.0.0")).to be_nil
106
106
  end
107
107
  end
108
108
 
@@ -148,6 +148,6 @@ describe Ridley::CookbookResource do
148
148
  end
149
149
 
150
150
  describe "#update" do
151
- pending
151
+ skip
152
152
  end
153
153
  end
@@ -3,5 +3,5 @@ require 'spec_helper'
3
3
  describe Ridley::DataBagItemResource do
4
4
  subject { described_class.new(double) }
5
5
 
6
- pending
6
+ skip
7
7
  end
@@ -8,13 +8,16 @@ describe Ridley::DataBagResource do
8
8
  subject { instance.item_resource }
9
9
 
10
10
  it "returns a DataBagItemResource" do
11
- subject.should be_a(Ridley::DataBagItemResource)
11
+ expect(subject).to be_a(Ridley::DataBagItemResource)
12
12
  end
13
13
 
14
- its(:encrypted_data_bag_secret) { should eql(secret) }
14
+ describe '#encrypted_data_bag_secret' do
15
+ subject { super().encrypted_data_bag_secret }
16
+ it { is_expected.to eql(secret) }
17
+ end
15
18
  end
16
19
 
17
20
  describe "#find" do
18
- pending
21
+ skip
19
22
  end
20
23
  end
@@ -28,13 +28,13 @@ describe Ridley::EnvironmentResource do
28
28
  end
29
29
 
30
30
  it "returns a Hash" do
31
- should be_a(Hash)
31
+ is_expected.to be_a(Hash)
32
32
  end
33
33
 
34
34
  it "contains a key for each cookbook" do
35
- subject.keys.should have(2).items
36
- subject.should have_key("hello")
37
- subject.should have_key("there")
35
+ expect(subject.keys.size).to eq(2)
36
+ expect(subject).to have_key("hello")
37
+ expect(subject).to have_key("there")
38
38
  end
39
39
  end
40
40
 
@@ -3,5 +3,5 @@ require 'spec_helper'
3
3
  describe Ridley::RoleResource do
4
4
  subject { described_class.new(double) }
5
5
 
6
- pending
6
+ skip
7
7
  end
@@ -22,24 +22,24 @@ describe Ridley::SandboxResource do
22
22
  end
23
23
 
24
24
  it "returns a Ridley::SandboxObject" do
25
- subject.create.should be_a(Ridley::SandboxObject)
25
+ expect(subject.create).to be_a(Ridley::SandboxObject)
26
26
  end
27
27
 
28
28
  it "has a value of 'false' for :is_completed" do
29
- subject.create.is_completed.should be_false
29
+ expect(subject.create.is_completed).to be_falsey
30
30
  end
31
31
 
32
32
  it "has an empty Hash of checksums" do
33
- subject.create.checksums.should be_a(Hash)
34
- subject.create.checksums.should be_empty
33
+ expect(subject.create.checksums).to be_a(Hash)
34
+ expect(subject.create.checksums).to be_empty
35
35
  end
36
36
 
37
37
  it "has a value for :uri" do
38
- subject.create.uri.should eql(sandbox_uri)
38
+ expect(subject.create.uri).to eql(sandbox_uri)
39
39
  end
40
40
 
41
41
  it "has a value for :sandbox_id" do
42
- subject.create.sandbox_id.should eql(sandbox_id)
42
+ expect(subject.create.sandbox_id).to eql(sandbox_id)
43
43
  end
44
44
 
45
45
  context "when given an array of checksums" do
@@ -54,7 +54,7 @@ describe Ridley::SandboxResource do
54
54
  let(:checksum_array) { checksums.keys }
55
55
 
56
56
  it "has a Hash of checksums with each of the given checksum ids" do
57
- subject.create(checksum_array).checksums.should have(checksum_array.length).checksums
57
+ expect(subject.create(checksum_array).checksums.size).to eq(checksum_array.length)
58
58
  end
59
59
  end
60
60
  end
@@ -11,8 +11,8 @@ describe Ridley::SearchResource do
11
11
  it "contains a 'q' key/value" do
12
12
  result = subject.build_query(query_string, options)
13
13
 
14
- result.should have_key(:q)
15
- result[:q].should eql(query_string)
14
+ expect(result).to have_key(:q)
15
+ expect(result[:q]).to eql(query_string)
16
16
  end
17
17
 
18
18
  context "when :sort option is set" do
@@ -21,8 +21,8 @@ describe Ridley::SearchResource do
21
21
  it "contains a 'sort' key/value" do
22
22
  result = subject.build_query(query_string, options)
23
23
 
24
- result.should have_key(:sort)
25
- result[:sort].should eql("DESC")
24
+ expect(result).to have_key(:sort)
25
+ expect(result[:sort]).to eql("DESC")
26
26
  end
27
27
  end
28
28
 
@@ -32,8 +32,8 @@ describe Ridley::SearchResource do
32
32
  it "contains a 'start' key/value" do
33
33
  result = subject.build_query(query_string, options)
34
34
 
35
- result.should have_key(:start)
36
- result[:start].should eql(1)
35
+ expect(result).to have_key(:start)
36
+ expect(result[:start]).to eql(1)
37
37
  end
38
38
  end
39
39
 
@@ -43,8 +43,8 @@ describe Ridley::SearchResource do
43
43
  it "contains a 'rows' key/value" do
44
44
  result = subject.build_query(query_string, options)
45
45
 
46
- result.should have_key(:rows)
47
- result[:rows].should eql(1)
46
+ expect(result).to have_key(:rows)
47
+ expect(result[:rows]).to eql(1)
48
48
  end
49
49
  end
50
50
  end
@@ -89,7 +89,7 @@ describe Ridley::SearchResource do
89
89
 
90
90
  describe "::query_uri" do
91
91
  it "returns a URI path containing the search resource path and index" do
92
- subject.query_uri(:nodes).should eql("search/nodes")
92
+ expect(subject.query_uri(:nodes)).to eql("search/nodes")
93
93
  end
94
94
  end
95
95
  end
@@ -118,7 +118,7 @@ describe Ridley::SearchResource do
118
118
  end
119
119
 
120
120
  it "contains a key for each index" do
121
- subject.indexes.should have(4).items
121
+ expect(subject.indexes.size).to eq(4)
122
122
  end
123
123
  end
124
124
 
@@ -179,8 +179,8 @@ describe Ridley::SearchResource do
179
179
  it "returns an array of Ridley::NodeObject" do
180
180
  result = run
181
181
 
182
- result.should be_a(Array)
183
- result.should each be_a(Ridley::NodeObject)
182
+ expect(result).to be_a(Array)
183
+ expect(result).to each be_a(Ridley::NodeObject)
184
184
  end
185
185
 
186
186
  context "after the search has executed and results are returned" do
@@ -188,7 +188,7 @@ describe Ridley::SearchResource do
188
188
 
189
189
  it "Ridley::NodeObject instances contain the results" do
190
190
  first_result = search_results.first
191
- first_result.name.should eq("ridley-one")
191
+ expect(first_result.name).to eq("ridley-one")
192
192
  end
193
193
  end
194
194
  end
@@ -217,8 +217,8 @@ describe Ridley::SearchResource do
217
217
  it "returns an array of Ridley::RoleObject" do
218
218
  result = run
219
219
 
220
- result.should be_a(Array)
221
- result.should each be_a(Ridley::RoleObject)
220
+ expect(result).to be_a(Array)
221
+ expect(result).to each be_a(Ridley::RoleObject)
222
222
  end
223
223
 
224
224
  context "after the search has executed and results are returned" do
@@ -226,7 +226,7 @@ describe Ridley::SearchResource do
226
226
 
227
227
  it "Ridley::RoleObject instances contain the results" do
228
228
  first_result = search_results.first
229
- first_result.name.should eq("ridley-role-one")
229
+ expect(first_result.name).to eq("ridley-role-one")
230
230
  end
231
231
  end
232
232
  end
@@ -254,8 +254,8 @@ describe Ridley::SearchResource do
254
254
  it "returns an array of Ridley::EnvironmentObject" do
255
255
  result = run
256
256
 
257
- result.should be_a(Array)
258
- result.should each be_a(Ridley::EnvironmentObject)
257
+ expect(result).to be_a(Array)
258
+ expect(result).to each be_a(Ridley::EnvironmentObject)
259
259
  end
260
260
 
261
261
  context "after the search has executed and results are returned" do
@@ -263,7 +263,7 @@ describe Ridley::SearchResource do
263
263
 
264
264
  it "Ridley::EnvironmentObject instances contain the results" do
265
265
  first_result = search_results.first
266
- first_result.name.should eq("ridley-env-test")
266
+ expect(first_result.name).to eq("ridley-env-test")
267
267
  end
268
268
  end
269
269
  end
@@ -292,8 +292,8 @@ describe Ridley::SearchResource do
292
292
  it "returns an array of Ridley::ClientObject" do
293
293
  result = run
294
294
 
295
- result.should be_a(Array)
296
- result.should each be_a(Ridley::ClientObject)
295
+ expect(result).to be_a(Array)
296
+ expect(result).to each be_a(Ridley::ClientObject)
297
297
  end
298
298
 
299
299
  context "after the search has executed and results are returned" do
@@ -301,7 +301,7 @@ describe Ridley::SearchResource do
301
301
 
302
302
  it "Ridley::ClientObject instances contain the results" do
303
303
  first_result = search_results.first
304
- first_result.name.should eq("ridley-client-test")
304
+ expect(first_result.name).to eq("ridley-client-test")
305
305
  end
306
306
  end
307
307
  end
@@ -8,14 +8,14 @@ describe Ridley::SandboxUploader do
8
8
  let(:io) { StringIO.new("some long string") }
9
9
  subject { described_class.checksum(io) }
10
10
 
11
- it { should eq("2fb66bbfb88cdf9e07a3f1d1dfad71ab") }
11
+ it { is_expected.to eq("2fb66bbfb88cdf9e07a3f1d1dfad71ab") }
12
12
  end
13
13
 
14
14
  describe "::checksum64" do
15
15
  let(:io) { StringIO.new("some long string") }
16
16
  subject { described_class.checksum64(io) }
17
17
 
18
- it { should eq("L7Zrv7iM354Ho/HR361xqw==") }
18
+ it { is_expected.to eq("L7Zrv7iM354Ho/HR361xqw==") }
19
19
  end
20
20
  end
21
21
 
@@ -80,7 +80,7 @@ describe Ridley::SandboxUploader do
80
80
  end
81
81
 
82
82
  it "returns nil" do
83
- subject.upload(sandbox, chk_id, path).should be_nil
83
+ expect(subject.upload(sandbox, chk_id, path)).to be_nil
84
84
  end
85
85
  end
86
86
 
@@ -9,9 +9,9 @@ describe Ridley do
9
9
  describe "::new" do
10
10
  it "creates a new Ridley::Connection" do
11
11
  client = double('client')
12
- Ridley::Client.should_receive(:new).with(config).and_return(client)
12
+ expect(Ridley::Client).to receive(:new).with(config).and_return(client)
13
13
 
14
- subject.new(config).should eql(client)
14
+ expect(subject.new(config)).to eql(client)
15
15
  end
16
16
  end
17
17
 
@@ -32,12 +32,12 @@ describe Ridley do
32
32
  let(:path) { tmp_path.join('config.rb').to_s }
33
33
 
34
34
  before do
35
- Ridley::Client.stub(:new).and_return(client)
35
+ allow(Ridley::Client).to receive(:new).and_return(client)
36
36
  File.open(path, 'w') { |f| f.write(chef_config) }
37
37
  end
38
38
 
39
39
  it "creates a Ridley connection from the Chef config" do
40
- Ridley::Client.should_receive(:new).with({
40
+ expect(Ridley::Client).to receive(:new).with({
41
41
  client_key: 'username.pem',
42
42
  client_name: 'username',
43
43
  validator_client: 'validator',
@@ -58,7 +58,7 @@ describe Ridley do
58
58
  end
59
59
 
60
60
  it "allows the user to override attributes" do
61
- Ridley::Client.should_receive(:new).with({
61
+ expect(Ridley::Client).to receive(:new).with({
62
62
  client_key: 'bacon.pem',
63
63
  client_name: 'bacon',
64
64
  validator_client: 'validator',
@@ -88,7 +88,7 @@ describe Ridley do
88
88
  end
89
89
 
90
90
  it "does a knife.rb search" do
91
- Ridley::Client.should_receive(:new).with({
91
+ expect(Ridley::Client).to receive(:new).with({
92
92
  client_key: 'username.pem',
93
93
  client_name: 'username',
94
94
  validator_client: 'validator',