Railsチュートリアル備忘録 -テスト編-
2590 ワード
テスト
ページが存在することの検証
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> |
追加中...
Author And Source
この問題について(Railsチュートリアル備忘録 -テスト編-), 我々は、より多くの情報をここで見つけました https://qiita.com/BlueBamb/items/728e0943d653e3e21b52著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .