diff --git a/lib/rspec_api_documentation/writers/json_writer.rb b/lib/rspec_api_documentation/writers/json_writer.rb index e9b9db96..6c956083 100644 --- a/lib/rspec_api_documentation/writers/json_writer.rb +++ b/lib/rspec_api_documentation/writers/json_writer.rb @@ -74,7 +74,7 @@ def respond_to?(method, include_private = false) end def dirname - resource_name.to_s.downcase.gsub(/\s+/, '_') + resource_name.to_s.downcase.gsub(/\s+/, '_').sub(/^\//,'') end def filename diff --git a/spec/writers/json_example_spec.rb b/spec/writers/json_example_spec.rb index c3add357..edcf1f68 100644 --- a/spec/writers/json_example_spec.rb +++ b/spec/writers/json_example_spec.rb @@ -4,6 +4,26 @@ describe RspecApiDocumentation::Writers::JsonExample do let(:configuration) { RspecApiDocumentation::Configuration.new } + describe "#dirname" do + it "strips out leading slashes" do + example = double(resource_name: "/test_string") + + json_example = + RspecApiDocumentation::Writers::JsonExample.new(example, configuration) + + expect(json_example.dirname).to eq "test_string" + end + + it "does not strip out non-leading slashes" do + example = double(resource_name: "test_string/test") + + json_example = + RspecApiDocumentation::Writers::JsonExample.new(example, configuration) + + expect(json_example.dirname).to eq "test_string/test" + end + end + describe '#filename' do specify 'Hello!/ 世界' do |example| expect(described_class.new(example, configuration).filename).to eq("hello!_世界.json")