1
背景私は私のRuby on Railsのアプリケーションのために、次のテストを書きたいはあるが動作していないclick_link
。
- ユーザーとしてログインします。
- ユーザー編集ページにアクセスしてください。
- ナビゲーションのリンクをクリックしてAbout Usページに移動します。
- 実際にAbout Usページにアクセスし、正しいテンプレートを確認してください。
理由は、私たちのリンクについて、私はそれが '/ welcome/about /'の参照となるため、存在しない/ users/welcome/aboutに行くバグを発見したからです。
マイコード
次のように私のテストコードは次のとおりです。
test 'welcome page from user page works' do
log_in_as(@user)
get edit_user_path(@user)
assert_select "a", { :text=> "About Us" }
click_on ("About Us")
assert_template 'welcome/about'
end
エラーメッセージ
ERROR["test_welcome_page_from_user_page_works", WelcomePageTest, 1.42307711095782]
test_welcome_page_from_user_page_works#WelcomePageTest (1.42s)
Capybara::ElementNotFound: Capybara::ElementNotFound: Unable to find link or button "About Us"
test/integration/welcome_page_test.rb:13:in `block in <class:WelcomePageTest>'
Finished in 1.42605s
1 tests, 1 assertions, 0 failures, 1 errors, 0 skips
これは私がその主張と思わせる1つのアサーションがあるのでリンクは過去のものですが、なんとかclick_linkはそれを見つけることができません。
test 'welcome page from user page works' do
log_in_as(@user)
visit edit_user_path(@user)
click_on ("About Us")
assert_template 'welcome/about'
end
私もちょうどでハードコードされるルートを変更注:
get 'about' => 'welcome#about'