LoginSignup
1
2

More than 3 years have passed since last update.

minitestからRSpecへテストコードを変換した

Posted at

まとめ

https://github.com/kinushu/minitest_to_rspec
使って
mt2rspec --rails source_file [target_file]
実行。
ただ手作業での変換もどうしても必要です。

やったこと

minitestでテスト書かれていたプロジェクト、RSpecの仕組み使いたいところもでてきたため、
えいやっとRSpecに変更しようと思い、
他にやっている人おられるか探してみたけどそんなに情報がなさそう…

GitHub を漁ると、おお
https://github.com/jaredbeck/minitest_to_rspec
いいではないですか。(もうメンテされてなさそうだけど、しょうがない)

# test/**/*_test.rb 
# それぞれに
mt2rspec --rails source_file [target_file]
# を適用していきます。

日本語がUTF-8のコードポイントのテキストになってしまう現象あったため、

UTF8_SYMBOL = 'utf-8'.freeze
UTF8_CODEPOINT_REG = /\\u([0-9a-fA-F]{4})/i
UTF8_CODEPOINT_REG2 = %r<\\u{([0-9a-fA-F]{4})}>

def convert_utf_codep_to_original_text(tgt_s)
  reg = UTF8_CODEPOINT_REG
  res = tgt_s.gsub(reg) { |s| s.match(reg)[1].to_i(16).chr(UTF8_SYMBOL) }

  reg = UTF8_CODEPOINT_REG2
  res = res.gsub(reg) { |s| s.match(reg)[1].to_i(16).chr(UTF8_SYMBOL) }

  return res
end

な感じで変換していく。

また、matcherが対応していないもので、対応できそうなところはforkして対応してみました。
https://github.com/kinushu/minitest_to_rspec
assert_not, assert_not_nil の対応を追記しました。

でも自動変換できないところはまだあるので、もう手動で書き換えしました。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2