acts_as_api 0.4.4 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -7
  3. data/History.txt +5 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.md +0 -25
  6. data/Rakefile +5 -12
  7. data/acts_as_api.gemspec +14 -13
  8. data/{examples/introduction → docs}/docco.css +0 -0
  9. data/{examples/introduction → docs}/index.html +18 -21
  10. data/{examples/introduction → docs}/index.rb +0 -0
  11. data/{examples/introduction → docs}/layout.mustache +0 -0
  12. data/lib/acts_as_api.rb +9 -12
  13. data/lib/acts_as_api/adapters.rb +1 -1
  14. data/lib/acts_as_api/api_template.rb +23 -25
  15. data/lib/acts_as_api/base.rb +11 -20
  16. data/lib/acts_as_api/collection.rb +1 -2
  17. data/lib/acts_as_api/config.rb +0 -5
  18. data/lib/acts_as_api/exceptions.rb +2 -2
  19. data/lib/acts_as_api/rails_renderer.rb +0 -2
  20. data/lib/acts_as_api/rendering.rb +5 -12
  21. data/lib/acts_as_api/responder.rb +8 -13
  22. data/lib/acts_as_api/version.rb +1 -1
  23. data/spec/README.md +15 -6
  24. data/spec/active_record_dummy/Gemfile +2 -10
  25. data/spec/active_record_dummy/app/models/user.rb +31 -32
  26. data/spec/active_record_dummy/config.ru +1 -1
  27. data/spec/active_record_dummy/config/application.rb +2 -2
  28. data/spec/active_record_dummy/config/boot.rb +1 -1
  29. data/spec/active_record_dummy/config/environments/test.rb +2 -2
  30. data/spec/active_record_dummy/config/initializers/session_store.rb +1 -1
  31. data/spec/active_record_dummy/config/initializers/wrap_parameters.rb +1 -1
  32. data/spec/active_record_dummy/config/routes.rb +1 -57
  33. data/spec/active_record_dummy/db/migrate/20110214201640_create_tables.rb +25 -26
  34. data/spec/active_record_dummy/db/schema.rb +27 -29
  35. data/spec/active_record_dummy/script/rails +2 -2
  36. data/spec/controllers/plain_objects_controller_spec.rb +11 -12
  37. data/spec/controllers/respond_with_users_controller_spec.rb +46 -67
  38. data/spec/controllers/users_controller_spec.rb +2 -3
  39. data/spec/models/model_spec.rb +17 -19
  40. data/spec/mongoid_dummy/Gemfile +3 -12
  41. data/spec/mongoid_dummy/app/models/profile.rb +6 -6
  42. data/spec/mongoid_dummy/app/models/task.rb +10 -10
  43. data/spec/mongoid_dummy/app/models/untouched.rb +4 -4
  44. data/spec/mongoid_dummy/app/models/user.rb +12 -14
  45. data/spec/mongoid_dummy/config.ru +1 -1
  46. data/spec/mongoid_dummy/config/application.rb +7 -7
  47. data/spec/mongoid_dummy/config/boot.rb +1 -1
  48. data/spec/mongoid_dummy/config/environments/development.rb +0 -1
  49. data/spec/mongoid_dummy/config/environments/production.rb +0 -1
  50. data/spec/mongoid_dummy/config/environments/test.rb +2 -2
  51. data/spec/mongoid_dummy/config/initializers/include_acts_as_api.rb +1 -1
  52. data/spec/mongoid_dummy/config/initializers/session_store.rb +1 -1
  53. data/spec/mongoid_dummy/config/initializers/wrap_parameters.rb +1 -2
  54. data/spec/mongoid_dummy/config/routes.rb +1 -57
  55. data/spec/mongoid_dummy/script/rails +2 -2
  56. data/spec/shared_engine/Gemfile +1 -1
  57. data/spec/shared_engine/Rakefile +1 -4
  58. data/spec/shared_engine/app/controllers/shared_engine/plain_objects_controller.rb +2 -2
  59. data/spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb +13 -15
  60. data/spec/shared_engine/app/controllers/shared_engine/users_controller.rb +17 -19
  61. data/spec/shared_engine/app/models/plain_object.rb +3 -1
  62. data/spec/shared_engine/app/models/user_template.rb +28 -29
  63. data/spec/shared_engine/lib/shared_engine.rb +1 -1
  64. data/spec/shared_engine/lib/shared_engine/version.rb +1 -1
  65. data/spec/shared_engine/shared_engine.gemspec +10 -12
  66. data/spec/spec_helper.rb +5 -13
  67. data/spec/support/api_test_helpers.rb +0 -2
  68. data/spec/support/controller_examples.rb +128 -173
  69. data/spec/support/it_supports.rb +1 -1
  70. data/spec/support/model_examples/associations.rb +119 -128
  71. data/spec/support/model_examples/callbacks.rb +17 -27
  72. data/spec/support/model_examples/closures.rb +21 -29
  73. data/spec/support/model_examples/conditional_if.rb +71 -103
  74. data/spec/support/model_examples/conditional_unless.rb +71 -103
  75. data/spec/support/model_examples/enabled.rb +5 -6
  76. data/spec/support/model_examples/extending.rb +49 -56
  77. data/spec/support/model_examples/methods.rb +11 -15
  78. data/spec/support/model_examples/options.rb +19 -25
  79. data/spec/support/model_examples/renaming.rb +21 -30
  80. data/spec/support/model_examples/simple.rb +10 -14
  81. data/spec/support/model_examples/sub_nodes.rb +47 -59
  82. data/spec/support/model_examples/undefined.rb +4 -6
  83. data/spec/support/model_examples/untouched.rb +6 -8
  84. data/spec/support/simple_fixtures.rb +11 -38
  85. metadata +22 -159
  86. data/spec/active_record_dummy/app/assets/images/rails.png +0 -0
  87. data/spec/active_record_dummy/app/assets/javascripts/application.js +0 -15
  88. data/spec/active_record_dummy/app/assets/stylesheets/application.css +0 -13
  89. data/spec/active_record_dummy/app/controllers/application_controller.rb +0 -3
  90. data/spec/active_record_dummy/app/helpers/application_helper.rb +0 -2
  91. data/spec/active_record_dummy/app/mailers/.gitkeep +0 -0
  92. data/spec/active_record_dummy/app/views/layouts/application.html.erb +0 -14
  93. data/spec/active_record_dummy/doc/README_FOR_APP +0 -2
  94. data/spec/active_record_dummy/lib/assets/.gitkeep +0 -0
  95. data/spec/active_record_dummy/lib/tasks/.gitkeep +0 -0
  96. data/spec/active_record_dummy/public/404.html +0 -26
  97. data/spec/active_record_dummy/public/422.html +0 -26
  98. data/spec/active_record_dummy/public/500.html +0 -25
  99. data/spec/active_record_dummy/public/favicon.ico +0 -0
  100. data/spec/active_record_dummy/public/index.html +0 -241
  101. data/spec/active_record_dummy/public/robots.txt +0 -5
  102. data/spec/active_record_dummy/vendor/assets/javascripts/.gitkeep +0 -0
  103. data/spec/active_record_dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  104. data/spec/active_record_dummy/vendor/plugins/.gitkeep +0 -0
  105. data/spec/mongoid_dummy/README.rdoc +0 -261
  106. data/spec/mongoid_dummy/app/assets/images/rails.png +0 -0
  107. data/spec/mongoid_dummy/app/assets/javascripts/application.js +0 -15
  108. data/spec/mongoid_dummy/app/assets/stylesheets/application.css +0 -13
  109. data/spec/mongoid_dummy/app/controllers/application_controller.rb +0 -3
  110. data/spec/mongoid_dummy/app/helpers/application_helper.rb +0 -2
  111. data/spec/mongoid_dummy/app/mailers/.gitkeep +0 -0
  112. data/spec/mongoid_dummy/app/views/layouts/application.html.erb +0 -14
  113. data/spec/mongoid_dummy/doc/README_FOR_APP +0 -2
  114. data/spec/mongoid_dummy/lib/assets/.gitkeep +0 -0
  115. data/spec/mongoid_dummy/lib/tasks/.gitkeep +0 -0
  116. data/spec/mongoid_dummy/public/404.html +0 -26
  117. data/spec/mongoid_dummy/public/422.html +0 -26
  118. data/spec/mongoid_dummy/public/500.html +0 -25
  119. data/spec/mongoid_dummy/public/favicon.ico +0 -0
  120. data/spec/mongoid_dummy/public/index.html +0 -241
  121. data/spec/mongoid_dummy/public/robots.txt +0 -5
  122. data/spec/mongoid_dummy/vendor/assets/javascripts/.gitkeep +0 -0
  123. data/spec/mongoid_dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  124. data/spec/mongoid_dummy/vendor/plugins/.gitkeep +0 -0
  125. data/spec/shared_engine/app/assets/images/shared_engine/.gitkeep +0 -0
  126. data/spec/shared_engine/app/assets/javascripts/shared_engine/application.js +0 -15
  127. data/spec/shared_engine/app/assets/stylesheets/shared_engine/application.css +0 -13
  128. data/spec/shared_engine/app/helpers/shared_engine/application_helper.rb +0 -4
  129. data/spec/shared_engine/app/views/layouts/shared_engine/application.html.erb +0 -14
  130. data/spec/shared_engine/dummy/README.rdoc +0 -261
  131. data/spec/shared_engine/dummy/Rakefile +0 -7
  132. data/spec/shared_engine/dummy/app/assets/javascripts/application.js +0 -15
  133. data/spec/shared_engine/dummy/app/assets/stylesheets/application.css +0 -13
  134. data/spec/shared_engine/dummy/app/controllers/application_controller.rb +0 -3
  135. data/spec/shared_engine/dummy/app/helpers/application_helper.rb +0 -2
  136. data/spec/shared_engine/dummy/app/mailers/.gitkeep +0 -0
  137. data/spec/shared_engine/dummy/app/models/.gitkeep +0 -0
  138. data/spec/shared_engine/dummy/app/views/layouts/application.html.erb +0 -14
  139. data/spec/shared_engine/dummy/config.ru +0 -4
  140. data/spec/shared_engine/dummy/config/application.rb +0 -56
  141. data/spec/shared_engine/dummy/config/boot.rb +0 -10
  142. data/spec/shared_engine/dummy/config/database.yml +0 -25
  143. data/spec/shared_engine/dummy/config/environment.rb +0 -5
  144. data/spec/shared_engine/dummy/config/environments/development.rb +0 -34
  145. data/spec/shared_engine/dummy/config/environments/production.rb +0 -63
  146. data/spec/shared_engine/dummy/config/environments/test.rb +0 -37
  147. data/spec/shared_engine/dummy/config/initializers/backtrace_silencers.rb +0 -7
  148. data/spec/shared_engine/dummy/config/initializers/inflections.rb +0 -15
  149. data/spec/shared_engine/dummy/config/initializers/mime_types.rb +0 -5
  150. data/spec/shared_engine/dummy/config/initializers/secret_token.rb +0 -7
  151. data/spec/shared_engine/dummy/config/initializers/session_store.rb +0 -8
  152. data/spec/shared_engine/dummy/config/initializers/wrap_parameters.rb +0 -14
  153. data/spec/shared_engine/dummy/config/locales/en.yml +0 -5
  154. data/spec/shared_engine/dummy/config/routes.rb +0 -4
  155. data/spec/shared_engine/dummy/lib/assets/.gitkeep +0 -0
  156. data/spec/shared_engine/dummy/log/.gitkeep +0 -0
  157. data/spec/shared_engine/dummy/public/404.html +0 -26
  158. data/spec/shared_engine/dummy/public/422.html +0 -26
  159. data/spec/shared_engine/dummy/public/500.html +0 -25
  160. data/spec/shared_engine/dummy/public/favicon.ico +0 -0
  161. data/spec/shared_engine/dummy/script/rails +0 -6
@@ -1,49 +1,41 @@
1
- shared_examples_for "calling a closure in the api template" do
1
+ shared_examples_for 'calling a closure in the api template' do
2
+ describe 'i.e. a proc (the record is passed as only parameter)' do
3
+ subject(:response) { @luke.as_api_response(:calling_a_proc) }
2
4
 
3
- describe "i.e. a proc (the record is passed as only parameter)" do
4
-
5
- before(:each) do
6
- @response = @luke.as_api_response(:calling_a_proc)
7
- end
8
-
9
- it "returns a hash" do
10
- @response.should be_kind_of(Hash)
5
+ it 'returns a hash' do
6
+ expect(response).to be_kind_of(Hash)
11
7
  end
12
8
 
13
- it "returns the correct number of fields" do
14
- @response.should have(2).keys
9
+ it 'returns the correct number of fields' do
10
+ expect(response).to have(2).keys
15
11
  end
16
12
 
17
- it "returns all specified fields" do
18
- @response.keys.sort_by(&:to_s).should eql([:all_caps_name, :without_param])
13
+ it 'returns all specified fields' do
14
+ expect(response.keys.sort_by(&:to_s)).to eql([:all_caps_name, :without_param])
19
15
  end
20
16
 
21
- it "returns the correct values for the specified fields" do
22
- @response.values.sort.should eql(["LUKE SKYWALKER", "Time"])
17
+ it 'returns the correct values for the specified fields' do
18
+ expect(response.values.sort).to eql(['LUKE SKYWALKER', 'Time'])
23
19
  end
24
20
  end
25
21
 
26
- describe "i.e. a lambda (the record is passed as only parameter)" do
22
+ describe 'i.e. a lambda (the record is passed as only parameter)' do
23
+ subject(:response) { @luke.as_api_response(:calling_a_lambda) }
27
24
 
28
- before(:each) do
29
- @response = @luke.as_api_response(:calling_a_lambda)
25
+ it 'returns a hash' do
26
+ expect(response).to be_kind_of(Hash)
30
27
  end
31
28
 
32
- it "returns a hash" do
33
- @response.should be_kind_of(Hash)
29
+ it 'returns the correct number of fields' do
30
+ expect(response).to have(2).keys
34
31
  end
35
32
 
36
- it "returns the correct number of fields" do
37
- @response.should have(2).keys
33
+ it 'returns all specified fields' do
34
+ expect(response.keys.sort_by(&:to_s)).to eql([:all_caps_name, :without_param])
38
35
  end
39
36
 
40
- it "returns all specified fields" do
41
- @response.keys.sort_by(&:to_s).should eql([:all_caps_name, :without_param])
37
+ it 'returns the correct values for the specified fields' do
38
+ expect(response.values.sort).to eql(['LUKE SKYWALKER', 'Time'])
42
39
  end
43
-
44
- it "returns the correct values for the specified fields" do
45
- @response.values.sort.should eql(["LUKE SKYWALKER", "Time"])
46
- end
47
-
48
40
  end
49
41
  end
@@ -1,165 +1,133 @@
1
- shared_examples_for "conditional if statements" do
2
-
3
- describe "using the :if option" do
4
-
5
- describe "passing a symbol" do
6
-
7
- describe "that returns false" do
8
-
9
- before(:each) do
10
- @response = @luke.as_api_response(:if_over_thirty)
1
+ shared_examples_for 'conditional if statements' do
2
+ describe 'using the :if option' do
3
+ describe 'passing a symbol' do
4
+ describe 'that returns false' do
5
+ subject(:response) { @luke.as_api_response(:if_over_thirty) }
6
+
7
+ it 'returns a hash' do
8
+ expect(response).to be_kind_of(Hash)
11
9
  end
12
10
 
13
- it "returns a hash" do
14
- @response.should be_kind_of(Hash)
11
+ it 'returns the correct number of fields' do
12
+ expect(response).to have(1).keys
15
13
  end
16
14
 
17
- it "returns the correct number of fields" do
18
- @response.should have(1).keys
15
+ it 'will not add the conditional field but all others' do
16
+ expect(response.keys).to include(:first_name)
17
+ expect(response.keys).not_to include(:full_name)
19
18
  end
20
19
 
21
- it "won't add the conditional field but all others" do
22
- @response.keys.should include(:first_name)
23
- @response.keys.should_not include(:full_name)
20
+ it 'the other specified fields have the correct value' do
21
+ expect(response.values).to include(@luke.first_name)
24
22
  end
25
-
26
- it "the other specified fields have the correct value" do
27
- @response.values.should include(@luke.first_name)
28
- end
29
-
30
23
  end
31
24
 
32
- describe "that returns nil" do
25
+ describe 'that returns nil' do
26
+ subject(:response) { @luke.as_api_response(:if_returns_nil) }
33
27
 
34
- before(:each) do
35
- @response = @luke.as_api_response(:if_returns_nil)
28
+ it 'returns a hash' do
29
+ expect(response).to be_kind_of(Hash)
36
30
  end
37
31
 
38
- it "returns a hash" do
39
- @response.should be_kind_of(Hash)
32
+ it 'returns the correct number of fields' do
33
+ expect(response).to have(1).keys
40
34
  end
41
35
 
42
- it "returns the correct number of fields" do
43
- @response.should have(1).keys
36
+ it 'will not add the conditional field but all others' do
37
+ expect(response.keys).to include(:first_name)
38
+ expect(response.keys).not_to include(:full_name)
44
39
  end
45
40
 
46
- it "won't add the conditional field but all others" do
47
- @response.keys.should include(:first_name)
48
- @response.keys.should_not include(:full_name)
41
+ it 'the other specified fields have the correct value' do
42
+ expect(response.values).to include(@luke.first_name)
49
43
  end
50
-
51
- it "the other specified fields have the correct value" do
52
- @response.values.should include(@luke.first_name)
53
- end
54
-
55
44
  end
56
45
 
57
- describe "that returns true" do
46
+ describe 'that returns true' do
47
+ subject(:response) { @han.as_api_response(:if_over_thirty) }
58
48
 
59
- before(:each) do
60
- @response = @han.as_api_response(:if_over_thirty)
49
+ it 'returns a hash' do
50
+ expect(response).to be_kind_of(Hash)
61
51
  end
62
52
 
63
- it "returns a hash" do
64
- @response.should be_kind_of(Hash)
53
+ it 'returns the correct number of fields' do
54
+ expect(response).to have(2).keys
65
55
  end
66
56
 
67
- it "returns the correct number of fields" do
68
- @response.should have(2).keys
57
+ it 'will not add the conditional field but all others' do
58
+ expect(response.keys).to include(:first_name)
59
+ expect(response.keys).to include(:last_name)
69
60
  end
70
61
 
71
- it "won't add the conditional field but all others" do
72
- @response.keys.should include(:first_name)
73
- @response.keys.should include(:last_name)
62
+ it 'the other specified fields have the correct value' do
63
+ expect(response.values).to include(@han.first_name, @han.last_name)
74
64
  end
75
-
76
- it "the other specified fields have the correct value" do
77
- @response.values.should include(@han.first_name, @han.last_name)
78
- end
79
-
80
65
  end
81
-
82
66
  end
83
-
84
67
  end
85
68
 
86
- describe "passing a proc" do
87
-
88
- describe "that returns false" do
89
-
90
- before(:each) do
91
- @response = @luke.as_api_response(:if_over_thirty_proc)
92
- end
69
+ describe 'passing a proc' do
70
+ describe 'that returns false' do
71
+ subject(:response) { @luke.as_api_response(:if_over_thirty_proc) }
93
72
 
94
- it "returns a hash" do
95
- @response.should be_kind_of(Hash)
73
+ it 'returns a hash' do
74
+ expect(response).to be_kind_of(Hash)
96
75
  end
97
76
 
98
- it "returns the correct number of fields" do
99
- @response.should have(1).keys
77
+ it 'returns the correct number of fields' do
78
+ expect(response).to have(1).keys
100
79
  end
101
80
 
102
- it "won't add the conditional field but all others" do
103
- @response.keys.should include(:first_name)
104
- @response.keys.should_not include(:full_name)
81
+ it 'will not add the conditional field but all others' do
82
+ expect(response.keys).to include(:first_name)
83
+ expect(response.keys).not_to include(:full_name)
105
84
  end
106
85
 
107
- it "the other specified fields have the correct value" do
108
- @response.values.should include(@luke.first_name)
86
+ it 'the other specified fields have the correct value' do
87
+ expect(response.values).to include(@luke.first_name)
109
88
  end
110
-
111
89
  end
112
90
 
113
- describe "that returns nil" do
114
-
115
- before(:each) do
116
- @response = @luke.as_api_response(:if_returns_nil_proc)
117
- end
91
+ describe 'that returns nil' do
92
+ subject(:response) { @luke.as_api_response(:if_returns_nil_proc) }
118
93
 
119
- it "returns a hash" do
120
- @response.should be_kind_of(Hash)
94
+ it 'returns a hash' do
95
+ expect(response).to be_kind_of(Hash)
121
96
  end
122
97
 
123
- it "returns the correct number of fields" do
124
- @response.should have(1).keys
98
+ it 'returns the correct number of fields' do
99
+ expect(response).to have(1).keys
125
100
  end
126
101
 
127
- it "won't add the conditional field but all others" do
128
- @response.keys.should include(:first_name)
129
- @response.keys.should_not include(:full_name)
102
+ it 'will not add the conditional field but all others' do
103
+ expect(response.keys).to include(:first_name)
104
+ expect(response.keys).not_to include(:full_name)
130
105
  end
131
106
 
132
- it "the other specified fields have the correct value" do
133
- @response.values.should include(@luke.first_name)
107
+ it 'the other specified fields have the correct value' do
108
+ expect(response.values).to include(@luke.first_name)
134
109
  end
135
-
136
110
  end
137
111
 
138
- describe "that returns true" do
139
-
140
- before(:each) do
141
- @response = @han.as_api_response(:if_over_thirty_proc)
142
- end
112
+ describe 'that returns true' do
113
+ subject(:response) { @han.as_api_response(:if_over_thirty_proc) }
143
114
 
144
- it "returns a hash" do
145
- @response.should be_kind_of(Hash)
115
+ it 'returns a hash' do
116
+ expect(response).to be_kind_of(Hash)
146
117
  end
147
118
 
148
- it "returns the correct number of fields" do
149
- @response.should have(2).keys
119
+ it 'returns the correct number of fields' do
120
+ expect(response).to have(2).keys
150
121
  end
151
122
 
152
- it "won't add the conditional field but all others" do
153
- @response.keys.should include(:first_name)
154
- @response.keys.should include(:last_name)
123
+ it 'will not add the conditional field but all others' do
124
+ expect(response.keys).to include(:first_name)
125
+ expect(response.keys).to include(:last_name)
155
126
  end
156
127
 
157
- it "the other specified fields have the correct value" do
158
- @response.values.should include(@han.first_name, @han.last_name)
128
+ it 'the other specified fields have the correct value' do
129
+ expect(response.values).to include(@han.first_name, @han.last_name)
159
130
  end
160
-
161
131
  end
162
-
163
132
  end
164
133
  end
165
-
@@ -1,165 +1,133 @@
1
- shared_examples_for "conditional unless statements" do
2
-
3
- describe "using the :unless option" do
4
-
5
- describe "passing a symbol" do
6
-
7
- describe "that returns false" do
8
-
9
- before(:each) do
10
- @response = @luke.as_api_response(:unless_under_thirty)
1
+ shared_examples_for 'conditional unless statements' do
2
+ describe 'using the :unless option' do
3
+ describe 'passing a symbol' do
4
+ describe 'that returns false' do
5
+ subject(:response) { @luke.as_api_response(:unless_under_thirty) }
6
+
7
+ it 'returns a hash' do
8
+ expect(response).to be_kind_of(Hash)
11
9
  end
12
10
 
13
- it "returns a hash" do
14
- @response.should be_kind_of(Hash)
11
+ it 'returns the correct number of fields' do
12
+ expect(response).to have(1).keys
15
13
  end
16
14
 
17
- it "returns the correct number of fields" do
18
- @response.should have(1).keys
15
+ it 'will not add the conditional field but all others' do
16
+ expect(response.keys).to include(:first_name)
17
+ expect(response.keys).not_to include(:full_name)
19
18
  end
20
19
 
21
- it "won't add the conditional field but all others" do
22
- @response.keys.should include(:first_name)
23
- @response.keys.should_not include(:full_name)
20
+ it 'the other specified fields have the correct value' do
21
+ expect(response.values).to include(@luke.first_name)
24
22
  end
25
-
26
- it "the other specified fields have the correct value" do
27
- @response.values.should include(@luke.first_name)
28
- end
29
-
30
23
  end
31
24
 
32
- describe "that returns nil" do
25
+ describe 'that returns nil' do
26
+ subject(:response) { @luke.as_api_response(:unless_returns_nil) }
33
27
 
34
- before(:each) do
35
- @response = @luke.as_api_response(:unless_returns_nil)
28
+ it 'returns a hash' do
29
+ expect(response).to be_kind_of(Hash)
36
30
  end
37
31
 
38
- it "returns a hash" do
39
- @response.should be_kind_of(Hash)
32
+ it 'returns the correct number of fields' do
33
+ expect(response).to have(2).keys
40
34
  end
41
35
 
42
- it "returns the correct number of fields" do
43
- @response.should have(2).keys
36
+ it 'will not add the conditional field but all others' do
37
+ expect(response.keys).to include(:first_name)
38
+ expect(response.keys).to include(:last_name)
44
39
  end
45
40
 
46
- it "won't add the conditional field but all others" do
47
- @response.keys.should include(:first_name)
48
- @response.keys.should include(:last_name)
41
+ it 'the other specified fields have the correct value' do
42
+ expect(response.values).to include(@luke.first_name, @luke.last_name)
49
43
  end
50
-
51
- it "the other specified fields have the correct value" do
52
- @response.values.should include(@luke.first_name, @luke.last_name)
53
- end
54
-
55
44
  end
56
45
 
57
- describe "that returns true" do
46
+ describe 'that returns true' do
47
+ subject(:response) { @han.as_api_response(:unless_under_thirty) }
58
48
 
59
- before(:each) do
60
- @response = @han.as_api_response(:unless_under_thirty)
49
+ it 'returns a hash' do
50
+ expect(response).to be_kind_of(Hash)
61
51
  end
62
52
 
63
- it "returns a hash" do
64
- @response.should be_kind_of(Hash)
53
+ it 'returns the correct number of fields' do
54
+ expect(response).to have(2).keys
65
55
  end
66
56
 
67
- it "returns the correct number of fields" do
68
- @response.should have(2).keys
57
+ it 'will not add the conditional field but all others' do
58
+ expect(response.keys).to include(:first_name)
59
+ expect(response.keys).to include(:last_name)
69
60
  end
70
61
 
71
- it "won't add the conditional field but all others" do
72
- @response.keys.should include(:first_name)
73
- @response.keys.should include(:last_name)
62
+ it 'the other specified fields have the correct value' do
63
+ expect(response.values).to include(@han.first_name, @han.last_name)
74
64
  end
75
-
76
- it "the other specified fields have the correct value" do
77
- @response.values.should include(@han.first_name, @han.last_name)
78
- end
79
-
80
65
  end
81
-
82
66
  end
83
-
84
67
  end
85
68
 
86
- describe "passing a proc" do
87
-
88
- describe "that returns false" do
89
-
90
- before(:each) do
91
- @response = @luke.as_api_response(:unless_under_thirty_proc)
92
- end
69
+ describe 'passing a proc' do
70
+ describe 'that returns false' do
71
+ subject(:response) { @luke.as_api_response(:unless_under_thirty_proc) }
93
72
 
94
- it "returns a hash" do
95
- @response.should be_kind_of(Hash)
73
+ it 'returns a hash' do
74
+ expect(response).to be_kind_of(Hash)
96
75
  end
97
76
 
98
- it "returns the correct number of fields" do
99
- @response.should have(1).keys
77
+ it 'returns the correct number of fields' do
78
+ expect(response).to have(1).keys
100
79
  end
101
80
 
102
- it "won't add the conditional field but all others" do
103
- @response.keys.should include(:first_name)
104
- @response.keys.should_not include(:full_name)
81
+ it 'will not add the conditional field but all others' do
82
+ expect(response.keys).to include(:first_name)
83
+ expect(response.keys).not_to include(:full_name)
105
84
  end
106
85
 
107
- it "the other specified fields have the correct value" do
108
- @response.values.should include(@luke.first_name)
86
+ it 'the other specified fields have the correct value' do
87
+ expect(response.values).to include(@luke.first_name)
109
88
  end
110
-
111
89
  end
112
90
 
113
- describe "that returns nil" do
114
-
115
- before(:each) do
116
- @response = @luke.as_api_response(:if_returns_nil_proc)
117
- end
91
+ describe 'that returns nil' do
92
+ subject(:response) { @luke.as_api_response(:if_returns_nil_proc) }
118
93
 
119
- it "returns a hash" do
120
- @response.should be_kind_of(Hash)
94
+ it 'returns a hash' do
95
+ expect(response).to be_kind_of(Hash)
121
96
  end
122
97
 
123
- it "returns the correct number of fields" do
124
- @response.should have(1).keys
98
+ it 'returns the correct number of fields' do
99
+ expect(response).to have(1).keys
125
100
  end
126
101
 
127
- it "won't add the conditional field but all others" do
128
- @response.keys.should include(:first_name)
129
- @response.keys.should_not include(:full_name)
102
+ it 'will not add the conditional field but all others' do
103
+ expect(response.keys).to include(:first_name)
104
+ expect(response.keys).not_to include(:full_name)
130
105
  end
131
106
 
132
- it "the other specified fields have the correct value" do
133
- @response.values.should include(@luke.first_name)
107
+ it 'the other specified fields have the correct value' do
108
+ expect(response.values).to include(@luke.first_name)
134
109
  end
135
-
136
110
  end
137
111
 
138
- describe "that returns true" do
139
-
140
- before(:each) do
141
- @response = @han.as_api_response(:unless_under_thirty_proc)
142
- end
112
+ describe 'that returns true' do
113
+ subject(:response) { @han.as_api_response(:unless_under_thirty_proc) }
143
114
 
144
- it "returns a hash" do
145
- @response.should be_kind_of(Hash)
115
+ it 'returns a hash' do
116
+ expect(response).to be_kind_of(Hash)
146
117
  end
147
118
 
148
- it "returns the correct number of fields" do
149
- @response.should have(2).keys
119
+ it 'returns the correct number of fields' do
120
+ expect(response).to have(2).keys
150
121
  end
151
122
 
152
- it "won't add the conditional field but all others" do
153
- @response.keys.should include(:first_name)
154
- @response.keys.should include(:last_name)
123
+ it 'will not add the conditional field but all others' do
124
+ expect(response.keys).to include(:first_name)
125
+ expect(response.keys).to include(:last_name)
155
126
  end
156
127
 
157
- it "the other specified fields have the correct value" do
158
- @response.values.should include(@han.first_name, @han.last_name)
128
+ it 'the other specified fields have the correct value' do
129
+ expect(response.values).to include(@han.first_name, @han.last_name)
159
130
  end
160
-
161
131
  end
162
-
163
132
  end
164
-
165
133
  end