我不明白这里有什么问题。我已经搜索了几个小时的互联网,只发现了有类似问题的人,并且我尝试了他们的解决方案,但是我仍然遇到了这个错误。我正在运行一个测试,它告诉我它无法找到元素标题,但是我在代码中查看它,并且我也在本地主机上看到它。当我在督察中查看它时,它的字段名称为标题。 任何帮助将不胜感激。水豚:: 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个范围,如果您不了解它,最终会出现各种奇怪的问题 –