mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-22 22:06:43 +00:00
Add spec generator test
This commit is contained in:
parent
189a7ef061
commit
4d29e09010
@ -6,7 +6,7 @@ RSpec.describe '<%= controller_path %>', type: :request do
|
||||
<% unless path_item[:params].empty? -%>
|
||||
# You'll want to customize the parameter types...
|
||||
<% path_item[:params].each do |param| -%>
|
||||
parameter '<%= param %>', in: :body, type: :string
|
||||
parameter name: '<%= param %>', in: :path, type: :string, description: '<%= param %>'
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
<% path_item[:actions].each do | action, details | %>
|
||||
|
||||
44
rswag-specs/spec/generators/rspec/swagger_generator_spec.rb
Normal file
44
rswag-specs/spec/generators/rspec/swagger_generator_spec.rb
Normal file
@ -0,0 +1,44 @@
|
||||
require 'generator_spec'
|
||||
require 'generators/rspec/swagger_generator'
|
||||
require 'tmpdir'
|
||||
|
||||
module Rspec
|
||||
describe SwaggerGenerator do
|
||||
include GeneratorSpec::TestCase
|
||||
destination Dir.mktmpdir
|
||||
|
||||
before(:all) do
|
||||
prepare_destination
|
||||
fixtures_dir = File.expand_path('../fixtures', __FILE__)
|
||||
FileUtils.cp_r("#{fixtures_dir}/spec", destination_root)
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
|
||||
end
|
||||
|
||||
it 'installs the swagger_helper for rspec' do
|
||||
allow_any_instance_of(Rswag::RouteParser).to receive(:routes).and_return(fake_routes)
|
||||
run_generator ['Posts::CommentsController']
|
||||
|
||||
assert_file('spec/requests/posts/comments_spec.rb') do |content|
|
||||
assert_match(/parameter name: 'post_id', in: :path, type: :string/, content)
|
||||
assert_match(/patch\('update_comments comment'\)/, content)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def fake_routes
|
||||
{
|
||||
"/posts/{post_id}/comments/{id}" => {
|
||||
:params => ["post_id", "id"],
|
||||
:actions => {
|
||||
"get" => { :summary=>"show comment" },
|
||||
"patch" => { :summary=>"update_comments comment" }
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user