apipie-rails 0.3.5 → 0.3.6

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 +5 -13
  2. data/.travis.yml +4 -1
  3. data/CHANGELOG.md +19 -0
  4. data/Gemfile.rails32 +1 -0
  5. data/Gemfile.rails41 +1 -1
  6. data/Gemfile.rails42 +5 -0
  7. data/README.rst +21 -4
  8. data/apipie-rails.gemspec +3 -3
  9. data/app/controllers/apipie/apipies_controller.rb +22 -1
  10. data/app/public/apipie/javascripts/bundled/jquery.js +5 -0
  11. data/app/views/apipie/apipies/_disqus.html.erb +3 -3
  12. data/app/views/apipie/apipies/_errors.html.erb +23 -0
  13. data/app/views/apipie/apipies/_method_detail.erb +1 -9
  14. data/app/views/apipie/apipies/_params.html.erb +11 -5
  15. data/app/views/apipie/apipies/apipie_404.html.erb +4 -4
  16. data/app/views/apipie/apipies/static.html.erb +1 -6
  17. data/app/views/layouts/apipie/apipie.html.erb +4 -3
  18. data/config/locales/de.yml +28 -0
  19. data/config/locales/en.yml +30 -28
  20. data/config/locales/es.yml +27 -27
  21. data/config/locales/pl.yml +27 -28
  22. data/config/locales/pt-BR.yml +1 -1
  23. data/config/locales/ru.yml +27 -28
  24. data/config/locales/tr.yml +28 -0
  25. data/config/locales/zh-CN.yml +2 -2
  26. data/config/locales/zh-TW.yml +2 -2
  27. data/lib/apipie/configuration.rb +1 -1
  28. data/lib/apipie/dsl_definition.rb +1 -1
  29. data/lib/apipie/errors.rb +9 -1
  30. data/lib/apipie/extractor/collector.rb +2 -2
  31. data/lib/apipie/extractor/writer.rb +6 -0
  32. data/lib/apipie/helpers.rb +22 -1
  33. data/lib/apipie/param_description.rb +5 -2
  34. data/lib/apipie/validator.rb +7 -6
  35. data/lib/apipie/version.rb +1 -1
  36. data/lib/tasks/apipie.rake +3 -2
  37. data/spec/controllers/api/v1/architectures_controller_spec.rb +7 -8
  38. data/spec/controllers/api/v2/architectures_controller_spec.rb +1 -1
  39. data/spec/controllers/api/v2/nested/resources_controller_spec.rb +1 -1
  40. data/spec/controllers/apipies_controller_spec.rb +71 -27
  41. data/spec/controllers/concerns_controller_spec.rb +9 -9
  42. data/spec/controllers/users_controller_spec.rb +122 -123
  43. data/spec/dummy/app/controllers/users_controller.rb +2 -1
  44. data/spec/dummy/config/initializers/secret_token.rb +1 -0
  45. data/spec/lib/application_spec.rb +3 -3
  46. data/spec/lib/extractor/writer_spec.rb +4 -4
  47. data/spec/lib/method_description_spec.rb +7 -7
  48. data/spec/lib/param_description_spec.rb +61 -46
  49. data/spec/lib/param_group_spec.rb +11 -11
  50. data/spec/lib/rake_spec.rb +10 -10
  51. data/spec/lib/resource_description_spec.rb +6 -6
  52. data/spec/lib/validator_spec.rb +7 -7
  53. data/spec/spec_helper.rb +11 -1
  54. metadata +36 -33
  55. data/app/public/apipie/javascripts/bundled/jquery-1.7.2.js +0 -9404
@@ -5,7 +5,7 @@ describe Api::V2::ArchitecturesController do
5
5
  subject { Apipie.get_resource_description(Api::V2::ArchitecturesController, "2.0") }
6
6
 
7
7
  it "should be version 2.0" do
8
- subject._version.should eq('2.0')
8
+ expect(subject._version).to eq('2.0')
9
9
  end
10
10
 
11
11
  end
@@ -5,7 +5,7 @@ describe Api::V2::Nested::ResourcesController do
5
5
  subject { Apipie.get_resource_name(Api::V2::Nested::ResourcesController) }
6
6
 
7
7
  it "should have resource_id set" do
8
- subject.should eq("resource")
8
+ expect(subject).to eq("resource")
9
9
  end
10
10
  end
11
11
  end
@@ -51,18 +51,18 @@ describe Apipie::ApipiesController do
51
51
  describe "reload_controllers" do
52
52
 
53
53
  RSpec::Matchers.define :reload_documentation do
54
- match do
55
- Apipie.should_receive(:reload_documentation)
54
+ match do |actual|
55
+ expect(Apipie).to receive(:reload_documentation)
56
+ get :index
57
+ end
58
+
59
+ match_when_negated do |actual|
60
+ expect(Apipie).not_to receive(:reload_documentation)
56
61
  get :index
57
- begin
58
- RSpec::Mocks.verify
59
- rescue RSpec::Mocks::MockExpectationError
60
- false
61
- end
62
62
  end
63
63
 
64
- failure_message_for_should { "the documentation expected to be reloaded but it was not" }
65
- failure_message_for_should_not { "the documentation expected not to be reloaded but it was" }
64
+ failure_message { "the documentation expected to be reloaded but it was not" }
65
+ failure_message_when_negated { "the documentation expected not to be reloaded but it was" }
66
66
  end
67
67
 
68
68
  before do
@@ -75,13 +75,13 @@ describe Apipie::ApipiesController do
75
75
  context "it's not specified explicitly" do
76
76
  context "and it's in development environment" do
77
77
  before do
78
- Rails.stub(:env => mock(:development? => true))
78
+ allow(Rails).to receive_messages(:env => double(:development? => true))
79
79
  end
80
- it { should reload_documentation }
80
+ it { is_expected.to reload_documentation }
81
81
  end
82
82
 
83
83
  context "and it's not development environment" do
84
- it { should_not reload_documentation }
84
+ it { is_expected.not_to reload_documentation }
85
85
  end
86
86
  end
87
87
 
@@ -93,13 +93,13 @@ describe Apipie::ApipiesController do
93
93
 
94
94
  context "and it's in development environment" do
95
95
  before do
96
- Rails.stub(:env => mock(:development? => true))
96
+ allow(Rails).to receive_messages(:env => double(:development? => true))
97
97
  end
98
- it { should reload_documentation }
98
+ it { is_expected.to reload_documentation }
99
99
  end
100
100
 
101
101
  context "and it's not development environment" do
102
- it { should reload_documentation }
102
+ it { is_expected.to reload_documentation }
103
103
  end
104
104
  end
105
105
 
@@ -110,13 +110,13 @@ describe Apipie::ApipiesController do
110
110
 
111
111
  context "and it's in development environment" do
112
112
  before do
113
- Rails.stub(:env => mock(:development? => true))
113
+ allow(Rails).to receive_messages(:env => double(:development? => true))
114
114
  end
115
- it { should_not reload_documentation }
115
+ it { is_expected.not_to reload_documentation }
116
116
  end
117
117
 
118
118
  context "and it's not development environment" do
119
- it { should_not reload_documentation }
119
+ it { is_expected.not_to reload_documentation }
120
120
  end
121
121
  end
122
122
 
@@ -126,7 +126,7 @@ describe Apipie::ApipiesController do
126
126
  Apipie.configuration.api_controllers_matcher = nil
127
127
  end
128
128
 
129
- it { should_not reload_documentation }
129
+ it { is_expected.not_to reload_documentation }
130
130
  end
131
131
  end
132
132
 
@@ -137,7 +137,51 @@ describe Apipie::ApipiesController do
137
137
  test = true
138
138
  end
139
139
  get :index
140
- test.should == true
140
+ expect(test).to eq(true)
141
+ end
142
+ end
143
+
144
+ describe "authorize document" do
145
+ it "if an authroize method is set" do
146
+ test = false
147
+ Apipie.configuration.authorize = Proc.new do |controller, method, doc|
148
+ test = true
149
+ true
150
+ end
151
+ get :index
152
+ expect(test).to eq(true)
153
+ end
154
+ it "remove all resources" do
155
+ Apipie.configuration.authorize = Proc.new do |&args|
156
+ false
157
+ end
158
+ get :index
159
+ expect(assigns(:doc)[:resources]).to eq({})
160
+ end
161
+ it "remove all methods" do
162
+ Apipie.configuration.authorize = Proc.new do |controller, method, doc|
163
+ !method
164
+ end
165
+ get :index
166
+ expect(assigns(:doc)[:resources]["concern_resources"][:methods]).to eq([])
167
+ expect(assigns(:doc)[:resources]["twitter_example"][:methods]).to eq([])
168
+ expect(assigns(:doc)[:resources]["users"][:methods]).to eq([])
169
+ end
170
+ it "remove specific method" do
171
+ Apipie.configuration.authorize = nil
172
+ get :index
173
+
174
+ users_methods = assigns(:doc)[:resources]["users"][:methods].size
175
+ twitter_example_methods = assigns(:doc)[:resources]["twitter_example"][:methods].size
176
+
177
+ Apipie.configuration.authorize = Proc.new do |controller, method, doc|
178
+ controller == "users" ? method != "index" : true
179
+ end
180
+
181
+ get :index
182
+
183
+ expect(assigns(:doc)[:resources]["users"][:methods].size).to eq(users_methods - 1)
184
+ expect(assigns(:doc)[:resources]["twitter_example"][:methods].size).to eq(twitter_example_methods)
141
185
  end
142
186
  end
143
187
 
@@ -170,19 +214,19 @@ describe Apipie::ApipiesController do
170
214
 
171
215
  it "uses the file in cache dir instead of generating the content on runtime" do
172
216
  get :index
173
- response.body.should == "apidoc.html cache v1"
217
+ expect(response.body).to eq("apidoc.html cache v1")
174
218
  get :index, :version => 'v1'
175
- response.body.should == "apidoc.html cache v1"
219
+ expect(response.body).to eq("apidoc.html cache v1")
176
220
  get :index, :version => 'v2'
177
- response.body.should == "apidoc.html cache v2"
221
+ expect(response.body).to eq("apidoc.html cache v2")
178
222
  get :index, :version => 'v1', :format => "html"
179
- response.body.should == "apidoc.html cache v1"
223
+ expect(response.body).to eq("apidoc.html cache v1")
180
224
  get :index, :version => 'v1', :format => "json"
181
- response.body.should == "apidoc.json cache"
225
+ expect(response.body).to eq("apidoc.json cache")
182
226
  get :index, :version => 'v1', :format => "html", :resource => "resource"
183
- response.body.should == "resource.html cache"
227
+ expect(response.body).to eq("resource.html cache")
184
228
  get :index, :version => 'v1', :format => "html", :resource => "resource", :method => "method"
185
- response.body.should == "method.html cache"
229
+ expect(response.body).to eq("method.html cache")
186
230
  end
187
231
 
188
232
  end
@@ -3,8 +3,8 @@ require "spec_helper"
3
3
  describe ConcernsController do
4
4
 
5
5
  it "displays is every controller the concern is included" do
6
- Apipie["concern_resources#index"].should be
7
- Apipie["concern_resources#show"].should be
6
+ expect(Apipie["concern_resources#index"]).to be
7
+ expect(Apipie["concern_resources#show"]).to be
8
8
  end
9
9
 
10
10
  it "should reply to valid request" do
@@ -13,30 +13,30 @@ describe ConcernsController do
13
13
  end
14
14
 
15
15
  it "should pass if required parameter is missing" do
16
- lambda { get :show, :id => '5' }.should_not raise_error
16
+ expect { get :show, :id => '5' }.not_to raise_error
17
17
  end
18
18
 
19
19
  it "peserved the order of methods being defined in file" do
20
20
  doc_methods = Apipie.get_resource_description('concern_resources')._methods.keys
21
- doc_methods.should == [:index, :show, :create, :update, :custom]
21
+ expect(doc_methods).to eq([:index, :show, :create, :update, :custom])
22
22
  end
23
23
 
24
24
  it "replaces a placeholder doc specified in concern with a real path" do
25
25
  path = Apipie["concern_resources#index"].apis.first.path
26
- path.should == '/api/concerns'
26
+ expect(path).to eq('/api/concerns')
27
27
 
28
28
  path = Apipie["concern_resources#show"].apis.first.path
29
- path.should == '/concern_resources/:id'
29
+ expect(path).to eq('/concern_resources/:id')
30
30
 
31
31
  path = Apipie["concern_resources#custom"].apis.first.path
32
- path.should == '/concern_resources/custom'
32
+ expect(path).to eq('/concern_resources/custom')
33
33
  end
34
34
 
35
35
  it "replaces placeholders in param names and descriptions" do
36
36
  create_desc = Apipie["concern_resources#create"].params[:user]
37
37
  name_param, concern_type_param = create_desc.validator.params_ordered
38
- name_param.desc.should include "Name of a user"
39
- concern_type_param.name.should == :user_type
38
+ expect(name_param.desc).to include "Name of a user"
39
+ expect(concern_type_param.name).to eq(:user_type)
40
40
  end
41
41
  end
42
42
 
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  def compare_hashes(h1, h2)
4
4
  if h1.is_a? String
5
- h1.should eq(h2)
5
+ expect(h1).to eq(h2)
6
6
  else
7
7
  h1.each do |key, val|
8
8
  if val.is_a? Hash
@@ -12,7 +12,7 @@ def compare_hashes(h1, h2)
12
12
  compare_hashes val[i], h2[key][i]
13
13
  end
14
14
  else
15
- val.should eq(h2[key])
15
+ expect(val).to eq(h2[key])
16
16
  end
17
17
  end
18
18
  end
@@ -29,30 +29,30 @@ describe UsersController do
29
29
 
30
30
  it "should contain all resource methods" do
31
31
  methods = subject._methods
32
- methods.keys.should include(:show)
33
- methods.keys.should include(:create_route)
34
- methods.keys.should include(:index)
35
- methods.keys.should include(:create)
36
- methods.keys.should include(:update)
37
- methods.keys.should include(:two_urls)
38
- methods.keys.should include(:action_with_headers)
32
+ expect(methods.keys).to include(:show)
33
+ expect(methods.keys).to include(:create_route)
34
+ expect(methods.keys).to include(:index)
35
+ expect(methods.keys).to include(:create)
36
+ expect(methods.keys).to include(:update)
37
+ expect(methods.keys).to include(:two_urls)
38
+ expect(methods.keys).to include(:action_with_headers)
39
39
  end
40
40
 
41
41
  it "should contain info about resource" do
42
- subject._short_description.should eq('Site members')
43
- subject._id.should eq('users')
44
- subject._path.should eq('/users')
45
- subject._version.should eq('development')
46
- subject._name.should eq('Users')
47
- subject._formats.should eq(['json'])
42
+ expect(subject._short_description).to eq('Site members')
43
+ expect(subject._id).to eq('users')
44
+ expect(subject._path).to eq('/users')
45
+ expect(subject._version).to eq('development')
46
+ expect(subject._name).to eq('Users')
47
+ expect(subject._formats).to eq(['json'])
48
48
  end
49
49
 
50
50
  it "should contain params defined on resource level" do
51
- subject._params_args.count.should == 2
51
+ expect(subject._params_args.count).to eq(2)
52
52
  name, type, options = subject._params_args.first
53
- name.should == :id
54
- type.should == Fixnum
55
- options.should == {:required=>false, :desc=>"User ID"}
53
+ expect(name).to eq(:id)
54
+ expect(type).to eq(Fixnum)
55
+ expect(options).to eq({:required=>false, :desc=>"User ID"})
56
56
  end
57
57
  end
58
58
 
@@ -71,7 +71,7 @@ describe UsersController do
71
71
  end
72
72
 
73
73
  it "should pass if required parameter is missing" do
74
- lambda { get :show, :id => 5 }.should_not raise_error
74
+ expect { get :show, :id => 5 }.not_to raise_error
75
75
  end
76
76
 
77
77
  end
@@ -92,17 +92,17 @@ describe UsersController do
92
92
  end
93
93
 
94
94
  it "should reply to valid request" do
95
- lambda { get :show, :id => 5, :session => "secret_hash" }.should_not raise_error
95
+ expect { get :show, :id => 5, :session => "secret_hash" }.not_to raise_error
96
96
  assert_response :success
97
97
  end
98
98
 
99
99
  it "should fail if required parameter is missing" do
100
- lambda { get :show, :id => 5 }.should raise_error(Apipie::ParamMissing, /\bsession\b/)
100
+ expect { get :show, :id => 5 }.to raise_error(Apipie::ParamMissing, /session_parameter_is_required/)
101
101
  end
102
102
 
103
103
  it "should pass if required parameter has wrong type" do
104
- lambda { get :show, :id => 5, :session => "secret_hash" }.should_not raise_error
105
- lambda { get :show, :id => "ten", :session => "secret_hash" }.should_not raise_error
104
+ expect { get :show, :id => 5, :session => "secret_hash" }.not_to raise_error
105
+ expect { get :show, :id => "ten", :session => "secret_hash" }.not_to raise_error
106
106
  end
107
107
 
108
108
  end
@@ -115,12 +115,12 @@ describe UsersController do
115
115
  end
116
116
 
117
117
  it "should reply to valid request" do
118
- lambda { get :show, :id => 5, :session => "secret_hash" }.should_not raise_error
118
+ expect { get :show, :id => 5, :session => "secret_hash" }.not_to raise_error
119
119
  assert_response :success
120
120
  end
121
121
 
122
122
  it "should fail if extra parameter is passed in" do
123
- lambda { get :show, :id => 5, :session => "secret_hash", :badparam => 'badfoo' }.should raise_error(Apipie::UnknownParam, /\bbadparam\b/)
123
+ expect { get :show, :id => 5, :session => "secret_hash", :badparam => 'badfoo' }.to raise_error(Apipie::UnknownParam, /\bbadparam\b/)
124
124
  end
125
125
  end
126
126
 
@@ -144,15 +144,15 @@ describe UsersController do
144
144
  end
145
145
 
146
146
  it "should fail if required parameter is missing" do
147
- lambda { get :show, :id => 5 }.should raise_error(Apipie::ParamMissing, /\bsession\b/)
147
+ expect { get :show, :id => 5 }.to raise_error(Apipie::ParamMissing, /session_parameter_is_required/)
148
148
  end
149
149
 
150
150
  it "should work with custom Type validator" do
151
- lambda {
151
+ expect {
152
152
  get :show,
153
153
  :id => "not a number",
154
154
  :session => "secret_hash"
155
- }.should raise_error(Apipie::ParamError, /id/) # old-style error rather than ParamInvalid
155
+ }.to raise_error(Apipie::ParamError, /id/) # old-style error rather than ParamInvalid
156
156
  end
157
157
 
158
158
  it "should work with Regexp validator" do
@@ -162,12 +162,12 @@ describe UsersController do
162
162
  :regexp_param => "24 years"
163
163
  assert_response :success
164
164
 
165
- lambda {
165
+ expect {
166
166
  get :show,
167
167
  :id => 5,
168
168
  :session => "secret_hash",
169
169
  :regexp_param => "ten years"
170
- }.should raise_error(Apipie::ParamInvalid, /regexp_param/)
170
+ }.to raise_error(Apipie::ParamInvalid, /regexp_param/)
171
171
  end
172
172
 
173
173
  it "should work with Array validator" do
@@ -180,28 +180,28 @@ describe UsersController do
180
180
  get :show, :id => 5, :session => "secret_hash", :boolean_param => false
181
181
  assert_response :success
182
182
 
183
- lambda {
183
+ expect {
184
184
  get :show,
185
185
  :id => 5,
186
186
  :session => "secret_hash",
187
187
  :array_param => "blabla"
188
- }.should raise_error(Apipie::ParamInvalid, /array_param/)
188
+ }.to raise_error(Apipie::ParamInvalid, /array_param/)
189
189
 
190
- lambda {
190
+ expect {
191
191
  get :show,
192
192
  :id => 5,
193
193
  :session => "secret_hash",
194
194
  :array_param => 3
195
- }.should raise_error(Apipie::ParamInvalid, /array_param/)
195
+ }.to raise_error(Apipie::ParamInvalid, /array_param/)
196
196
  end
197
197
 
198
198
  it "should work with Proc validator" do
199
- lambda {
199
+ expect {
200
200
  get :show,
201
201
  :id => 5,
202
202
  :session => "secret_hash",
203
203
  :proc_param => "asdgsag"
204
- }.should raise_error(Apipie::ParamInvalid, /proc_param/)
204
+ }.to raise_error(Apipie::ParamInvalid, /proc_param/)
205
205
 
206
206
  get :show,
207
207
  :id => 5,
@@ -216,25 +216,25 @@ describe UsersController do
216
216
 
217
217
  a = Apipie[UsersController, :create]
218
218
  param = a.params_ordered.select {|p| p.name == :user }
219
- param.count.should == 1
220
- param.first.validator.class.should eq(Apipie::Validator::HashValidator)
219
+ expect(param.count).to eq(1)
220
+ expect(param.first.validator.class).to eq(Apipie::Validator::HashValidator)
221
221
  hash_params = param.first.validator.params_ordered
222
- hash_params.count.should == 4
222
+ expect(hash_params.count).to eq(4)
223
223
  hash_params[0].name == :name
224
224
  hash_params[1].name == :pass
225
225
  hash_params[2].name == :membership
226
226
 
227
- lambda {
227
+ expect {
228
228
  post :create, :user => { :name => "root", :pass => "12345", :membership => "____" }
229
- }.should raise_error(Apipie::ParamInvalid, /membership/)
229
+ }.to raise_error(Apipie::ParamInvalid, /membership/)
230
230
 
231
- lambda {
231
+ expect {
232
232
  post :create, :user => { :name => "root" }
233
- }.should raise_error(Apipie::ParamMissing, /pass/)
233
+ }.to raise_error(Apipie::ParamMissing, /pass/)
234
234
 
235
- lambda {
235
+ expect {
236
236
  post :create, :user => "a string is not a hash"
237
- }.should raise_error(Apipie::ParamInvalid, /user/)
237
+ }.to raise_error(Apipie::ParamInvalid, /user/)
238
238
 
239
239
  post :create, :user => { :name => "root", :pass => "pwd" }
240
240
  assert_response :success
@@ -242,7 +242,7 @@ describe UsersController do
242
242
 
243
243
  it "should support Hash validator without specifying keys" do
244
244
  params = Apipie[UsersController, :create].to_json[:params]
245
- params.should include(:name => "facts",
245
+ expect(params).to include(:name => "facts",
246
246
  :full_name => "facts",
247
247
  :validator => "Must be Hash",
248
248
  :description => "\n<p>Additional optional facts about the user</p>\n",
@@ -250,7 +250,8 @@ describe UsersController do
250
250
  :allow_nil => true,
251
251
  :metadata => nil,
252
252
  :show => true,
253
- :expected_type => "hash")
253
+ :expected_type => "hash",
254
+ :validations => [])
254
255
  end
255
256
 
256
257
  it "should allow nil when allow_nil is set to true" do
@@ -363,37 +364,37 @@ describe UsersController do
363
364
 
364
365
  it "should contain basic info about method" do
365
366
  a = Apipie[UsersController, :create]
366
- a.apis.count.should == 1
367
- a.formats.should eq(['json'])
367
+ expect(a.apis.count).to eq(1)
368
+ expect(a.formats).to eq(['json'])
368
369
  api = a.apis.first
369
- api.short_description.should eq("Create user")
370
- api.path.should eq("/users")
371
- api.http_method.should eq("POST")
370
+ expect(api.short_description).to eq("Create user")
371
+ expect(api.path).to eq("/users")
372
+ expect(api.http_method).to eq("POST")
372
373
 
373
374
  b = Apipie.get_method_description(UsersController, :show)
374
- b.should eq(Apipie[UsersController, :show])
375
- b.method.should eq('show')
376
- b.resource._id.should eq('users')
375
+ expect(b).to eq(Apipie[UsersController, :show])
376
+ expect(b.method).to eq('show')
377
+ expect(b.resource._id).to eq('users')
377
378
 
378
- b.apis.count.should == 1
379
- b.formats.should eq(['json', 'jsonp'])
379
+ expect(b.apis.count).to eq(1)
380
+ expect(b.formats).to eq(['json', 'jsonp'])
380
381
  api = b.apis.first
381
- api.short_description.should eq("Show user profile")
382
- api.path.should eq("/users/:id")
383
- api.http_method.should eq("GET")
384
- b.full_description.length.should be > 400
382
+ expect(api.short_description).to eq("Show user profile")
383
+ expect(api.path).to eq("/users/:id")
384
+ expect(api.http_method).to eq("GET")
385
+ expect(b.full_description.length).to be > 400
385
386
  end
386
387
 
387
388
  context "Usign routes.rb" do
388
389
  it "should contain basic info about method" do
389
390
  a = Apipie[UsersController, :create_route]
390
- a.apis.count.should == 1
391
- a.formats.should eq(['json'])
391
+ expect(a.apis.count).to eq(1)
392
+ expect(a.formats).to eq(['json'])
392
393
  api = a.apis.first
393
- api.short_description.should eq("Create user")
394
- api.path.should eq("/api/users/create_route")
395
- api.from_routes.should be_true
396
- api.http_method.should eq("POST")
394
+ expect(api.short_description).to eq("Create user")
395
+ expect(api.path).to eq("/api/users/create_route")
396
+ expect(api.from_routes).to be_truthy
397
+ expect(api.http_method).to eq("POST")
397
398
  end
398
399
  end
399
400
 
@@ -402,18 +403,18 @@ describe UsersController do
402
403
  context "the key is valid" do
403
404
  it "should contain reference to another method" do
404
405
  api = Apipie[UsersController, :see_another]
405
- api.show.should == false
406
+ expect(api.show).to be false
406
407
  see = api.see.first
407
- see.see_url.should == Apipie[UsersController, :create].doc_url
408
- see.link.should == 'development#users#create'
409
- see.description.should == 'development#users#create'
408
+ expect(see.see_url).to eql Apipie[UsersController, :create].doc_url
409
+ expect(see.link).to eql 'development#users#create'
410
+ expect(see.description).to eql 'development#users#create'
410
411
 
411
412
  see_with_desc = api.see.last
412
- see_with_desc.see_url.should == Apipie[UsersController, :index].doc_url
413
- see_with_desc.link.should == 'development#users#index'
414
- see_with_desc.description.should == 'very interesting method reference'
413
+ expect(see_with_desc.see_url).to eql Apipie[UsersController, :index].doc_url
414
+ expect(see_with_desc.link).to eql 'development#users#index'
415
+ expect(see_with_desc.description).to eql 'very interesting method reference'
415
416
 
416
- Apipie['development#users#see_another'].should eq(Apipie[UsersController, :see_another])
417
+ expect(Apipie['development#users#see_another']).to eql Apipie[UsersController, :see_another]
417
418
  end
418
419
  end
419
420
 
@@ -421,9 +422,9 @@ describe UsersController do
421
422
  it "should raise exception" do
422
423
  api = Apipie[UsersController, :see_another]
423
424
  api.instance_variable_set :@see, [Apipie::SeeDescription.new(['doesnot#exist'])]
424
- lambda {
425
+ expect {
425
426
  api.see.first.see_url
426
- }.should raise_error(ArgumentError, /does not exist/)
427
+ }.to raise_error(ArgumentError, /does not exist/)
427
428
  api.instance_variable_set :@see, []
428
429
  end
429
430
  end
@@ -432,18 +433,18 @@ describe UsersController do
432
433
  it "should contain possible errors description" do
433
434
  a = Apipie.get_method_description(UsersController, :show)
434
435
 
435
- a.errors[0].code.should eq(500)
436
- a.errors[0].description.should include("crashed")
437
- a.errors[1].code.should eq(401)
438
- a.errors[1].description.should eq("Unauthorized")
439
- a.errors[2].code.should eq(404)
440
- a.errors[2].description.should eq("Not Found")
436
+ expect(a.errors[0].code).to eq(500)
437
+ expect(a.errors[0].description).to include("crashed")
438
+ expect(a.errors[1].code).to eq(401)
439
+ expect(a.errors[1].description).to eq("Unauthorized")
440
+ expect(a.errors[2].code).to eq(404)
441
+ expect(a.errors[2].description).to eq("Not Found")
441
442
  end
442
443
 
443
444
  it "should contain all params description" do
444
445
  a = Apipie.get_method_description(UsersController, :show)
445
- a.params.count.should == 11
446
- a.instance_variable_get('@params_ordered').count.should == 9
446
+ expect(a.params.count).to eq(12)
447
+ expect(a.instance_variable_get('@params_ordered').count).to eq(10)
447
448
  end
448
449
 
449
450
  context 'headers' do
@@ -470,7 +471,7 @@ describe UsersController do
470
471
 
471
472
  it 'contains all headers description in method doc' do
472
473
  headers = Apipie.get_method_description(UsersController, :action_with_headers).headers
473
- headers.should be_an(Array)
474
+ expect(headers).to be_an(Array)
474
475
 
475
476
  compare_hashes headers[0], expected_required_header
476
477
  compare_hashes headers[1], expected_optional_header
@@ -490,7 +491,7 @@ describe UsersController do
490
491
 
491
492
  it 'contains all headers description in resource doc' do
492
493
  headers = Apipie.get_resource_description(UsersController)._headers
493
- headers.should be_an(Array)
494
+ expect(headers).to be_an(Array)
494
495
 
495
496
  compare_hashes headers[0], expected_resource_header
496
497
  end
@@ -499,17 +500,17 @@ describe UsersController do
499
500
 
500
501
  it "should contain all api method description" do
501
502
  method_description = Apipie[UsersController, :two_urls]
502
- method_description.class.should be(Apipie::MethodDescription)
503
- method_description.apis.count.should == 2
503
+ expect(method_description.class).to be(Apipie::MethodDescription)
504
+ expect(method_description.apis.count).to eq(2)
504
505
  a1, a2 = method_description.apis
505
506
 
506
- a1.short_description.should eq('Get company users')
507
- a1.path.should eq('/company_users')
508
- a1.http_method.should eq('GET')
507
+ expect(a1.short_description).to eq('Get company users')
508
+ expect(a1.path).to eq('/company_users')
509
+ expect(a1.http_method).to eq('GET')
509
510
 
510
- a2.short_description.should eq('Get users working in given company')
511
- a2.path.should eq('/company/:id/users')
512
- a2.http_method.should eq('GET')
511
+ expect(a2.short_description).to eq('Get users working in given company')
512
+ expect(a2.path).to eq('/company/:id/users')
513
+ expect(a2.http_method).to eq('GET')
513
514
  end
514
515
 
515
516
  it "should be described by valid json" do
@@ -594,7 +595,7 @@ describe UsersController do
594
595
  describe "examples" do
595
596
 
596
597
  it "should be able to load examples from yml file" do
597
- Apipie.get_method_description(UsersController, :show).examples.should == [<<EOS1, <<EOS2].map(&:chomp)
598
+ expect(Apipie.get_method_description(UsersController, :show).examples).to eq [<<EOS1, <<EOS2].map(&:chomp)
598
599
  GET /users/14?verbose=true
599
600
  200
600
601
  {
@@ -608,7 +609,7 @@ EOS2
608
609
 
609
610
  describe "document" do
610
611
  it "should be able to load document from markup file" do
611
- Apipie.get_method_description(UsersController, :desc_from_file).full_description.should include("description from document")
612
+ expect(Apipie.get_method_description(UsersController, :desc_from_file).full_description).to include("description from document")
612
613
  end
613
614
  end
614
615
  end
@@ -619,37 +620,35 @@ EOS2
619
620
  a = Apipie.get_method_description(UsersController, :show)
620
621
 
621
622
  param = a.params[:session]
622
- param.required.should eq(true)
623
- param.desc.should eq("\n<p>user is logged in</p>\n")
624
- param.validator.class.should be(Apipie::Validator::TypeValidator)
625
- param.validator.instance_variable_get("@type").should eq(String)
623
+ expect(param.required).to eq(true)
624
+ expect(param.desc).to eq("\n<p>user is logged in</p>\n")
625
+ expect(param.validator.class).to be(Apipie::Validator::TypeValidator)
626
+ expect(param.validator.instance_variable_get("@type")).to eq(String)
626
627
 
627
628
  param = a.params[:id]
628
- param.required.should eq(true)
629
- param.desc.should eq("\n<p>user id</p>\n")
630
- param.validator.class.should be(Apipie::Validator::IntegerValidator)
631
- param.validator.instance_variable_get("@type").should eq(Integer)
629
+ expect(param.required).to eq(true)
630
+ expect(param.desc).to eq("\n<p>user id</p>\n")
631
+ expect(param.validator.class).to be(Apipie::Validator::IntegerValidator)
632
+ expect(param.validator.instance_variable_get("@type")).to eq(Integer)
632
633
 
633
634
  param = a.params[:regexp_param]
634
- param.desc.should eq("\n<p>regexp param</p>\n")
635
- param.required.should eq(false)
636
- param.validator.class.should be(Apipie::Validator::RegexpValidator)
637
- param.validator.instance_variable_get("@regexp").should
638
- eq(/^[0-9]* years/)
635
+ expect(param.desc).to eq("\n<p>regexp param</p>\n")
636
+ expect(param.required).to eq(false)
637
+ expect(param.validator.class).to be(Apipie::Validator::RegexpValidator)
638
+ expect(param.validator.instance_variable_get("@regexp")).to eq(/^[0-9]* years/)
639
639
 
640
640
  param = a.params[:array_param]
641
- param.desc.should eq("\n<p>array validator</p>\n")
642
- param.validator.class.should be(Apipie::Validator::EnumValidator)
643
- param.validator.instance_variable_get("@array").should
644
- eq([100, "one", "two", 1, 2])
641
+ expect(param.desc).to eq("\n<p>array validator</p>\n")
642
+ expect(param.validator.class).to be(Apipie::Validator::EnumValidator)
643
+ expect(param.validator.instance_variable_get("@array")).to eq(["100", "one", "two", "1", "2"])
645
644
 
646
645
  param = a.params[:proc_param]
647
- param.desc.should eq("\n<p>proc validator</p>\n")
648
- param.validator.class.should be(Apipie::Validator::ProcValidator)
646
+ expect(param.desc).to eq("\n<p>proc validator</p>\n")
647
+ expect(param.validator.class).to be(Apipie::Validator::ProcValidator)
649
648
 
650
649
  param = a.params[:briefer_dsl]
651
- param.desc.should eq("\n<p>You dont need :desc =&gt; from now</p>\n")
652
- param.validator.class.should be(Apipie::Validator::TypeValidator)
650
+ expect(param.desc).to eq("\n<p>You dont need :desc =&gt; from now</p>\n")
651
+ expect(param.validator.class).to be(Apipie::Validator::TypeValidator)
653
652
  end
654
653
 
655
654
  end
@@ -668,10 +667,10 @@ EOS2
668
667
 
669
668
  it "skips the listed actions from the documentation" do
670
669
  Apipie.define_method_description(UsersController, :ignore, dsl_data)
671
- Apipie.get_method_description(UsersController, :ignore).should be_nil
670
+ expect(Apipie.get_method_description(UsersController, :ignore)).to be_nil
672
671
 
673
672
  Apipie.define_method_description(UsersController, :dont_ignore, dsl_data)
674
- Apipie.get_method_description(UsersController, :dont_ignore).should_not be_nil
673
+ expect(Apipie.get_method_description(UsersController, :dont_ignore)).not_to be_nil
675
674
  end
676
675
  end
677
676
 
@@ -682,9 +681,9 @@ EOS2
682
681
 
683
682
  it "skips the listed controller from the documentation" do
684
683
  Apipie.define_method_description(IgnoredController, :ignore, dsl_data)
685
- Apipie.get_method_description(IgnoredController, :ignore).should be_nil
684
+ expect(Apipie.get_method_description(IgnoredController, :ignore)).to be_nil
686
685
  Apipie.define_method_description(IgnoredController, :ignore, dsl_data)
687
- Apipie.get_method_description(IgnoredController, :ignore).should be_nil
686
+ expect(Apipie.get_method_description(IgnoredController, :ignore)).to be_nil
688
687
  end
689
688
  end
690
689
  end