我不明白這裏有什麼問題。我已經搜索了幾個小時的互聯網,只發現了有類似問題的人,並且我嘗試了他們的解決方案,但是我仍然遇到了這個錯誤。我正在運行一個測試,它告訴我它無法找到元素標題,但是我在代碼中查看它,並且我也在本地主機上看到它。當我在督察中查看它時,它的字段名稱爲標題。 任何幫助將不勝感激。水豚:: ElementNotFound無法找到字段「標題」
我_form.html.erb這我呈現在new.html.erb
<div class='form-group'> <div class='control-label col-md-1'> <%= f.label :title %> </div> <div class='col-md-11'> <%= f.text_field :title, class: 'form-control', placeholder: 'Title of movie', autofocus: true %> </div>
我控制器
def create @movie = current_admin.movies.build(movie_params) if @movie.save flash[:success] = "Movie has been created" redirect_to root_path else flash.now[:danger] = "Movie has not been created" render :new end end
我的功能規格
fill_in "Title", with: "Movie title" fill_in "Synopsis", with: "Lorem Ipsum" fill_in "Year released", with: "Date" click_button "Add Movie」
我的錯誤
Capybara::ElementNotFound Unable to find field 「Title」
這裏是GitHub如果你認爲有必要關注一下。
是的!謝謝,湯姆!我沒有意識到範圍,對RSpec來說是新的。 – kyle
@kyle範圍是設計的一個功能。您應該在設計文檔中閱讀它,因爲您已在應用程序中創建了至少2個範圍,如果您不瞭解它,最終會出現各種奇怪的問題 –