2016-04-13 2 views
1

背景私は私のRuby on Railsのアプリケーションのために、次のテストを書きたいはあるが動作していないclick_link

  1. ユーザーとしてログインします。
  2. ユーザー編集ページにアクセスしてください。
  3. ナビゲーションのリンクをクリックしてAbout Usページに移動します。
  4. 実際に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' 

答えて

0

カピバラのために代わりのvisitメソッドを使用します

EDITこれはテストのための私の最終的なコードでしたget

visit edit_user_path(@user)

関連する問題