0
0

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チュートリアル備忘録 -テスト編-

Last updated at Posted at 2020-04-24

テスト

ページが存在することの検証

  test "should get home" do
    get root_path
    assert_response :success
  end

タイトルの検証

  test "home title" do
    get root_path
    assert_select "title", "Home | Ruby on Rails Tutorial Sample App"
  end

統合テスト

作成

$ rails g integration_test テスト名

検証

$ rails test:integration

特定のHTMLが存在するかどうか

assert_select "文章"

あるパスが存在するかどうか

assert_select "a[href=?]", パス
例:assert_select "a[href=?]", about_path

あるバスが特定の個数存在するか

assert_select "a[href=?]", パス,count:数字
例:assert_select "a[href=?]", root_path, count: 2
Code マッチするHTML
assert_select "div" <div>foobar</div>
assert_select "div", "foobar" <div>foobar</div>
assert_select "div.nav" <div class="nav">foobar</div>
assert_select "div#profile" <div id="profile">foobar</div>
assert_select "div[name=yo]" <div name="yo">hey</div>
assert_select "a[href=?]", '/', count: 1 <a href="/">foo</a>
assert_select "a[href=?]", '/', text: "foo" <a href="/">foo</a>

追加中...

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?