From 7b3437a09bfcc746a5edd81174d7f3a698599999 Mon Sep 17 00:00:00 2001 From: Seiei Higa Date: Thu, 12 Jun 2014 00:43:56 +0900 Subject: [PATCH] Supports non ascii characters in example description and resource name --- lib/rspec_api_documentation/views/markup_example.rb | 4 ++-- lib/rspec_api_documentation/writers/json_writer.rb | 2 +- spec/views/html_example_spec.rb | 5 ++--- spec/writers/json_example_spec.rb | 12 ++++++++++++ 4 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 spec/writers/json_example_spec.rb diff --git a/lib/rspec_api_documentation/views/markup_example.rb b/lib/rspec_api_documentation/views/markup_example.rb index 40d3236a..3548e98f 100644 --- a/lib/rspec_api_documentation/views/markup_example.rb +++ b/lib/rspec_api_documentation/views/markup_example.rb @@ -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 diff --git a/lib/rspec_api_documentation/writers/json_writer.rb b/lib/rspec_api_documentation/writers/json_writer.rb index 2b7db626..2621f7cb 100644 --- a/lib/rspec_api_documentation/writers/json_writer.rb +++ b/lib/rspec_api_documentation/writers/json_writer.rb @@ -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 diff --git a/spec/views/html_example_spec.rb b/spec/views/html_example_spec.rb index 804101de..29962b8e 100644 --- a/spec/views/html_example_spec.rb +++ b/spec/views/html_example_spec.rb @@ -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 diff --git a/spec/writers/json_example_spec.rb b/spec/writers/json_example_spec.rb new file mode 100644 index 00000000..c3add357 --- /dev/null +++ b/spec/writers/json_example_spec.rb @@ -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