From 8296db925530934a8f2c9a2d88600848993bf454 Mon Sep 17 00:00:00 2001 From: Akihiro Matsumura Date: Mon, 9 Jul 2012 16:09:22 +0900 Subject: [PATCH 1/2] Support multibyte description --- lib/rspec_api_documentation/html_writer.rb | 1 + spec/html_writer_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/rspec_api_documentation/html_writer.rb b/lib/rspec_api_documentation/html_writer.rb index 818f7cae..a66bbdcc 100644 --- a/lib/rspec_api_documentation/html_writer.rb +++ b/lib/rspec_api_documentation/html_writer.rb @@ -73,6 +73,7 @@ def dirname def filename basename = description.downcase.gsub(/\s+/, '_').gsub(/[^a-z_]/, '') + basename = URI.encode(description) if basename.blank? "#{basename}.html" end diff --git a/spec/html_writer_spec.rb b/spec/html_writer_spec.rb index 21baf4b9..c84c03b9 100644 --- a/spec/html_writer_spec.rb +++ b/spec/html_writer_spec.rb @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- require 'spec_helper' describe RspecApiDocumentation::HtmlWriter do @@ -31,3 +32,24 @@ end end end + +describe RspecApiDocumentation::HtmlExample do + let(:metadata) { {} } + let(:group) { RSpec::Core::ExampleGroup.describe("Orders", metadata) } + let(:example) { group.example("Ordering a cup of coffee") {} } + let(:configuration) { RspecApiDocumentation::Configuration.new } + let(:html_example) { described_class.new(example, configuration) } + + it "should have downcased filename" do + html_example.filename.should == "ordering_a_cup_of_coffee.html" + end + + describe "multi charctor example name" do + let(:label) { "コーヒーが順番で並んでいること" } + let(:example) { group.example(label) {} } + + it "should have downcased filename" do + html_example.filename.should == URI.encode(label) + ".html" + end + end +end From c21408fd0216b88dba93a7c303e9199446ccbcb4 Mon Sep 17 00:00:00 2001 From: Akihiro Matsumura Date: Mon, 9 Jul 2012 16:20:16 +0900 Subject: [PATCH 2/2] Support multibyte description To out put file as "#{md5}.html" --- lib/rspec_api_documentation/html_writer.rb | 2 +- spec/html_writer_spec.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/rspec_api_documentation/html_writer.rb b/lib/rspec_api_documentation/html_writer.rb index a66bbdcc..d669bb5b 100644 --- a/lib/rspec_api_documentation/html_writer.rb +++ b/lib/rspec_api_documentation/html_writer.rb @@ -73,7 +73,7 @@ def dirname def filename basename = description.downcase.gsub(/\s+/, '_').gsub(/[^a-z_]/, '') - basename = URI.encode(description) if basename.blank? + basename = Digest::MD5.new.update(description).to_s if basename.blank? "#{basename}.html" end diff --git a/spec/html_writer_spec.rb b/spec/html_writer_spec.rb index c84c03b9..8000342a 100644 --- a/spec/html_writer_spec.rb +++ b/spec/html_writer_spec.rb @@ -49,7 +49,8 @@ let(:example) { group.example(label) {} } it "should have downcased filename" do - html_example.filename.should == URI.encode(label) + ".html" + filename = Digest::MD5.new.update(label).to_s + html_example.filename.should == filename + ".html" end end end