rapidoc 0.0.4

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 (96) hide show
  1. data/.gitignore +21 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +20 -0
  4. data/README.rdoc +152 -0
  5. data/Rakefile +1 -0
  6. data/lib/rapidoc.rb +62 -0
  7. data/lib/rapidoc/action_doc.rb +86 -0
  8. data/lib/rapidoc/config.rb +127 -0
  9. data/lib/rapidoc/config/rapidoc.yml +4 -0
  10. data/lib/rapidoc/controller_extractor.rb +54 -0
  11. data/lib/rapidoc/http_response.rb +61 -0
  12. data/lib/rapidoc/param_errors.rb +43 -0
  13. data/lib/rapidoc/resource_doc.rb +66 -0
  14. data/lib/rapidoc/resources_extractor.rb +42 -0
  15. data/lib/rapidoc/routes_doc.rb +96 -0
  16. data/lib/rapidoc/templates/action.html.hbs +170 -0
  17. data/lib/rapidoc/templates/assets/css/bootstrap-responsive.min.css +9 -0
  18. data/lib/rapidoc/templates/assets/css/bootstrap.min.css +9 -0
  19. data/lib/rapidoc/templates/assets/css/rapidoc.css +43 -0
  20. data/lib/rapidoc/templates/assets/img/glyphicons-halflings.png +0 -0
  21. data/lib/rapidoc/templates/assets/js/bootstrap.min.js +6 -0
  22. data/lib/rapidoc/templates/assets/js/jquery-1.9.0.min.js +4 -0
  23. data/lib/rapidoc/templates/assets/js/json2.js +486 -0
  24. data/lib/rapidoc/templates/index.html.hbs +85 -0
  25. data/lib/rapidoc/templates_generator.rb +65 -0
  26. data/lib/rapidoc/version.rb +3 -0
  27. data/lib/rapidoc/yaml_parser.rb +49 -0
  28. data/lib/tasks/railtie.rb +7 -0
  29. data/lib/tasks/rapidoc.rake +18 -0
  30. data/rapidoc.gemspec +26 -0
  31. data/spec/dummy/.gitignore +15 -0
  32. data/spec/dummy/Gemfile +42 -0
  33. data/spec/dummy/README.rdoc +261 -0
  34. data/spec/dummy/Rakefile +7 -0
  35. data/spec/dummy/app/assets/images/rails.png +0 -0
  36. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  37. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  38. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  39. data/spec/dummy/app/controllers/users_controller.rb +114 -0
  40. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  41. data/spec/dummy/app/mailers/.gitkeep +0 -0
  42. data/spec/dummy/app/models/.gitkeep +0 -0
  43. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  44. data/spec/dummy/config.ru +4 -0
  45. data/spec/dummy/config/application.rb +62 -0
  46. data/spec/dummy/config/boot.rb +6 -0
  47. data/spec/dummy/config/database.yml +25 -0
  48. data/spec/dummy/config/environment.rb +5 -0
  49. data/spec/dummy/config/environments/development.rb +37 -0
  50. data/spec/dummy/config/environments/production.rb +67 -0
  51. data/spec/dummy/config/environments/test.rb +37 -0
  52. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  53. data/spec/dummy/config/initializers/inflections.rb +15 -0
  54. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  55. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  56. data/spec/dummy/config/initializers/session_store.rb +8 -0
  57. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  58. data/spec/dummy/config/locales/en.yml +5 -0
  59. data/spec/dummy/config/routes.rb +9 -0
  60. data/spec/dummy/db/seeds.rb +7 -0
  61. data/spec/dummy/lib/assets/.gitkeep +0 -0
  62. data/spec/dummy/lib/tasks/.gitkeep +0 -0
  63. data/spec/dummy/log/.gitkeep +0 -0
  64. data/spec/dummy/public/404.html +26 -0
  65. data/spec/dummy/public/422.html +26 -0
  66. data/spec/dummy/public/500.html +25 -0
  67. data/spec/dummy/public/favicon.ico +0 -0
  68. data/spec/dummy/public/index.html +241 -0
  69. data/spec/dummy/public/robots.txt +5 -0
  70. data/spec/dummy/salida/users_create_response.json +12 -0
  71. data/spec/dummy/script/rails +6 -0
  72. data/spec/dummy/test/fixtures/.gitkeep +0 -0
  73. data/spec/dummy/test/functional/.gitkeep +0 -0
  74. data/spec/dummy/test/integration/.gitkeep +0 -0
  75. data/spec/dummy/test/performance/browsing_test.rb +12 -0
  76. data/spec/dummy/test/test_helper.rb +13 -0
  77. data/spec/dummy/test/unit/.gitkeep +0 -0
  78. data/spec/dummy/vendor/assets/javascripts/.gitkeep +0 -0
  79. data/spec/dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  80. data/spec/dummy/vendor/plugins/.gitkeep +0 -0
  81. data/spec/features/action_spec.rb +212 -0
  82. data/spec/features/index_spec.rb +64 -0
  83. data/spec/lib/action_doc_spec.rb +202 -0
  84. data/spec/lib/config_spec.rb +186 -0
  85. data/spec/lib/controller_extractor_spec.rb +77 -0
  86. data/spec/lib/http_response_spec.rb +63 -0
  87. data/spec/lib/param_errors_spec.rb +69 -0
  88. data/spec/lib/rake_spec.rb +25 -0
  89. data/spec/lib/rapidoc_spec.rb +39 -0
  90. data/spec/lib/resource_doc_spec.rb +131 -0
  91. data/spec/lib/resources_extractor_spec.rb +105 -0
  92. data/spec/lib/routes_doc_spec.rb +150 -0
  93. data/spec/lib/templates_generator_spec.rb +90 -0
  94. data/spec/lib/yard_parser_spec.rb +55 -0
  95. data/spec/spec_helper.rb +10 -0
  96. metadata +307 -0
@@ -0,0 +1,186 @@
1
+ require "spec_helper"
2
+
3
+ include Rapidoc
4
+
5
+ describe Rapidoc::Config do
6
+ before :all do
7
+ reset_structure
8
+ end
9
+
10
+ it "config_dir returns correct dir" do
11
+ config_dir().should eql( ::Rails.root.to_s + '/config/rapidoc' )
12
+ end
13
+
14
+ it "config_dir returns correct dir + file" do
15
+ config_dir('file.yml').should eql( ::Rails.root.to_s + '/config/rapidoc/file.yml' )
16
+ end
17
+
18
+ it "gem_templates_dir returns correct dir" do
19
+ gem_templates_dir().should =~ /(.*)\/lib\/rapidoc\/templates/
20
+ end
21
+
22
+ it "gem_templates_dir returns correct dir + file" do
23
+ gem_templates_dir('template.hbs').should =~ /(.*)\/templates\/template\.hbs/
24
+ end
25
+
26
+ context "when call controller_dir" do
27
+ context "when use default route" do
28
+ it "controller_dir returns correct dir" do
29
+ controller_dir().should eql( ::Rails.root.to_s + '/app/controllers' )
30
+ end
31
+
32
+ it "controller_dir returns correct dir + file" do
33
+ controller_dir('file.rb').should eql( ::Rails.root.to_s + '/app/controllers/file.rb' )
34
+ end
35
+ end
36
+
37
+ context "when use config route" do
38
+ it "controller_dir returns correct dir" do
39
+ File.open( config_file_path, 'w') { |file| file.write "controllers_route: \"vim\"" }
40
+ load_config
41
+ controller_dir().should eql( ::Rails.root.to_s + '/vim' )
42
+ end
43
+ end
44
+ end
45
+
46
+ context "when call target_dir" do
47
+ context "when config file has a route" do
48
+ before do
49
+ File.open( config_file_path, 'w') { |file| file.write "doc_route: \"vim\"" }
50
+ load_config
51
+ end
52
+
53
+ it "returns correct route" do
54
+ target_dir.should == ::Rails.root.to_s + "/vim"
55
+ end
56
+ end
57
+
58
+ context "when config file hasn't a route" do
59
+ before do
60
+ File.open("#{config_dir}/rapidoc.yml", 'w') { |file| file.write "" }
61
+ load_config
62
+ end
63
+
64
+ it "returns default route" do
65
+ target_dir.should == ::Rails.root.to_s + "/rapidoc"
66
+ end
67
+ end
68
+
69
+ context "when pass file name" do
70
+ it "returns correct dir + file" do
71
+ target_dir('file.html').should eql( target_dir + '/file.html' )
72
+ end
73
+ end
74
+ end
75
+
76
+ context "when call default_errors" do
77
+ before :all do
78
+ File.open( config_file_path, 'w') { |file| file.write "default_errors: true" }
79
+ load_config
80
+ end
81
+
82
+ context "when action is index" do
83
+ it "returns false" do
84
+ default_errors?( 'index' ).should == false
85
+ end
86
+ end
87
+
88
+ context "when action is create" do
89
+ it "returns true" do
90
+ default_errors?( 'create' ).should == true
91
+ end
92
+ end
93
+ end
94
+
95
+ context "when call default_response_formats" do
96
+ context "when config file has not response_formats" do
97
+ it "returns nil" do
98
+ default_response_formats.should == nil
99
+ end
100
+ end
101
+
102
+ context "when config file has response_formats" do
103
+ it "returns response formats" do
104
+ File.open( config_file_path, 'w') { |file| file.write "response_formats: json" }
105
+ load_config
106
+ default_response_formats.should == 'json'
107
+ end
108
+ end
109
+ end
110
+
111
+ context "when call actions_dir" do
112
+ context "when config file has a route" do
113
+ before do
114
+ File.open( config_file_path, 'w') { |file| file.write "doc_route: \"vim\"" }
115
+ load_config
116
+ end
117
+
118
+ it "returns correct route" do
119
+ actions_dir.should == ::Rails.root.to_s + "/vim/actions"
120
+ end
121
+ end
122
+
123
+ context "when config file hasn't a route" do
124
+ before do
125
+ File.open("#{config_dir}/rapidoc.yml", 'w') { |file| file.write "" }
126
+ load_config
127
+ end
128
+
129
+ it "returns default route" do
130
+ actions_dir.should == ::Rails.root.to_s + "/rapidoc/actions"
131
+ end
132
+ end
133
+
134
+ context "when pass file name" do
135
+ it "returns correct dir + file" do
136
+ actions_dir('file.html').should eql( actions_dir + '/file.html' )
137
+ end
138
+ end
139
+ end
140
+
141
+ context "when call examples_dir" do
142
+ context "when config file has an example dir" do
143
+ before do
144
+ File.open( "#{config_dir}/rapidoc.yml", 'w' ) do |file|
145
+ file.write "examples_route: \"vim\""
146
+ end
147
+
148
+ load_config
149
+ end
150
+
151
+ it "examples_dir returns correct route" do
152
+ examples_dir.should == ::Rails.root.to_s + "/vim"
153
+ end
154
+ end
155
+ context "when config file hasn't an example dir" do
156
+ before do
157
+ File.open("#{config_dir}/rapidoc.yml", 'w') { |file| file.write "" }
158
+ load_config
159
+ end
160
+
161
+ it "examples_dir returns default examples dir route" do
162
+ examples_dir.should == "#{config_dir}/examples"
163
+ end
164
+ end
165
+ end
166
+
167
+ context "when call resources_black_list" do
168
+ context "when config file has resources_black_list" do
169
+ it "returns array with resources" do
170
+ File.open("#{config_dir}/rapidoc.yml", 'w') do |file|
171
+ file.write "resources_black_list: images, albums"
172
+ end
173
+ load_config
174
+ resources_black_list.should == [ :images, :albums ]
175
+ end
176
+ end
177
+
178
+ context "when config file has not resources_black_list" do
179
+ it "returns empty array" do
180
+ File.open("#{config_dir}/rapidoc.yml", 'w') { |file| file.write "" }
181
+ load_config
182
+ resources_black_list.should == []
183
+ end
184
+ end
185
+ end
186
+ end
@@ -0,0 +1,77 @@
1
+ require "spec_helper"
2
+
3
+ include Rapidoc
4
+
5
+ describe ControllerExtractor do
6
+
7
+ context "when create instance with valid controller file" do
8
+ before :all do
9
+ @extractor = ControllerExtractor.new "users_controller.rb"
10
+ end
11
+
12
+ context
13
+
14
+ context "when call get_actions_info function" do
15
+ before :all do
16
+ @info = @extractor.get_actions_info
17
+ end
18
+
19
+ it "should return info about all commented actions" do
20
+ actions = @info.map{ |info| info["action"] }
21
+ actions.should be_include( 'index' )
22
+ actions.should be_include( 'show' )
23
+ actions.should be_include( 'create' )
24
+ end
25
+ end
26
+
27
+ context "when call get_action_info " do
28
+ before :all do
29
+ @info = @extractor.get_action_info( "index" )
30
+ end
31
+
32
+ it "returns the correct action" do
33
+ @info['action'].should == "index"
34
+ end
35
+
36
+ it "should return all mandatary fields" do
37
+ @info.keys.should be_include( 'http_responses' )
38
+ @info.keys.should be_include( 'action' )
39
+ @info.keys.should be_include( 'method' )
40
+ @info.keys.should be_include( 'authentication_required' )
41
+ @info.keys.should be_include( 'response_formats' )
42
+ @info.keys.should be_include( 'description' )
43
+ end
44
+ end
45
+
46
+ context "when call get_resource_info" do
47
+ before :all do
48
+ @info = @extractor.get_resource_info
49
+ end
50
+
51
+ it "controller info contatins resource description" do
52
+ @info.keys.should be_include( 'description' )
53
+ end
54
+ end
55
+
56
+ context "when call get_controller_info" do
57
+ before :all do
58
+ @info = @extractor.get_controller_info
59
+ end
60
+
61
+ it "returns resource description" do
62
+ @info.keys.should be_include( 'description' )
63
+ end
64
+
65
+ it "returns resource actions info" do
66
+ @info.keys.should be_include( 'actions' )
67
+ end
68
+ end
69
+ end
70
+
71
+ context "when create new instance with invalid controller file" do
72
+ it "throw exception" do
73
+ lambda{ ControllerExtractor.new( "no_file" ) }.should raise_error
74
+ end
75
+ end
76
+ end
77
+
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ include Rapidoc
4
+
5
+ describe "When check HttpResponse class" do
6
+
7
+ context "when create new instance" do
8
+ before :all do
9
+ @http_response = HttpResponse.new 200
10
+ end
11
+
12
+ it "should set correct code" do
13
+ @http_response.code.should == 200
14
+ end
15
+
16
+ it "should set correct label" do
17
+ @http_response.label.should == 'label label-info'
18
+ end
19
+
20
+ it "should set correct description" do
21
+ @http_response.description.should == "OK"
22
+ end
23
+ end
24
+
25
+ context "when check get_description function" do
26
+ before do
27
+ @codes = [ 200, 201, 401, 404, 422, 403, 409 ]
28
+ @descriptions = [ 'OK', 'Created', 'Unauthorized', 'Not found',
29
+ 'Unprocessable Entity', 'Forbidden', '' ]
30
+ end
31
+
32
+ it "should return correct descriptions" do
33
+ @codes.each_index do |i|
34
+ http_response = HttpResponse.new @codes[i]
35
+ http_response.get_description.should == @descriptions[i]
36
+ end
37
+ end
38
+ end
39
+
40
+ context "when call get_label function" do
41
+ context "when pass know code" do
42
+ before do
43
+ @codes = [ 200, 201, 204, 401, 403, 422, 404 ]
44
+ @labels = [ 'label-info', 'label-success', 'label-info2', 'label-warning',
45
+ 'label-warning2', 'label-important', 'label-inverse' ]
46
+ end
47
+
48
+ it "should return correct labels" do
49
+ @codes.each_index do |i|
50
+ http_response = HttpResponse.new @codes[i]
51
+ http_response.get_label.should == 'label ' + @labels[i]
52
+ end
53
+ end
54
+ end
55
+
56
+ context "when pass unknow code" do
57
+ it "should return correct label" do
58
+ http_response = HttpResponse.new 400
59
+ http_response.get_label.should == 'label'
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ include Rapidoc
4
+
5
+ describe ParamErrors do
6
+ context "when use default messages and descriptions"do
7
+ context "when call get_required_error_info" do
8
+ it "return correct error info" do
9
+ info = get_required_error_info( 'name' )
10
+ info['object'].should == 'name'
11
+ info['message'].should == 'blank'
12
+ info['description'].should == 'This parameter is mandatory'
13
+ end
14
+ end
15
+
16
+ context "when call get_inclusion_error_info" do
17
+ it "return correct error info" do
18
+ info = get_inclusion_error_info( 'name' )
19
+ info['object'].should == 'name'
20
+ info['message'].should == 'inclusion'
21
+ info['description'].should == 'This parameter is not in the collection'
22
+ end
23
+ end
24
+
25
+ context "when call get_error_info" do
26
+ it "return correct error info" do
27
+ get_error_info( 'name', 'required' ).should == get_required_error_info( 'name' )
28
+ end
29
+ end
30
+ end
31
+
32
+ context "when use config messaes and descriptions" do
33
+ before :all do
34
+
35
+ File.open( config_file_path, 'w') do |file|
36
+ file.write "default_errors: true\n"
37
+ file.write "errors:\n"
38
+ file.write " required:\n message: \"m1\"\n description: \"d1\"\n"
39
+ file.write " inclusion:\n message: \"m2\"\n description: \"d2\"\n"
40
+ end
41
+
42
+ load_config
43
+ end
44
+
45
+ context "when call get_required_error_info" do
46
+ it "return correct error info" do
47
+ info = get_required_error_info( 'name' )
48
+ info['object'].should == 'name'
49
+ info['message'].should == 'm1'
50
+ info['description'].should == 'd1'
51
+ end
52
+ end
53
+
54
+ context "when call get_inclusion_error_info" do
55
+ it "return correct error info" do
56
+ info = get_inclusion_error_info( 'name' )
57
+ info['object'].should == 'name'
58
+ info['message'].should == 'm2'
59
+ info['description'].should == 'd2'
60
+ end
61
+ end
62
+
63
+ context "when call get_error_info" do
64
+ it "return correct error info" do
65
+ get_error_info( 'name', 'required' ).should == get_required_error_info( 'name' )
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+ require 'rake'
3
+
4
+ describe Rake do
5
+ context 'rapidoc:generate' do
6
+ before do
7
+ Rake.application.rake_require "tasks/rapidoc"
8
+ Rake::Task.define_task(:environment)
9
+ end
10
+
11
+ after do
12
+ remove_doc
13
+ end
14
+
15
+ let :run_rake_task do
16
+ Rake::Task["rapidoc:generate"].reenable
17
+ Rake.application.invoke_task "rapidoc:generate"
18
+ end
19
+
20
+ it "should create documentation" do
21
+ run_rake_task
22
+ File.exists?( ::Rails.root.to_s + "/rapidoc/index.html" ).should == true
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,39 @@
1
+ require "spec_helper"
2
+
3
+ include Rapidoc
4
+
5
+ describe Rapidoc do
6
+
7
+ before :all do
8
+ create_structure
9
+ load_config
10
+ end
11
+
12
+ after :all do
13
+ remove_doc
14
+ end
15
+
16
+ context "when create estructure" do
17
+ it "should create config files" do
18
+ File.exists?( config_dir( "rapidoc.yml" ) ).should == true
19
+ end
20
+
21
+ it "should create target dir" do
22
+ File.directory?( target_dir ).should == true
23
+ end
24
+
25
+ it "should create example dir" do
26
+ File.directory?( examples_dir ).should == true
27
+ end
28
+ end
29
+
30
+ context "when executing genarate_doc function" do
31
+ before do
32
+ generate_doc
33
+ end
34
+
35
+ it "should create new index.html file" do
36
+ File.exists?( ::Rails.root.to_s + "/rapidoc/index.html" ).should == true
37
+ end
38
+ end
39
+ end