Rails本体の、testを実行する(2)

昨日 (http://d.hatena.ne.jp/kouji0625/20130611/p1) の続きです。

全体のテストを実行する

ここで全体のテストを実行してみて、現状の問題を確認します。

$ mkdir -p ../rails-test-logs/v3.0.3/
$ bundle exec rake test 2>&1 | tee ../rails-test-logs/v3.0.3/`date +%Y%m%dT%H%M%S`.log
(以下、実行結果)
(in /Users/kouji/work/rails/rails)
(省略)
rake aborted!
Errors in activesupport, actionpack, activerecord
/Users/kouji/work/rails/rails/Rakefile:45
(See full trace by running task with --trace)

実行結果から分かった問題を以下に挙げます。(作業を進めるとまだまだ増えるかもね。)

  • 全体
  • activesupport
    • 2つテストに失敗する(のちに5つに増えたorz)
  • actionpack
    • 3つテストに失敗する
  • activerecord
    • MySQLのセットアップが必要
    • PostgreSQLのセットアップが必要
    • 失敗するテストの修正。なお、そもそも DBMS が未設定なのでテスト自体ができておらず、この時点では失敗するテストの数は不明。
    • 「DEPRECATION WARNING: reorder is deprecated. Please use except(:order).order(...) instead. (called from ./test/models/developer.rb:91)」の警告
    • 大量の「joins is deprecated and will be removed in 2.2」の警告
    • linecacheの「warning: method redefined; discarding old clear_file_format_cache」の警告
    • 「to_a is deprecated. Please remove it from ./test/cases/relations_test.rb:31:in `test_apply_relation_as_where_id'」の警告
    • 「./test/cases/relation_scoping_test.rb:418: warning: method redefined; discarding old test_except_and_order_overrides_default_scope_order」の警告
    • 「/Users/kouji/.rvm/gems/ruby-1.8.7-p358@rails-3.0.3/gems/rack-1.2.8/lib/rack/utils.rb:304: warning: method redefined; discarding old bytesize」の警告

上記を地道に問題を解決していく。

全体

memcachedのインストール
$ sudo port install memcached
$ memcached -d

この状態で rake test を実行すれば「Skipping memcached backed store tests. Start memcached and try again.」は表示されなくなる。
なお、 memcached を停止するときは「killall memcached」を実行すればよい。(もっとよい停止方法があるかも...)

activesupport

テストに失敗する
  1) Failure:
test_deprecate_class_method(DeprecationTest)
    [/Users/kouji/work/rails/rails/activesupport/lib/active_support/testing/deprecation.rb:11:in `assert_deprecated'
     /Users/kouji/work/rails/rails/activesupport/test/deprecation_test.rb:65:in `test_deprecate_class_method'

v3.0.20からバックポートして対応。

$ git diff v3.0.3..v3.0.20 -- test/deprecation_test.rb | patch -p2          
  2) Failure:
test_escaping_to_xml(HashToXmlTest)
    [/Users/kouji/work/rails/rails/activesupport/test/core_ext/hash_ext_test.rb:919:in `test_escaping_to_xml'

v3.0.20から手作業でバックポートして対応。commit id: f0001afd26b17a7af71be96efb2fd0c5f6ec2716

  3) Failure:
test_uniq_load_paths(LoadPathsTest)
    [/Users/kouji/work/rails/rails/activesupport/test/load_paths_test.rb:13:in `test_uniq_load_paths'

rakeのバージョンが新しいことが原因だった。bundle exec rake testで回避。

  4) Failure:
test_formatted_offset_positive(TimeZoneTest)
    [/Users/kouji/work/rails/rails/activesupport/test/time_zone_test.rb:228:in `test_formatted_offset_positive'
  5) Failure:
test_to_s(TimeZoneTest)
    [/Users/kouji/work/rails/rails/activesupport/test/time_zone_test.rb:260:in `test_to_s'

v3.0.20からバックポートして対応。

$ git diff v3.0.3..v3.0.20 test/time_zone_test.rb | patch -p2

actionpack

テストに失敗する
  1) Failure:
test_response_cookies_are_added_to_the_cookie_jar_for_the_next_request(IntegrationProcessTest)
    [./test/controller/integration_test.rb:299:in `test_response_cookies_are_added_to_the_cookie_jar_for_the_next_request'

v3.0.20からバックポートして対応。

$ git diff v3.0.3..v3.0.20 test/controller/integration_test.rb | patch -p2
  2) Failure:
test_rendering_a_partial_in_an_RJS_template_should_pick_the_JS_template_over_the_HTML_one(RenderRjs::TestBasic)
    [./test/abstract_unit.rb:268:in `assert_body'
     ./test/abstract_unit.rb:276:in `assert_response'
     ./test/controller/new_base/render_rjs_test.rb:48:in `test_rendering_a_partial_in_an_RJS_template_should_pick_the_JS_template_over_the_HTML_one'

v3.0.20からバックポート。lib/action_view/testing/resolvers.rb も修正しないといけなかった。resolvers.rb のほうは、順番通りにファイルを探索する処理が入っている。

$ git diff v3.0.3..v3.0.20 test/controller/new_base/render_rjs_test.rb | patch -p2
$ git diff v3.0.3..v3.0.20 lib/action_view/testing/resolvers.rb | patch -p2
  3) Failure:
test_auto_link_with_block_with_html(TextHelperTest)
    [./test/template/text_helper_test.rb:501:in `test_auto_link_with_block_with_html'

sanitize(html)の処理結果の属性の順番が不定であることが原因のようだ。このため、のsrcとwidthの順番が不定になる。そして、テストに失敗する。不定であることが仕様なので、テストを修正すべきと判断しました。修正結果は以下です。

diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb
index 88ec6fc..493cff2 100644
--- a/actionpack/test/template/text_helper_test.rb
+++ b/actionpack/test/template/text_helper_test.rb
@@ -498,7 +498,7 @@ class TextHelperTest < ActionView::TestCase
     pic = "http://example.com/pic.png"
     url = "http://example.com/album?a&b=c"
 
-    assert_equal %(My pic: <a href="#{pic}"><img src="#{pic}" width="160px"></a> -- full album here #{generate_result(url)}), auto_link("My pic: #{pic} -- full album here #{url}") { |link|
+    assert_match %r(My pic: <a href="#{Regexp.quote(pic)}"><img (src="#{Regexp.quote(pic)}" width="160px"|width="160px" src="#{Regexp.quote(pic)}")></a> -- full album here #{Regexp.quote(generate_result(url))}), auto_link("My pic: #{pic} -- full album here #{url}") { |link|
       if link =~ /\.(jpg|gif|png|bmp|tif)$/i
         raw %(<img src="#{link}" width="160px">)
       else

今日はここまで。

(つづく...)

--- 参考URL

--- PR広告
記事を読んでくださり、ありがとうございます。もしよろしければ、この記事の著者が提供している無料のサービス「かくってる?」をお試しください。