6
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

RSpecでUnable to find visible file field が出た

Posted at

RSspecでのsystemtestでattach_fileしようとしたらfile fieldが見つからなかった

users_spec.rb
#省略
  attach_file "プロフィール画像を選択", "#{Rails.root}/spec/images/test.jpg"
#省略
edit.html.erb

#省略
  <div class="field">
          <%= f.label :image, "プロフィール画像を選択", class: "form-control" %>
          <%= f.file_field :image, class: "none-form" %>
  </div>
#省略
application.css
.none-form {
  display: none;
}

cssでfile_fieldを非表示にしていたのが原因

#解決法
make_visible: trueを加える

users_spec.rb
# make_visible: true を追加
attach_file "プロフィール画像を選択", "#{Rails.root}/spec/images/test.jpg", make_visible: true

参照: https://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Actions#attach_file-instance_method

6
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?