Skip to content

Commit

Permalink
Supports non ascii characters in example description and resource name
Browse files Browse the repository at this point in the history
  • Loading branch information
hanachin committed Jun 11, 2014
1 parent e8cbdac commit 7b3437a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/rspec_api_documentation/views/markup_example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def respond_to?(method, include_private = false)
end

def dirname
resource_name.downcase.gsub(/[^0-9a-z.\-]+/, '_')
resource_name.downcase.gsub(/\s+/, '_')
end

def filename
basename = description.downcase.gsub(/\s+/, '_').gsub(/[^a-z_]/, '')
basename = description.downcase.gsub(/\s+/, '_').gsub(Pathname::SEPARATOR_PAT, '')
basename = Digest::MD5.new.update(description).to_s if basename.blank?
"#{basename}.#{extension}"
end
Expand Down
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 @@ -78,7 +78,7 @@ def dirname
end

def filename
basename = description.downcase.gsub(/\s+/, '_').gsub(/[^a-z_]/, '')
basename = description.downcase.gsub(/\s+/, '_').gsub(Pathname::SEPARATOR_PAT, '')
"#{basename}.json"
end

Expand Down
5 changes: 2 additions & 3 deletions spec/views/html_example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
end

describe "multi charctor example name" do
let(:label) { "コーヒーが順番で並んでいること" }
let(:label) { "Coffee / Teaが順番で並んでいること" }
let(:example) { group.example(label) {} }

it "should have downcased filename" do
filename = Digest::MD5.new.update(label).to_s
expect(html_example.filename).to eq(filename + ".html")
expect(html_example.filename).to eq("coffee__teaが順番で並んでいること.html")
end
end
end
12 changes: 12 additions & 0 deletions spec/writers/json_example_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
require 'spec_helper'

describe RspecApiDocumentation::Writers::JsonExample do
let(:configuration) { RspecApiDocumentation::Configuration.new }

describe '#filename' do
specify 'Hello!/ 世界' do |example|
expect(described_class.new(example, configuration).filename).to eq("hello!_世界.json")
end
end
end

0 comments on commit 7b3437a

Please sign in to comment.