1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Rails】assert_matchの使い方

Last updated at Posted at 2021-03-16

assert_match

Railsテストで使うメソッドで、第一引数の正規表現の値と第二引数の値がマッチすれば成功になるメソッドです。

第三引数にメッセージを設定すると、失敗時のメッセージを指定できます。(指定は任意です)

また、HTMLを評価する際に、assert_selectではタグを指定する必要がありますが、assert_matchではタグを指定する必要がありません。

assert_match
#基本構文
assert_match(正規表現, 文字列 [, メッセージ])

#HTMLを評価するときの使い方(Railsチュートリアル第13章より)
assert_match @user.microposts.count.to_s, response.body

```



<h2>参考</h2>
Rails ドキュメント
https://railsdoc.com/test

Ruby STUDIO Railsのテスト
http://ruby.studio-kingdom.com/rails/guides/testing#2
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?