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
@@ -7,10 +7,10 @@ describe Ridley::RoleObject do
7
7
  it "sets an override node attribute at the nested path" do
8
8
  subject.set_override_attribute('deep.nested.item', true)
9
9
 
10
- subject.override_attributes.should have_key("deep")
11
- subject.override_attributes["deep"].should have_key("nested")
12
- subject.override_attributes["deep"]["nested"].should have_key("item")
13
- subject.override_attributes["deep"]["nested"]["item"].should be_true
10
+ expect(subject.override_attributes).to have_key("deep")
11
+ expect(subject.override_attributes["deep"]).to have_key("nested")
12
+ expect(subject.override_attributes["deep"]["nested"]).to have_key("item")
13
+ expect(subject.override_attributes["deep"]["nested"]["item"]).to be_truthy
14
14
  end
15
15
 
16
16
  context "when the override attribute is already set" do
@@ -24,7 +24,7 @@ describe Ridley::RoleObject do
24
24
  }
25
25
  subject.set_override_attribute('deep.nested.item', true)
26
26
 
27
- subject.override_attributes["deep"]["nested"]["item"].should be_true
27
+ expect(subject.override_attributes["deep"]["nested"]["item"]).to be_truthy
28
28
  end
29
29
  end
30
30
  end
@@ -33,10 +33,10 @@ describe Ridley::RoleObject do
33
33
  it "sets an override node attribute at the nested path" do
34
34
  subject.set_default_attribute('deep.nested.item', true)
35
35
 
36
- subject.default_attributes.should have_key("deep")
37
- subject.default_attributes["deep"].should have_key("nested")
38
- subject.default_attributes["deep"]["nested"].should have_key("item")
39
- subject.default_attributes["deep"]["nested"]["item"].should be_true
36
+ expect(subject.default_attributes).to have_key("deep")
37
+ expect(subject.default_attributes["deep"]).to have_key("nested")
38
+ expect(subject.default_attributes["deep"]["nested"]).to have_key("item")
39
+ expect(subject.default_attributes["deep"]["nested"]["item"]).to be_truthy
40
40
  end
41
41
 
42
42
  context "when the override attribute is already set" do
@@ -50,7 +50,7 @@ describe Ridley::RoleObject do
50
50
  }
51
51
  subject.set_default_attribute('deep.nested.item', true)
52
52
 
53
- subject.default_attributes["deep"]["nested"]["item"].should be_true
53
+ expect(subject.default_attributes["deep"]["nested"]["item"]).to be_truthy
54
54
  end
55
55
  end
56
56
  end
@@ -24,15 +24,15 @@ describe Ridley::SandboxObject do
24
24
  )
25
25
  end
26
26
 
27
- before { subject.stub(resource: resource) }
27
+ before { allow(subject).to receive_messages(resource: resource) }
28
28
 
29
29
  describe "#checksums" do
30
- pending
30
+ skip
31
31
  end
32
32
 
33
33
  describe "#commit" do
34
34
  let(:response) { { is_completed: nil} }
35
- before { resource.should_receive(:commit).with(subject).and_return(response) }
35
+ before { expect(resource).to receive(:commit).with(subject).and_return(response) }
36
36
 
37
37
  context "when the commit is successful" do
38
38
  before { response[:is_completed] = true }
@@ -40,7 +40,7 @@ describe Ridley::SandboxObject do
40
40
  it "has an 'is_completed' value of true" do
41
41
  subject.commit
42
42
 
43
- subject.is_completed.should be_true
43
+ expect(subject.is_completed).to be_truthy
44
44
  end
45
45
  end
46
46
 
@@ -50,7 +50,7 @@ describe Ridley::SandboxObject do
50
50
  it "has an 'is_completed' value of false" do
51
51
  subject.commit
52
52
 
53
- subject.is_completed.should be_false
53
+ expect(subject.is_completed).to be_falsey
54
54
  end
55
55
  end
56
56
  end
@@ -58,7 +58,7 @@ describe Ridley::SandboxObject do
58
58
  describe "#upload" do
59
59
  it "delegates to resource#upload" do
60
60
  checksums = double('checksums')
61
- resource.should_receive(:upload).with(subject, checksums)
61
+ expect(resource).to receive(:upload).with(subject, checksums)
62
62
 
63
63
  subject.upload(checksums)
64
64
  end
@@ -32,9 +32,20 @@ describe Ridley::Client do
32
32
  subject { described_class.new(options) }
33
33
 
34
34
  describe "parsing the 'server_url' option" do
35
- its(:host) { should eql("api.opscode.com") }
36
- its(:scheme) { should eql("https") }
37
- its(:path_prefix) { should eql("/") }
35
+ describe '#host' do
36
+ subject { super().host }
37
+ it { is_expected.to eql("api.opscode.com") }
38
+ end
39
+
40
+ describe '#scheme' do
41
+ subject { super().scheme }
42
+ it { is_expected.to eql("https") }
43
+ end
44
+
45
+ describe '#path_prefix' do
46
+ subject { super().path_prefix }
47
+ it { is_expected.to eql("/") }
48
+ end
38
49
  end
39
50
 
40
51
  describe "with a server_url containing an organization" do
@@ -43,16 +54,16 @@ describe Ridley::Client do
43
54
  end
44
55
 
45
56
  it "gets the host data from the server_url" do
46
- subject.host.should eql("api.opscode.com")
47
- subject.scheme.should eql("https")
57
+ expect(subject.host).to eql("api.opscode.com")
58
+ expect(subject.scheme).to eql("https")
48
59
  end
49
60
 
50
61
  it "takes the organization out of the server_url and assigns it to the organization reader" do
51
- subject.organization.should eql(organization)
62
+ expect(subject.organization).to eql(organization)
52
63
  end
53
64
 
54
65
  it "sets the 'path_prefix' of the connection the organization sub URI" do
55
- subject.path_prefix.should eql("/organizations/#{organization}")
66
+ expect(subject.path_prefix).to eql("/organizations/#{organization}")
56
67
  end
57
68
  end
58
69
 
@@ -94,26 +105,26 @@ describe Ridley::Client do
94
105
  it "expands the path of the client_key" do
95
106
  config[:client_key] = "spec/fixtures/reset.pem"
96
107
 
97
- described_class.new(config).client_key[0..4].should_not == "spec/"
108
+ expect(described_class.new(config).client_key[0..4]).not_to eq("spec/")
98
109
  end
99
110
 
100
111
  it "accepts a client key as a string" do
101
112
  key = File.read(fixtures_path.join("reset.pem").to_s)
102
113
  config[:client_key] = key.dup
103
- described_class.new(config).client_key.should == key
114
+ expect(described_class.new(config).client_key).to eq(key)
104
115
  end
105
116
 
106
117
  it "assigns a 'chef_version' attribute from the given 'chef_version' option" do
107
- described_class.new(config).chef_version.should eql("10.24.0-01")
118
+ expect(described_class.new(config).chef_version).to eql("10.24.0-01")
108
119
  end
109
120
  end
110
121
 
111
122
  describe "::open" do
112
123
  it "instantiates a new connection, yields to it, and terminates it" do
113
124
  new_instance = double(alive?: true)
114
- described_class.should_receive(:new).and_return(new_instance)
115
- new_instance.should_receive(:hello)
116
- new_instance.should_receive(:terminate)
125
+ expect(described_class).to receive(:new).and_return(new_instance)
126
+ expect(new_instance).to receive(:hello)
127
+ expect(new_instance).to receive(:terminate)
117
128
 
118
129
  described_class.open do |f|
119
130
  f.hello
@@ -126,18 +137,45 @@ describe Ridley::Client do
126
137
 
127
138
  subject { instance }
128
139
 
129
- its(:client) { should be_a(Ridley::ClientResource) }
130
- its(:cookbook) { should be_a(Ridley::CookbookResource) }
131
- its(:data_bag) { should be_a(Ridley::DataBagResource) }
132
- its(:environment) { should be_a(Ridley::EnvironmentResource) }
133
- its(:node) { should be_a(Ridley::NodeResource) }
134
- its(:role) { should be_a(Ridley::RoleResource) }
135
- its(:sandbox) { should be_a(Ridley::SandboxResource) }
140
+ describe '#client' do
141
+ subject { super().client }
142
+ it { is_expected.to be_a(Ridley::ClientResource) }
143
+ end
144
+
145
+ describe '#cookbook' do
146
+ subject { super().cookbook }
147
+ it { is_expected.to be_a(Ridley::CookbookResource) }
148
+ end
149
+
150
+ describe '#data_bag' do
151
+ subject { super().data_bag }
152
+ it { is_expected.to be_a(Ridley::DataBagResource) }
153
+ end
154
+
155
+ describe '#environment' do
156
+ subject { super().environment }
157
+ it { is_expected.to be_a(Ridley::EnvironmentResource) }
158
+ end
159
+
160
+ describe '#node' do
161
+ subject { super().node }
162
+ it { is_expected.to be_a(Ridley::NodeResource) }
163
+ end
164
+
165
+ describe '#role' do
166
+ subject { super().role }
167
+ it { is_expected.to be_a(Ridley::RoleResource) }
168
+ end
169
+
170
+ describe '#sandbox' do
171
+ subject { super().sandbox }
172
+ it { is_expected.to be_a(Ridley::SandboxResource) }
173
+ end
136
174
 
137
175
  describe "#encrypted_data_bag_secret" do
138
176
  subject { instance.encrypted_data_bag_secret }
139
177
 
140
- it { should be_a(String) }
178
+ it { is_expected.to be_a(String) }
141
179
 
142
180
  context "when a encrypted_data_bag_secret_path is not provided" do
143
181
  before(:each) do
@@ -18,7 +18,7 @@ describe Ridley::Connection do
18
18
  expect {
19
19
  subject.get('organizations/vialstudios')
20
20
  }.to raise_error
21
- a_request(:get, "https://api.opscode.com/organizations/vialstudios").should have_been_made.times(6)
21
+ expect(a_request(:get, "https://api.opscode.com/organizations/vialstudios")).to have_been_made.times(6)
22
22
  end
23
23
 
24
24
  context "given a configured count of two (2) retries" do
@@ -31,7 +31,7 @@ describe Ridley::Connection do
31
31
  subject.get('organizations/vialstudios')
32
32
  }.to raise_error
33
33
 
34
- a_request(:get, "https://api.opscode.com/organizations/vialstudios").should have_been_made.times(3)
34
+ expect(a_request(:get, "https://api.opscode.com/organizations/vialstudios")).to have_been_made.times(3)
35
35
  end
36
36
  end
37
37
  end
@@ -40,13 +40,13 @@ describe Ridley::Connection do
40
40
  it "returns :foss if the organization is not set" do
41
41
  subject.stub(:organization).and_return(nil)
42
42
 
43
- subject.api_type.should eql(:foss)
43
+ expect(subject.api_type).to eql(:foss)
44
44
  end
45
45
 
46
46
  it "returns :hosted if the organization is set" do
47
47
  subject.stub(:organization).and_return("vialstudios")
48
48
 
49
- subject.api_type.should eql(:hosted)
49
+ expect(subject.api_type).to eql(:hosted)
50
50
  end
51
51
  end
52
52
 
@@ -62,17 +62,17 @@ describe Ridley::Connection do
62
62
  it "creates a destination file on disk" do
63
63
  subject.stream(target, destination)
64
64
 
65
- File.exist?(destination).should be_true
65
+ expect(File.exist?(destination)).to be_truthy
66
66
  end
67
67
 
68
68
  it "returns true when the file was copied" do
69
- expect(subject.stream(target, destination)).to be_true
69
+ expect(subject.stream(target, destination)).to be_truthy
70
70
  end
71
71
 
72
72
  it "contains the contents of the response body" do
73
73
  subject.stream(target, destination)
74
74
 
75
- File.read(destination).should include(contents)
75
+ expect(File.read(destination)).to include(contents)
76
76
  end
77
77
  end
78
78
  end
@@ -18,7 +18,7 @@ describe Ridley::Errors do
18
18
  it "adds an item to the error map" do
19
19
  subject.register_error(400)
20
20
 
21
- subject.error_map.should have(1).item
21
+ expect(subject.error_map.size).to eq(1)
22
22
  end
23
23
 
24
24
  it "adds a key of the given status code with a value of the class inheriting from HTTPError" do
@@ -26,7 +26,7 @@ describe Ridley::Errors do
26
26
  register_error(400)
27
27
  end
28
28
 
29
- subject.error_map[400].should eql(RidleyTestHTTPError)
29
+ expect(subject.error_map[400]).to eql(RidleyTestHTTPError)
30
30
  end
31
31
  end
32
32
  end
@@ -35,7 +35,7 @@ describe Ridley::Errors do
35
35
  subject { Ridley::Errors::HTTPError.new(:body => "<html><body><h1>Redirected</h1></body></html>") }
36
36
 
37
37
  it "has an HTML body" do
38
- subject.message.should eq("<html><body><h1>Redirected</h1></body></html>")
38
+ expect(subject.message).to eq("<html><body><h1>Redirected</h1></body></html>")
39
39
  end
40
40
  end
41
41
  end
@@ -16,7 +16,7 @@ describe Ridley::Middleware::ChefAuth do
16
16
  host: "https://api.opscode.com",
17
17
  path: "/something.file"
18
18
  }
19
- subject.authentication_headers(client_name, client_key, options).should be_a(Hash)
19
+ expect(subject.authentication_headers(client_name, client_key, options)).to be_a(Hash)
20
20
  end
21
21
 
22
22
  context "when the :client_key is an actual key" do
@@ -28,7 +28,7 @@ describe Ridley::Middleware::ChefAuth do
28
28
  host: "https://api.opscode.com",
29
29
  path: "/something.file"
30
30
  }
31
- subject.authentication_headers(client_name, client_key, options).should be_a(Hash)
31
+ expect(subject.authentication_headers(client_name, client_key, options)).to be_a(Hash)
32
32
  end
33
33
  end
34
34
  end
@@ -11,33 +11,33 @@ describe Ridley::Middleware::ChefResponse do
11
11
 
12
12
  it "returns true if response status between 200 and 210" do
13
13
  (200..210).each do |code|
14
- env.should_receive(:[]).with(:status).and_return(code)
14
+ expect(env).to receive(:[]).with(:status).and_return(code)
15
15
 
16
- subject.success?(env).should be_true
16
+ expect(subject.success?(env)).to be_truthy
17
17
  end
18
18
  end
19
19
 
20
20
  it "returns false if response status is in the 300 range" do
21
21
  (300..399).each do |code|
22
- env.should_receive(:[]).with(:status).and_return(code)
22
+ expect(env).to receive(:[]).with(:status).and_return(code)
23
23
 
24
- subject.success?(env).should be_false
24
+ expect(subject.success?(env)).to be_falsey
25
25
  end
26
26
  end
27
27
 
28
28
  it "returns false if response status is in the 400 range" do
29
29
  (400..499).each do |code|
30
- env.should_receive(:[]).with(:status).and_return(code)
30
+ expect(env).to receive(:[]).with(:status).and_return(code)
31
31
 
32
- subject.success?(env).should be_false
32
+ expect(subject.success?(env)).to be_falsey
33
33
  end
34
34
  end
35
35
 
36
36
  it "returns false if response status is in the 500 range" do
37
37
  (500..599).each do |code|
38
- env.should_receive(:[]).with(:status).and_return(code)
38
+ expect(env).to receive(:[]).with(:status).and_return(code)
39
39
 
40
- subject.success?(env).should be_false
40
+ expect(subject.success?(env)).to be_falsey
41
41
  end
42
42
  end
43
43
  end
@@ -117,15 +117,15 @@ describe Ridley::Middleware::ChefResponse do
117
117
  end
118
118
 
119
119
  it "raises a Ridley::Errors::HTTPBadRequest" do
120
- lambda {
120
+ expect {
121
121
  subject.get('cookbooks')
122
- }.should raise_error(Ridley::Errors::HTTPBadRequest)
122
+ }.to raise_error(Ridley::Errors::HTTPBadRequest)
123
123
  end
124
124
 
125
125
  it "should have the body of the response as the error's message" do
126
- lambda {
126
+ expect {
127
127
  subject.get('cookbooks')
128
- }.should raise_error("errors: '400 - Bad Request: Valid X-CHEF-VERSION header is required.'")
128
+ }.to raise_error("errors: '400 - Bad Request: Valid X-CHEF-VERSION header is required.'")
129
129
  end
130
130
  end
131
131
 
@@ -135,15 +135,15 @@ describe Ridley::Middleware::ChefResponse do
135
135
  end
136
136
 
137
137
  it "raises a Ridley::Errors::HTTPUnauthorized" do
138
- lambda {
138
+ expect {
139
139
  subject.get('cookbooks')
140
- }.should raise_error(Ridley::Errors::HTTPUnauthorized)
140
+ }.to raise_error(Ridley::Errors::HTTPUnauthorized)
141
141
  end
142
142
 
143
143
  it "should have the body of the response as the error's message" do
144
- lambda {
144
+ expect {
145
145
  subject.get('cookbooks')
146
- }.should raise_error("errors: '401 - Unauthorized. You must properly authenticate your API requests!'")
146
+ }.to raise_error("errors: '401 - Unauthorized. You must properly authenticate your API requests!'")
147
147
  end
148
148
  end
149
149
 
@@ -153,15 +153,15 @@ describe Ridley::Middleware::ChefResponse do
153
153
  end
154
154
 
155
155
  it "raises a Ridley::Errors::HTTPForbidden" do
156
- lambda {
156
+ expect {
157
157
  subject.get('cookbooks')
158
- }.should raise_error(Ridley::Errors::HTTPForbidden)
158
+ }.to raise_error(Ridley::Errors::HTTPForbidden)
159
159
  end
160
160
 
161
161
  it "should have the body of the response as the error's message" do
162
- lambda {
162
+ expect {
163
163
  subject.get('cookbooks')
164
- }.should raise_error("errors: '403 - Forbidden.'")
164
+ }.to raise_error("errors: '403 - Forbidden.'")
165
165
  end
166
166
  end
167
167
 
@@ -171,15 +171,15 @@ describe Ridley::Middleware::ChefResponse do
171
171
  end
172
172
 
173
173
  it "raises a Ridley::Errors::HTTPNotFound" do
174
- lambda {
174
+ expect {
175
175
  subject.get('not_existant_route')
176
- }.should raise_error(Ridley::Errors::HTTPNotFound)
176
+ }.to raise_error(Ridley::Errors::HTTPNotFound)
177
177
  end
178
178
 
179
179
  it "should have the body of the response as the error's message" do
180
- lambda {
180
+ expect {
181
181
  subject.get('not_existant_route')
182
- }.should raise_error(Ridley::Errors::HTTPNotFound, "errors: 'No routes match the request: /organizations/vialstudios/cookbookss/not_existant'")
182
+ }.to raise_error(Ridley::Errors::HTTPNotFound, "errors: 'No routes match the request: /organizations/vialstudios/cookbookss/not_existant'")
183
183
  end
184
184
  end
185
185
 
@@ -189,15 +189,15 @@ describe Ridley::Middleware::ChefResponse do
189
189
  end
190
190
 
191
191
  it "raises a Ridley::Errors::HTTPForbidden" do
192
- lambda {
192
+ expect {
193
193
  subject.get('cookbooks')
194
- }.should raise_error(Ridley::Errors::HTTPConflict)
194
+ }.to raise_error(Ridley::Errors::HTTPConflict)
195
195
  end
196
196
 
197
197
  it "should have the body of the response as the error's message" do
198
- lambda {
198
+ expect {
199
199
  subject.get('cookbooks')
200
- }.should raise_error("errors: '409 - Conflict.'")
200
+ }.to raise_error("errors: '409 - Conflict.'")
201
201
  end
202
202
  end
203
203
 
@@ -207,7 +207,7 @@ describe Ridley::Middleware::ChefResponse do
207
207
  end
208
208
 
209
209
  it "returns a body containing a hash" do
210
- subject.get('roles/reset').env[:body].should be_a(Hash)
210
+ expect(subject.get('roles/reset').env[:body]).to be_a(Hash)
211
211
  end
212
212
  end
213
213
  end