履歴: ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト

各行は、その日時に書かれた内容です。追加・削除は、1 つ前の版との行数の差です (全 13 版)。「差分」は比較する版、「基準」は比べる相手の版を選びます

日時タイトル文字数追加削除内容差分基準
2014/6/2 9:53:59ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト 最新版39,445+1 -1表示差分—
2014/6/2 9:53:59ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト 39,451+6 -1表示差分選択
2014/5/30 14:33:33ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト 39,363+2 -0表示差分選択
2014/5/30 14:32:24ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト 39,288+116 -17表示差分選択
2014/5/30 7:58:45ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト 36,014+229 -0表示差分選択
2014/5/26 4:31:48ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト 29,846+11 -4表示差分選択
2014/5/26 4:31:48ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト 29,608+30 -0表示差分選択
2014/5/24 1:25:48ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト 28,564+1 -1表示表示中選択
2014/5/23 17:42:25ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト 27,825+163 -0表示差分選択
2014/5/23 13:25:19ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト 21,221+174 -2表示差分基準
2014/5/23 3:13:32ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト 15,654+253 -88表示差分選択
2014/5/22 14:25:52ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト 12,435+167 -47表示差分選択
2014/5/22 13:28:26ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト 9,057— —表示—選択

基準: ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト (2014/5/23 13:25:19) → 比較: ソフトウェア/rails/ActiveSupport_TestCase + shoulda によるテスト (2014/5/24 1:25:48)

@@ -597,6 +597,10 @@
このようなメッセージからエラーが生じたテストの場所を特定するのはなかなか手間がかかります。
+ごたごたは飛ばして解決策へ飛ぶ場合は [[こちら>#s29326e1]]
+
+*** 試行錯誤 [#c418a6e5]
+
で、例外のバックトレースをいじって改善できない物か???と考えたわけです。
ActiveSupport::TestCase ~
@@ -702,14 +706,21 @@
これだと例外から行番号を得るのは難しいですね。
+*** 解決 [#s29326e1]
+
むしろ、この :name に行番号を突っ込んじゃえばいいという話かも。
+test/shoulda_macros/add_caller_information.rb
LANG:ruby
+ #coding: utf-8
+
module Shoulda
module Context
class Context # :nodoc:
+ # should ブロックの :name に行番号を書き足す
def add_caller_line_number(should)
+ # 現バージョンでは2番目が呼び出し元になるみたい
caller(2).first =~ /:(\d+):in /
should[:name] = should[:name].to_s + " (at line #{$1})"
end
@@ -745,6 +756,158 @@
などというように、should や should_not に対応する行番号が (at line xxx) の形で付くようになりました。
+caller() は遅いので、called_from を作った、という記事がありました。テストの規模が大きい場合には検討の価値があるかもしれません。(このライブラリ、Ruby 1.8 以外に対応していない?)~
+http://magazine.rubyist.net/?0031-BackTrace#l7 ~
+とはいえ1万個の should を作ってようやく1秒違うかどうかなので、気にするだけ損なのかも。
+
+* assert_XXX [#h14dab47]
+
+|>|>|>|>|~[[mt>https://github.com/seattlerb/minitest/blob/7e25922c340fa1cfdbeffaf8f37ec020cf6a4fff/lib/minitest/unit.rb#L190]] [[AS>https://github.com/rails/rails/blob/4-0-stable/activesupport/lib/active_support/testing/assertions.rb]] [[AS dep>https://github.com/rails/rails/blob/4-1-stable/activesupport/lib/active_support/testing/deprecation.rb]] [[AD>https://github.com/rails/rails/tree/4-0-stable/actionpack/lib/action_dispatch/testing/assertions]] [[AC>https://github.com/rails/rails/blob/4-0-stable/actionpack/lib/action_controller/test_case.rb#L95]] [[sd>https://github.com/thoughtbot/shoulda-context/blob/master/lib/shoulda/context/assertions.rb]] [[jr>https://github.com/rails/jquery-rails/blob/master/lib/jquery/assert_select.rb]] で実装される assert_xxxx |
+|名前|引数|テスト内容|refuse|実装|
+| assert |test, msg = nil | test | ○ |mt|
+| assert_accepts | matcher, target, options = {} | matcher.matches?(target) | | sd |
+| assert_blank | obj, msg=nil | obj.blank? | | AS |
+| assert_contains | collection, x, extra_msg = "" | x can be regexp | | sd |
+| assert_deprecated | match = nil, &block | | | AS |
+| assert_difference|expression, diff = 1, msg = nil, &block|block 前後で変化||AS|
+| assert_does_not_contain | collection, x, extra_msg = "" | x can be regexp | | sd |
+| assert_dom_equal | expected, actual, message = "" | HTML::Document.new(?).rootを比較 | | AD |
+| assert_dom_not_equal | expected, actual, message = "" | HTML::Document.new(?).rootを比較 | | AD |
+| assert_empty |obj, msg = nil | obj.empty? | ○ |mt|
+| assert_equal |exp, act, msg = nil | exp == act | ○ |mt|
+| assert_generates | expected_path, options, defaults={}, extras = {}, message=nil | | | AD |
+| assert_in_delta |exp, act, delta = 0.001, msg = nil | (act-exp).abs <= delta | ○ |mt|
+| assert_in_epsilon |a, b, epsilon = 0.001, msg = nil | 上の別名 | ○ |mt|
+| assert_includes |collection, obj, msg = nil | collection.include?(obj) | ○ |mt|
+| assert_instance_of |cls, obj, msg = nil | obj.instance_of?(cls) | ○ |mt|
+| assert_kind_of |cls, obj, msg = nil | obj.kind_of?(cls) | ○ |mt|
+| assert_match |matcher, obj, msg = nil | matcher =~ obj | ○ |mt|
+| assert_nil |obj, msg = nil | obj.nil? | ○ |mt|
+| assert_no_difference|expression, msg = nil, &block|block 前後で保存||AS|
+| assert_no_match |matcher, obj, msg = nil | matcher !~ obj | |mt|
+| assert_no_tag | *opts | html_document.find(*opts) | | AD |
+| assert_not |obj, msg = nil|!obj||AS|
+| assert_not_deprecated | &block | | |AS|
+| assert_not_empty |obj, msg = nil | !obj.empty? | |mt|
+| assert_not_equal |exp, act, msg = nil | exp != act | |mt|
+| assert_not_in_delta |exp, act, delta = 0.001, msg = nil | (act-exp).abs > delta | |mt|
+| assert_not_in_epsilon |a, b, epsilon = 0.001, msg = nil | 上の別名 | |mt|
+| assert_not_includes |collection, obj, msg = nil | !collection.include?(obj) | |mt|
+| assert_not_instance_of |cls, obj, msg = nil | !obj.instance_of?(cls) | |mt|
+| assert_not_kind_of |cls, obj, msg = nil | !obj.kind_of?(cls) | |mt|
+| assert_not_nil |obj, msg = nil | !obj.nil? | |mt|
+| assert_not_operator |o1, op, o2 = UNDEFINED, msg = nil | !o1._send_(op, o2) | |mt|
+| assert_not_predicate |o1, op, msg = nil | !o1._send_(op) | |mt|
+| assert_not_respond_to |obj, meth, msg = nil | !obj.respond_to?(meth) | |mt|
+| assert_not_same |exp, act, msg = nil | !exp.equal?(act) | |mt|
+| assert_nothing_raised | | | | |
+| assert_operator |o1, op, o2 = UNDEFINED, msg = nil | o1._send_(op, o2) | ○ |mt|
+| assert_output |stdout = nil, stderr = nil | | |mt|
+| assert_predicate |o1, op, msg = nil | o1._send_(op) | ○ |mt|
+| assert_raise | | | | |
+| assert_raises |*exp | | |mt|
+| assert_recognizes | expected_options, path, extras={}, msg=nil | | | AD |
+| assert_redirected_to | options = {}, message=nil | | | AD |
+| assert_rejects | matcher, target, options = {} | !matcher.matches?(target) | | sd |
+| assert_respond_to |obj, meth, msg = nil | obj.respond_to?(meth) | ○ |mt|
+| assert_response | type, message = nil | | | AD |
+| assert_routing | path, options, defaults={}, extras={}, message=nil | | | AD |
+| assert_same |exp, act, msg = nil | exp.equal?(act) | ○ |mt|
+| assert_same_elements | a1, a2, msg = nil | compare array asif it is set | | sd |
+| assert_select | *args, &block | | | AD |
+| assert_select_email | &block | | | AD |
+| assert_select_encoded | element = nil, &block | | | AD |
+| assert_select_jquery | *args, &block | | | jr |
+| assert_send |[recv, msg, *args], m = nil | recv._send_(msg, *args) | |mt|
+| assert_silent | |assert_output "", "" | |mt|
+| assert_tag | *opts | html_document.find(*opts) | | AD |
+| assert_template | options = {}, message = nil | | | AC |
+| assert_throws |sym, msg = nil | | |mt|
+
+- mt: minitest = https://github.com/seattlerb/minitest/blob/7e25922c340fa1cfdbeffaf8f37ec020cf6a4fff/lib/minitest/unit.rb#L190
+- AS: ActiveSupport = https://github.com/rails/rails/blob/4-0-stable/activesupport/lib/active_support/testing/assertions.rb- AS: ActiveSupport deplication = https://github.com/rails/rails/blob/4-1-stable/activesupport/lib/active_support/testing/deprecation.rb
+- AD: ActionDispatch = https://github.com/rails/rails/tree/4-0-stable/actionpack/lib/action_dispatch/testing/assertions
+- AC: ActionController = https://github.com/rails/rails/blob/4-0-stable/actionpack/lib/action_controller/test_case.rb#L95
+- sd: Shoulda = https://github.com/thoughtbot/shoulda-context/blob/master/lib/shoulda/context/assertions.rb
+- jr: jquery-rails = https://github.com/rails/jquery-rails/blob/master/lib/jquery/assert_select.rb
+
+AD: with_routing ~
+AD: css_select ~
+
+* shouda の matcher [#gd8d5b05]
+
+#multicolumns
+
+*** [[ActiveModel Matchers>https://github.com/thoughtbot/shoulda-matchers#activemodel-matchers]] [#n7a5004d]
+
+-allow_mass_assignment_of
+-''allow_value''
+-ensure_inclusion_of
+-ensure_exclusion_of
+-ensure_length_of
+-have_secure_password
+-validate_absence_of
+-validate_acceptance_of
+-validate_confirmation_of
+-validate_numericality_of
+-validate_presence_of
+-validate_uniqueness_of
+
+#multicolumns
+
+*** [[ActiveRecord Matchers>https://github.com/thoughtbot/shoulda-matchers#activerecord-matchers]] [#x0e4eaa5]
+
+-accept_nested_attributes_for
+-belong_to
+-have_many
+-have_one
+-have_and_belong_to_many
+-have_db_column
+-have_db_index
+-have_readonly_attribute
+-serialize
+
+#multicolumns
+
+*** [[ActionController Matchers>https://github.com/thoughtbot/shoulda-matchers#actioncontroller-matchers]] [#kdd1429f]
+
+-filter_param
+-permit
+-''redirect_to''
+-''render_template''
+-''render_with_layout''
+-rescue_from
+-''respond_with''
+-route
+-''set_session''
+-''set_the_flash''
+-use_after_filter
+-use_after_action
+-use_around_filter
+-use_around_action
+-use_before_filter
+-use_around_action
+
+#multicolumns(end)
+
+始めからコード側で宣言的に書かれている、例えば has_many なんかを
+わざわざテストしても、ほとんどコピペになるだけで意味は薄いと思います。
+
+なので、上記のように matcher はたくさんある物の、頻繁に使うのは、
+
+ActionModel の
+-allow_value
+
+ActionController の
+
+-redirect_to
+-render_template
+-respond_with
+-set_session
+-set_the_flash
+
+くらいかもしれません。
+
* 役立ちそうな記事 [#x64e134e]
- http://www.railstips.org/blog/archives/2009/02/21/shoulda-looked-at-it-sooner/