spice 0.4.2 → 0.5.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,105 +3,66 @@ require 'spec_helper'
3
3
  module Spice
4
4
  describe Cookbook do
5
5
  describe ".all" do
6
+ before { stub_cookbook_list }
7
+ subject { Cookbook.all }
6
8
 
7
- it "returns a list of cookbooks" do
8
- stub_cookbook_list
9
- Cookbook.all.length.should == 1
10
- end
9
+ it { should have_body(cookbook_list_response) }
10
+ it { should respond_with(200) }
11
11
  end
12
-
12
+
13
13
  describe ".show" do
14
-
15
- context "valid" do
16
- it "returns a valid cookbook" do
17
- stub_cookbook_show("monkeypants")
18
- cookbook = Cookbook.show(:name => "monkeypants")
19
- cookbook["name"].should == "monkeypants"
20
- cookbook["admin"].should == true
21
- end
14
+ context "if the cookbook is found" do
15
+ before { stub_cookbook_show }
16
+ subject { Cookbook.show(:name => "testcookbook") }
17
+
18
+ it { should have_body(cookbook_show_response) }
19
+ it { should respond_with(200) }
22
20
  end
23
21
 
24
- context "errors" do
25
- it "return a 404 when a cookbook is not found" do
26
- stub_cookbook_show("applesauce", 404)
27
- lambda { Cookbook.show(:name => "applesauce") }.
28
- should raise_error(RestCookbook::ResourceNotFound)
29
- end
22
+ context "if the cookbook is not found" do
23
+ before { stub_cookbook_show(404) }
24
+ subject { Cookbook.show(:name => "testcookbook") }
30
25
 
31
- it "raises ArgumentError if option :name not present" do
32
- stub_cookbook_show("pizza")
33
- lambda {Cookbook.show() }.should raise_error ArgumentError
34
- end
26
+ it { should_not have_body(cookbook_show_response) }
27
+ it { should respond_with(404) }
35
28
  end
36
29
  end
37
-
30
+
38
31
  describe ".create" do
39
-
40
- context "valid" do
41
- it "creates a valid non-admin cookbook" do
42
- stub_cookbook_create("spork")
43
- cookbook = Cookbook.create(:name => "spork", :admin => false)
44
- cookbook["private_key"].should == "RSA PRIVATE KEY"
45
- cookbook["uri"].should == "http://http://localhost:4000/cookbooks/spork"
46
- end
32
+ context "if the cookbook can be created" do
33
+ before { stub_cookbook_create }
34
+ subject { Cookbook.create(:name => "testcookbook") }
47
35
 
48
- it "creates a valid admin cookbook" do
49
- stub_cookbook_create("pants", true)
50
- response = Cookbook.create(:name => "pants", :admin => true)
51
- response["private_key"].should == "RSA PRIVATE KEY"
52
- response["uri"].should == "http://http://localhost:4000/cookbooks/pants"
53
-
54
- stub_cookbook_show("pants")
55
- cookbook = Cookbook.show(:name => "pants")
56
- cookbook["admin"].should == true
57
- end
36
+ it { should have_body(cookbook_create_response) }
37
+ it { should respond_with(201) }
58
38
  end
59
39
 
60
- context "errors" do
61
- it "does not create a cookbook that already exists" do
62
- stub_cookbook_create("pants", false, 409)
63
- lambda { Cookbook.create(:name => "pants", :admin => false) }.
64
- should raise_error(RestCookbook::Conflict)
65
- end
66
- end
67
- end
68
-
69
- describe ".update" do
70
-
71
- context "valid" do
72
- it "makes a cookbook an admin" do
73
- stub_cookbook_update("awesome", true, false, 200)
74
- Cookbook.update(:name => "awesome", :admin => true, :private_key => false)
75
- end
40
+ context "if the cookbook already exists" do
41
+ before { stub_cookbook_create(409) }
42
+ subject { Cookbook.create(:name => "testcookbook") }
76
43
 
77
- it "regenerates the cookbook private key" do
78
- stub_cookbook_update("awesome", false, true, 200)
79
- Cookbook.update(:name => "awesome", :admin => false, :private_key => true)
80
- end
81
- end
44
+ it { should have_body(cookbook_conflict) }
45
+ it { should respond_with(409) }
46
+ end
82
47
  end
83
-
48
+
84
49
  describe ".delete" do
85
-
86
- context "valid" do
87
- it "deletes a cookbook" do
88
- stub_cookbook_delete("spork")
89
- Cookbook.delete(:name => "spork")
90
- end
50
+ context "if the cookbook can be deleted" do
51
+ before { stub_cookbook_delete }
52
+ subject { Cookbook.delete(:name => "testcookbook") }
53
+
54
+ it { should have_body(cookbook_delete_response) }
55
+ it { should respond_with(200) }
91
56
  end
92
-
93
- context "errors" do
94
- it "raises ArgumentError if option :name not present" do
95
- stub_cookbook_delete("pizza")
96
- lambda {Cookbook.delete }.should raise_error ArgumentError
97
- end
57
+
58
+ context "if the cookbook cannot be deleted" do
59
+ before { stub_cookbook_delete(404) }
60
+ subject { Cookbook.delete(:name => "testcookbook") }
98
61
 
99
- it "does not delete a non-existent cookbook" do
100
- stub_cookbook_delete("spork", 404)
101
- lambda { Cookbook.delete(:name => "spork") }.
102
- should raise_error(RestCookbook::ResourceNotFound)
103
- end
62
+ it { should have_body(cookbook_not_found) }
63
+ it { should respond_with(404) }
104
64
  end
105
65
  end
66
+
106
67
  end
107
68
  end
@@ -9,12 +9,12 @@ module Spice
9
9
  it { should have_body(data_bag_list_response) }
10
10
  it { should respond_with(200) }
11
11
  end
12
-
12
+
13
13
  describe ".show" do
14
14
  context "if the data bag is found" do
15
15
  before { stub_data_bag_show }
16
16
  subject { DataBag.show(:name => "users") }
17
-
17
+
18
18
  it { should have_body(data_bag_show_response) }
19
19
  it { should respond_with(200) }
20
20
  end
@@ -45,7 +45,7 @@ module Spice
45
45
  it { should respond_with(409) }
46
46
  end
47
47
  end
48
-
48
+
49
49
  describe ".delete" do
50
50
  context "if the data bag can be deleted" do
51
51
  before { stub_data_bag_delete }
@@ -82,87 +82,86 @@ module Spice
82
82
  end
83
83
  end
84
84
 
85
- describe ".create_item" do
86
- context "if the data bag item can be created" do
87
- before { stub_data_bag_item_create }
88
- subject do
89
- Spice::DataBag.create_item(
90
- :name => "users", :id => "adam", :real_name => "Adam Jacob"
91
- )
92
- end
93
-
94
- it { should have_body(data_bag_item_create_response) }
95
- it { should respond_with(201) }
96
- end
97
-
98
- context "if the data bag item cannot be created" do
99
- before { stub_data_bag_item_create(409) }
100
- subject do
101
- Spice::DataBag.create_item(
102
- :name => "users", :id => "adam", :real_name => "Adam Jacob"
103
- )
104
- end
105
-
106
- it { should have_body(data_bag_item_conflict) }
107
- it { should respond_with(409) }
108
- end
109
-
110
- context "if the data bag does not exist" do
111
- before { stub_data_bag_item_create(404) }
112
- subject do
113
- Spice::DataBag.create_item(
114
- :name => "users", :id => "adam", :real_name => "Adam Jacob"
115
- )
116
- end
117
-
118
- it { should have_body(data_bag_not_found) }
119
- it { should respond_with(404) }
120
- end
121
- end
122
-
123
- describe ".update_item" do
124
- context "if the data bag item can be updated" do
125
- before { stub_data_bag_item_update }
126
- subject do
127
- Spice::DataBag.update_item(
128
- :name => "users", :id => "adam", :title => "Supreme Awesomer"
129
- )
130
- end
131
-
132
- it { should have_body(data_bag_item_update_response) }
133
- it { should respond_with(200) }
134
- end
135
-
136
- context "if the data bag item cannot be updated" do
137
- before { stub_data_bag_item_update(404) }
138
- subject do
139
- Spice::DataBag.update_item(
140
- :name => "users", :id => "adam", :title => "Supreme Awesomer"
141
- )
142
- end
143
- it { should have_body(data_bag_item_not_found) }
144
- it { should respond_with(404) }
145
- end
146
- end
147
-
148
- describe ".delete_item" do
149
- context "if the data bag item can be deleted" do
150
- before { stub_data_bag_item_delete }
151
- subject{ Spice::DataBag.delete_item(:name => "users", :id => "adam") }
152
-
153
- it { should have_body(data_bag_item_delete_response) }
154
- it { should respond_with(200) }
155
- end
156
-
157
- context "if the data bag item cannot be deleted" do
158
- before { stub_data_bag_item_delete(404) }
159
- subject{ Spice::DataBag.delete_item(:name => "users", :id => "adam") }
160
-
161
- it { should have_body(data_bag_item_not_found) }
162
- it { should respond_with(404) }
163
-
164
-
165
- end
166
- end
85
+ describe ".create_item" do
86
+ context "if the data bag item can be created" do
87
+ before { stub_data_bag_item_create }
88
+ subject do
89
+ Spice::DataBag.create_item(
90
+ :name => "users", :id => "adam", :real_name => "Adam Jacob"
91
+ )
92
+ end
93
+
94
+ it { should have_body(data_bag_item_create_response) }
95
+ it { should respond_with(201) }
96
+ end
97
+
98
+ context "if the data bag item cannot be created" do
99
+ before { stub_data_bag_item_create(409) }
100
+ subject do
101
+ Spice::DataBag.create_item(
102
+ :name => "users", :id => "adam", :real_name => "Adam Jacob"
103
+ )
104
+ end
105
+
106
+ it { should have_body(data_bag_item_conflict) }
107
+ it { should respond_with(409) }
108
+ end
109
+
110
+ context "if the data bag does not exist" do
111
+ before { stub_data_bag_item_create(404) }
112
+ subject do
113
+ Spice::DataBag.create_item(
114
+ :name => "users", :id => "adam", :real_name => "Adam Jacob"
115
+ )
116
+ end
117
+
118
+ it { should have_body(data_bag_not_found) }
119
+ it { should respond_with(404) }
120
+ end
121
+ end
122
+
123
+ describe ".update_item" do
124
+ context "if the data bag item can be updated" do
125
+ before { stub_data_bag_item_update }
126
+ subject do
127
+ Spice::DataBag.update_item(
128
+ :name => "users", :id => "adam", :title => "Supreme Awesomer"
129
+ )
130
+ end
131
+
132
+ it { should have_body(data_bag_item_update_response) }
133
+ it { should respond_with(200) }
134
+ end
135
+
136
+ context "if the data bag item cannot be updated" do
137
+ before { stub_data_bag_item_update(404) }
138
+ subject do
139
+ Spice::DataBag.update_item(
140
+ :name => "users", :id => "adam", :title => "Supreme Awesomer"
141
+ )
142
+ end
143
+ it { should have_body(data_bag_item_not_found) }
144
+ it { should respond_with(404) }
145
+ end
146
+ end
147
+
148
+ describe ".delete_item" do
149
+ context "if the data bag item can be deleted" do
150
+ before { stub_data_bag_item_delete }
151
+ subject{ Spice::DataBag.delete_item(:name => "users", :id => "adam") }
152
+
153
+ it { should have_body(data_bag_item_delete_response) }
154
+ it { should respond_with(200) }
155
+ end
156
+
157
+ context "if the data bag item cannot be deleted" do
158
+ before { stub_data_bag_item_delete(404) }
159
+ subject{ Spice::DataBag.delete_item(:name => "users", :id => "adam") }
160
+
161
+ it { should have_body(data_bag_item_not_found) }
162
+ it { should respond_with(404) }
163
+ end
164
+ end
165
+
167
166
  end
168
167
  end
@@ -2,5 +2,80 @@ require 'spec_helper'
2
2
 
3
3
  module Spice
4
4
  describe Node do
5
+ describe ".all" do
6
+ before { stub_node_list }
7
+ subject { Node.all }
8
+
9
+ it { should have_body(node_list_response) }
10
+ it { should respond_with(200) }
11
+ end
12
+
13
+ describe ".show" do
14
+ context "if the node is found" do
15
+ before { stub_node_show }
16
+ subject { Node.show(:name => "testnode") }
17
+
18
+ it { should have_body(node_show_response) }
19
+ it { should respond_with(200) }
20
+ end
21
+
22
+ context "if the node is not found" do
23
+ before { stub_node_show(404) }
24
+ subject { Node.show(:name => "testnode") }
25
+
26
+ it { should_not have_body(node_show_response) }
27
+ it { should respond_with(404) }
28
+ end
29
+ end
30
+
31
+ describe ".create" do
32
+ context "if the node can be created" do
33
+ before { stub_node_create }
34
+ subject { Node.create(:name => "testnode") }
35
+
36
+ it { should have_body(node_create_response) }
37
+ it { should respond_with(201) }
38
+ end
39
+
40
+ context "if the node has a run list" do
41
+ before { stub_node_create_with_run_list }
42
+ subject do
43
+ Node.create(
44
+ :name => "testnode",
45
+ :run_list => ["recipe[unicorn]" ]
46
+ )
47
+ end
48
+
49
+ it { should have_body(node_create_response_with_run_list) }
50
+ it { should respond_with(201) }
51
+ end
52
+
53
+ context "if the node already exists" do
54
+ before { stub_node_create(409) }
55
+ subject { Node.create(:name => "testnode") }
56
+
57
+ it { should have_body(node_conflict) }
58
+ it { should respond_with(409) }
59
+ end
60
+ end
61
+
62
+ describe ".delete" do
63
+ context "if the node can be deleted" do
64
+ before { stub_node_delete }
65
+ subject { Node.delete(:name => "testnode") }
66
+
67
+ it { should have_body(node_delete_response) }
68
+ it { should respond_with(200) }
69
+ end
70
+
71
+ context "if the node cannot be deleted" do
72
+ before { stub_node_delete(404) }
73
+ subject { Node.delete(:name => "testnode") }
74
+
75
+ it { should have_body(node_not_found) }
76
+ it { should respond_with(404) }
77
+ end
78
+ end
79
+
5
80
  end
6
81
  end
@@ -2,6 +2,67 @@ require 'spec_helper'
2
2
 
3
3
  module Spice
4
4
  describe Role do
5
+ describe ".all" do
6
+ before { stub_role_list }
7
+ subject { Role.all }
5
8
 
9
+ it { should have_body(role_list_response) }
10
+ it { should respond_with(200) }
11
+ end
12
+
13
+ describe ".show" do
14
+ context "if the role is found" do
15
+ before { stub_role_show }
16
+ subject { Role.show(:name => "testrole") }
17
+
18
+ it { should have_body(role_show_response) }
19
+ it { should respond_with(200) }
20
+ end
21
+
22
+ context "if the role is not found" do
23
+ before { stub_role_show(404) }
24
+ subject { Role.show(:name => "testrole") }
25
+
26
+ it { should_not have_body(role_show_response) }
27
+ it { should respond_with(404) }
28
+ end
29
+ end
30
+
31
+ describe ".create" do
32
+ context "if the role can be created" do
33
+ before { stub_role_create }
34
+ subject { Role.create(:name => "testrole") }
35
+
36
+ it { should have_body(role_create_response) }
37
+ it { should respond_with(201) }
38
+ end
39
+
40
+ context "if the role already exists" do
41
+ before { stub_role_create(409) }
42
+ subject { Role.create(:name => "testrole") }
43
+
44
+ it { should have_body(role_conflict) }
45
+ it { should respond_with(409) }
46
+ end
47
+ end
48
+
49
+ describe ".delete" do
50
+ context "if the role can be deleted" do
51
+ before { stub_role_delete }
52
+ subject { Role.delete(:name => "testrole") }
53
+
54
+ it { should have_body(role_delete_response) }
55
+ it { should respond_with(200) }
56
+ end
57
+
58
+ context "if the role cannot be deleted" do
59
+ before { stub_role_delete(404) }
60
+ subject { Role.delete(:name => "testrole") }
61
+
62
+ it { should have_body(role_not_found) }
63
+ it { should respond_with(404) }
64
+ end
65
+ end
66
+
6
67
  end
7
68
  end