Javascript 水豚找不到链接“;删除评论;

Javascript 水豚找不到链接“;删除评论;,javascript,ruby-on-rails,rspec,phantomjs,capybara,Javascript,Ruby On Rails,Rspec,Phantomjs,Capybara,这里是风景 #视图/注释/_comment.html.erb <div class="comment clearfix"> <div class="comment_content"> <p class="comment_name"><strong><%= comment.name %></strong></p> <p clas

这里是风景 #视图/注释/_comment.html.erb

<div class="comment clearfix">

  <div class="comment_content">
    <p class="comment_name"><strong><%= comment.name %></strong></p>
    <p class="comment_body"><%= comment.body %></p>
    <p class="comment_time"><%= time_ago_in_words(comment.created_at) %> ago</p>
  </div>

  <% if user_signed_in? && current_user.email == ENV['ADMIN'] %>
    <p><%= link_to 'Delete Comment', [comment.post, comment], method: :delete, class: 'button', data: { confirm: 'Are you sure?' }, remote: true %></p>
  <% end %>

</div>
我认为这可能是由于检测到javascript,因为我用
destroy.js.erb
文件删除了它

#视图/注释/destroy.js.erb

$('.comment').remove()
所以我安装了
phantomjs

#支持/数据库_cleaner.rb

RSpec.configure do |config|
  config.before(:each) do
    DatabaseCleaner.clean_with(:truncation)
  end

  config.before(:each) do
    DatabaseCleaner.strategy = :transaction
  end

  config.before(:each, js: true) do
    DatabaseCleaner.strategy = :truncation
  end

  config.before(:each) do
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end

  config.after(:each) do
  end
end
#等级库/rails\u helper.rb

require "capybara/poltergeist" 
Capybara.javascript_driver = :poltergeist
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }

RSpec.configure do |config|    
  config.use_transactional_fixtures = false
当我运行
rspec
时,测试失败,输出如下

 Failure/Error: click_link 'Delete Comment'

 Capybara::ElementNotFound:
   Unable to find link "Delete Comment"

“删除评论”链接仅在用户登录时显示(
if user\u signed\u in?&&&…
),但在测试中,您没有登录到该用户-因此该链接实际上不在页面上。

哦,好的,你说得对。我不敢相信我忽略了这一点。谢谢您。
 Failure/Error: click_link 'Delete Comment'

 Capybara::ElementNotFound:
   Unable to find link "Delete Comment"