Kouhei Sutou
kous****@users*****
2006年 11月 26日 (日) 16:30:37 JST
Index: tomoe/test/Makefile.am diff -u tomoe/test/Makefile.am:1.15 tomoe/test/Makefile.am:1.16 --- tomoe/test/Makefile.am:1.15 Wed Nov 22 16:18:11 2006 +++ tomoe/test/Makefile.am Sun Nov 26 16:30:37 2006 @@ -26,6 +26,8 @@ run-spec.rb \ run-test.sh \ tomoe-spec-utils.rb \ - context_spec.rb + context_spec.rb \ + dict_spec.rb \ + writing_spec.rb TESTS = run-spec.rb Index: tomoe/test/context_spec.rb diff -u tomoe/test/context_spec.rb:1.9 tomoe/test/context_spec.rb:1.10 --- tomoe/test/context_spec.rb:1.9 Thu Nov 23 23:30:48 2006 +++ tomoe/test/context_spec.rb Sun Nov 26 16:30:37 2006 @@ -1,9 +1,6 @@ require 'tomoe-spec-utils' context "Tomoe::Context" do - inherit TomoeSpecBase - include TomoeSpecUtils - setup do @context = Tomoe::Context.new test_dir = File.expand_path(File.join(File.dirname(__FILE__))) Index: tomoe/test/dict_spec.rb diff -u /dev/null tomoe/test/dict_spec.rb:1.1 --- /dev/null Sun Nov 26 16:30:37 2006 +++ tomoe/test/dict_spec.rb Sun Nov 26 16:30:37 2006 @@ -0,0 +1,52 @@ +require 'tomoe-spec-utils' + +context "Tomoe::Context" do + setup do + @dict_file = Tempfile.new("tomoe-dict") + @dict_content = <<-EOX +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE tomoe_dictionary SYSTEM "tomoe-dict.dtd"> +<tomoe_dictionary name="TOMOE Strokelist Dictionary"> + <character> + <literal>ã</literal> + <strokelist> + <s>(54 58) (249 68) </s> + <s>(147 10) (145 201) (182 252) </s> + <s>(224 103) (149 230) (82 240) (53 204) (86 149) (182 139) (240 172) (248 224) (228 250) </s> + </strokelist> + </character> +</tomoe_dictionary> +EOX + set_content(@dict_content) + end + + specify "should load and save" do + dict = Tomoe::Dict.new(@dict_file.path, true) + truncate_content + dict.save + content.should == @dict_content + end + + def set_content(content) + @dict_file.open + @dict_file.truncate(0) + @dict_file.rewind + @dict_file.print(content) + @dict_file.close + + @dict_file.open + @dict_file.read.should == content + @dict_file.close + end + + def truncate_content + set_content("") + end + + def content + @dict_file.open + @dict_file.read + ensure + @dict_file.close + end +end Index: tomoe/test/run-spec.rb diff -u tomoe/test/run-spec.rb:1.2 tomoe/test/run-spec.rb:1.3 --- tomoe/test/run-spec.rb:1.2 Tue Nov 21 17:20:56 2006 +++ tomoe/test/run-spec.rb Sun Nov 26 16:30:37 2006 @@ -17,6 +17,8 @@ end end +ARGV.unshift("--diff") + Dir.glob(File.join(test_dir, "*_spec.rb")).each do |file| require File.basename(file, ".rb") end Index: tomoe/test/tomoe-spec-utils.rb diff -u tomoe/test/tomoe-spec-utils.rb:1.5 tomoe/test/tomoe-spec-utils.rb:1.6 --- tomoe/test/tomoe-spec-utils.rb:1.5 Sat Nov 25 00:57:20 2006 +++ tomoe/test/tomoe-spec-utils.rb Sun Nov 26 16:30:37 2006 @@ -4,13 +4,28 @@ $KCODE = "u" -class TomoeSpecBase - def setup - setup_context +module TomoeSpecSetup + def before_context_eval + super + @context_eval_module.class_eval do + include TomoeSpecUtils + + setup do + setup_context + end + + teardown do + teardown_context + end + end end +end - def teardown - teardown_context +module Spec + module Runner + class Context + include TomoeSpecSetup + end end end Index: tomoe/test/writing_spec.rb diff -u tomoe/test/writing_spec.rb:1.2 tomoe/test/writing_spec.rb:1.3 --- tomoe/test/writing_spec.rb:1.2 Thu Nov 23 23:09:36 2006 +++ tomoe/test/writing_spec.rb Sun Nov 26 16:30:37 2006 @@ -1,9 +1,6 @@ require 'tomoe-spec-utils' context "Tomoe::Writing" do - inherit TomoeSpecBase - include TomoeSpecUtils - specify "should each all strokes" do writing = Tomoe::Writing.new strokes = [