Skip to content

Commit

Permalink
Merge pull request #191 from jessieay/master
Browse files Browse the repository at this point in the history
Remove leading slashes from dirname
  • Loading branch information
oestrich committed Jan 17, 2015
2 parents dc861da + 601b6c8 commit 93c88c5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rspec_api_documentation/writers/json_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions spec/writers/json_example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 93c88c5

Please sign in to comment.