Cucumber/Capybara 使用 JavaScript 的测试似乎不会只针对一个也使用 ActionCable 和 Redis 的测试执行

Cucumber/Capybara test with JavaScript doesn't appear to execute for only one test which also uses ActionCable and Redis

我有一个 Rails (5.2.3) 应用程序,我正在尝试向其中添加聊天功能,以便用户可以相互交流。我还没有完全实现该功能,因为我正在尝试编写测试(如果我不知道如何为我要测试的内容编写测试,我经常这样做)。到目前为止,我在 HTML 中布局了应用程序相关页面的两个区域,用于发送和接收聊天消息,JavaScript 页面的其余部分 运行,JavaScript 旨在 运行 在页面加载时使聊天功能的区域填写页面的正确 space,JavaScript 收听 textarea 用于发送聊天,JavaScript 用于监听广播聊天。相关测试模仿我目前在开发版本中可以做的事情:在发送 <textarea> 中键入文本,点击 return,然后在 <div> 中查看包含聊天的消息。开发日志显示消息命中redis服务器并按预期转发。

聊天工具测试失败。如果我在浏览器中打开控制台 运行 测试,我既没有看到错误也没有证据表明页面上的 JavaScript 是为这个测试执行的(所有其他测试,所有这些都被标记@javascript正确执行)。如果我添加足够的延迟,我可以看到我用来将 enter 键发送到 textarea 的两种方法似乎都有效(因为光标移动),但预期页面上的行为(将文本发送到 redis 服务器进行广播)不会发生。

测试日志中没有证据表明 ActionCable 服务器已启动。我已经安装了 capybara-chromedriver-logger,但是我没有看到我期望的日志记录的证据。

如果我的问题中缺少您认为有助于回答问题的信息,请提出。

我为聊天元素编写的 CoffeeScript(在开发中执行,但不在测试中执行):

# Behavior for driving the sizing of the heckle forum window.
#= require_self
#= require common
class ChatWindowDriver
  @setChatWidths: () ->
    curWidth = 0
    (curWidth += $('td[data-node="'+n+'"]').width() for n in ["5", "2", "1", "3", "7"])
    curWidth -= 20 # Because of the margins we want
    $('div[id^="chat"]').each (index, element) =>
      $(element).css("width", curWidth)
    $('textarea#chat-text').each (index, element) =>
      $(element).css("width", curWidth)
    headerHeight = 0
    $('td.chat-header').each (index, element) =>
      headerHeight += $(element).height()
    $('div#chat-header-anchor').css('height', headerHeight)
    receiptHeight = 0
    $('tr.chat-receipt').each (index, element) =>
      receiptHeight += $(element).height()
    $('div#chats-received').css('height', receiptHeight)
    sendingHeight = 0
    $('tr.chat-sending').each (index, element) =>
      sendingHeight += $(element).height()
    $('div#chat-send').css('height', sendingHeight)

  @sendChat: (event) ->
    if event.keyCode is 13 # return/enter => send
      Chats.forum.heckle event.target.value
      event.target.value = ''
      event.preventDefault()

$ ->
  console.log 'can we see this message?'
  ChatWindowDriver.setChatWidths()
  $('#chat-text').on 'keypress', (e) => ChatWindowDriver.sendChat(e)

Gemfile.lock:

GEM
  remote: https://rubygems.org/
  specs:
    actioncable (5.2.4)
      actionpack (= 5.2.4)
      nio4r (~> 2.0)
      websocket-driver (>= 0.6.1)
    actionmailer (5.2.4)
      actionpack (= 5.2.4)
      actionview (= 5.2.4)
      activejob (= 5.2.4)
      mail (~> 2.5, >= 2.5.4)
      rails-dom-testing (~> 2.0)
    actionpack (5.2.4)
      actionview (= 5.2.4)
      activesupport (= 5.2.4)
      rack (~> 2.0)
      rack-test (>= 0.6.3)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.0, >= 1.0.2)
    actionview (5.2.4)
      activesupport (= 5.2.4)
      builder (~> 3.1)
      erubi (~> 1.4)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.0, >= 1.0.3)
    activejob (5.2.4)
      activesupport (= 5.2.4)
      globalid (>= 0.3.6)
    activemodel (5.2.4)
      activesupport (= 5.2.4)
    activerecord (5.2.4)
      activemodel (= 5.2.4)
      activesupport (= 5.2.4)
      arel (>= 9.0)
    activestorage (5.2.4)
      actionpack (= 5.2.4)
      activerecord (= 5.2.4)
      marcel (~> 0.3.1)
    activesupport (5.2.4)
      concurrent-ruby (~> 1.0, >= 1.0.2)
      i18n (>= 0.7, < 2)
      minitest (~> 5.1)
      tzinfo (~> 1.1)
    addressable (2.7.0)
      public_suffix (>= 2.0.2, < 5.0)
    arel (9.0.0)
    backports (3.15.0)
    bcrypt (3.1.13)
    bindex (0.8.1)
    builder (3.2.4)
    byebug (11.0.1)
    cancancan (3.0.1)
    capybara (3.29.0)
      addressable
      mini_mime (>= 0.1.3)
      nokogiri (~> 1.8)
      rack (>= 1.6.0)
      rack-test (>= 0.6.3)
      regexp_parser (~> 1.5)
      xpath (~> 3.2)
    capybara-chromedriver-logger (0.2.1)
      capybara
      colorize
    capybara-screenshot (1.0.24)
      capybara (>= 1.0, < 4)
      launchy
    childprocess (3.0.0)
    coderay (1.1.2)
    coffee-rails (5.0.0)
      coffee-script (>= 2.2.0)
      railties (>= 5.2.0)
    coffee-script (2.4.1)
      coffee-script-source
      execjs
    coffee-script-source (1.12.2)
    colorize (0.8.1)
    concurrent-ruby (1.1.5)
    crass (1.0.5)
    cucumber (3.1.2)
      builder (>= 2.1.2)
      cucumber-core (~> 3.2.0)
      cucumber-expressions (~> 6.0.1)
      cucumber-wire (~> 0.0.1)
      diff-lcs (~> 1.3)
      gherkin (~> 5.1.0)
      multi_json (>= 1.7.5, < 2.0)
      multi_test (>= 0.1.2)
    cucumber-core (3.2.1)
      backports (>= 3.8.0)
      cucumber-tag_expressions (~> 1.1.0)
      gherkin (~> 5.0)
    cucumber-expressions (6.0.1)
    cucumber-rails (2.0.0)
      capybara (>= 2.12, < 4)
      cucumber (>= 3.0.2, < 4)
      mime-types (>= 2.0, < 4)
      nokogiri (~> 1.8)
      railties (>= 4.2, < 7)
    cucumber-tag_expressions (1.1.1)
    cucumber-wire (0.0.1)
    daemons (1.3.1)
    database_cleaner (1.7.0)
    delayed_job (4.1.8)
      activesupport (>= 3.0, < 6.1)
    delayed_job_active_record (4.1.4)
      activerecord (>= 3.0, < 6.1)
      delayed_job (>= 3.0, < 5)
    diff-lcs (1.3)
    docile (1.3.2)
    email_spec (2.2.0)
      htmlentities (~> 4.3.3)
      launchy (~> 2.1)
      mail (~> 2.7)
    erubi (1.9.0)
    execjs (2.7.0)
    factory_bot (5.1.1)
      activesupport (>= 4.2.0)
    factory_bot_rails (5.1.1)
      factory_bot (~> 5.1.0)
      railties (>= 4.2.0)
    faker (2.8.1)
      i18n (>= 1.6, < 1.8)
    ffi (1.11.3)
    formatador (0.2.5)
    gherkin (5.1.0)
    globalid (0.4.2)
      activesupport (>= 4.2.0)
    guard (2.16.1)
      formatador (>= 0.2.4)
      listen (>= 2.7, < 4.0)
      lumberjack (>= 1.0.12, < 2.0)
      nenv (~> 0.1)
      notiffany (~> 0.0)
      pry (>= 0.9.12)
      shellany (~> 0.0)
      thor (>= 0.18.1)
    guard-compat (1.2.1)
    guard-rspec (4.7.3)
      guard (~> 2.1)
      guard-compat (~> 1.1)
      rspec (>= 2.99.0, < 4.0)
    htmlentities (4.3.4)
    i18n (1.7.0)
      concurrent-ruby (~> 1.0)
    jbuilder (2.9.1)
      activesupport (>= 4.2.0)
    jquery-rails (4.3.5)
      rails-dom-testing (>= 1, < 3)
      railties (>= 4.2.0)
      thor (>= 0.14, < 2.0)
    json (2.3.0)
    launchy (2.4.3)
      addressable (~> 2.3)
    lazy_priority_queue (0.1.1)
    libnotify (0.9.4)
      ffi (>= 1.0.11)
    libv8 (3.16.14.19)
    listen (3.1.5)
      rb-fsevent (~> 0.9, >= 0.9.4)
      rb-inotify (~> 0.9, >= 0.9.7)
      ruby_dep (~> 1.2)
    loofah (2.4.0)
      crass (~> 1.0.2)
      nokogiri (>= 1.5.9)
    lumberjack (1.0.13)
    mail (2.7.1)
      mini_mime (>= 0.1.1)
    marcel (0.3.3)
      mimemagic (~> 0.3.2)
    method_source (0.9.2)
    mime-types (3.3)
      mime-types-data (~> 3.2015)
    mime-types-data (3.2019.1009)
    mimemagic (0.3.3)
    mini_mime (1.0.2)
    mini_portile2 (2.4.0)
    minitest (5.13.0)
    multi_json (1.14.1)
    multi_test (0.1.2)
    nenv (0.3.0)
    nio4r (2.5.2)
    nokogiri (1.10.7)
      mini_portile2 (~> 2.4.0)
    notiffany (0.1.3)
      nenv (~> 0.1)
      shellany (~> 0.0)
    pg (1.1.4)
    pry (0.12.2)
      coderay (~> 1.1.0)
      method_source (~> 0.9.0)
    public_suffix (4.0.1)
    puma (4.3.1)
      nio4r (~> 2.0)
    rack (2.0.8)
    rack-test (1.1.0)
      rack (>= 1.0, < 3)
    rails (5.2.4)
      actioncable (= 5.2.4)
      actionmailer (= 5.2.4)
      actionpack (= 5.2.4)
      actionview (= 5.2.4)
      activejob (= 5.2.4)
      activemodel (= 5.2.4)
      activerecord (= 5.2.4)
      activestorage (= 5.2.4)
      activesupport (= 5.2.4)
      bundler (>= 1.3.0)
      railties (= 5.2.4)
      sprockets-rails (>= 2.0.0)
    rails-dom-testing (2.0.3)
      activesupport (>= 4.2.0)
      nokogiri (>= 1.6)
    rails-html-sanitizer (1.3.0)
      loofah (~> 2.3)
    railties (5.2.4)
      actionpack (= 5.2.4)
      activesupport (= 5.2.4)
      method_source
      rake (>= 0.8.7)
      thor (>= 0.19.0, < 2.0)
    rake (13.0.1)
    rb-fsevent (0.10.3)
    rb-inotify (0.10.0)
      ffi (~> 1.0)
    record_tag_helper (1.0.0)
      actionview (~> 5.x)
    redis (4.1.3)
    ref (2.0.0)
    regexp_parser (1.6.0)
    responders (3.0.0)
      actionpack (>= 5.0)
      railties (>= 5.0)
    rgl (0.5.6)
      lazy_priority_queue (~> 0.1.0)
      stream (~> 0.5.2)
    rspec (3.9.0)
      rspec-core (~> 3.9.0)
      rspec-expectations (~> 3.9.0)
      rspec-mocks (~> 3.9.0)
    rspec-core (3.9.0)
      rspec-support (~> 3.9.0)
    rspec-expectations (3.9.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.9.0)
    rspec-mocks (3.9.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.9.0)
    rspec-rails (3.9.0)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      railties (>= 3.0)
      rspec-core (~> 3.9.0)
      rspec-expectations (~> 3.9.0)
      rspec-mocks (~> 3.9.0)
      rspec-support (~> 3.9.0)
    rspec-support (3.9.0)
    ruby_dep (1.5.0)
    ruby_http_client (3.3.0)
    rubyzip (2.0.0)
    sass-rails (6.0.0)
      sassc-rails (~> 2.1, >= 2.1.1)
    sassc (2.2.1)
      ffi (~> 1.9)
    sassc-rails (2.1.2)
      railties (>= 4.0.0)
      sassc (>= 2.0)
      sprockets (> 3.0)
      sprockets-rails
      tilt
    selenium-webdriver (3.142.6)
      childprocess (>= 0.5, < 4.0)
      rubyzip (>= 1.2.2)
    sendgrid-ruby (6.0.0)
      ruby_http_client (~> 3.3.0)
    shellany (0.0.1)
    shoulda (3.6.0)
      shoulda-context (~> 1.0, >= 1.0.1)
      shoulda-matchers (~> 3.0)
    shoulda-context (1.2.2)
    shoulda-matchers (3.1.3)
      activesupport (>= 4.0.0)
    simplecov (0.17.1)
      docile (~> 1.1)
      json (>= 1.8, < 3)
      simplecov-html (~> 0.10.0)
    simplecov-html (0.10.2)
    spring (2.1.0)
    spring-watcher-listen (2.0.1)
      listen (>= 2.7, < 4.0)
      spring (>= 1.2, < 3.0)
    sprockets (4.0.0)
      concurrent-ruby (~> 1.0)
      rack (> 1, < 3)
    sprockets-rails (3.2.1)
      actionpack (>= 4.0)
      activesupport (>= 4.0)
      sprockets (>= 3.0.0)
    stream (0.5.2)
    therubyracer (0.12.3)
      libv8 (~> 3.16.14.15)
      ref
    thor (1.0.1)
    thread_safe (0.3.6)
    tilt (2.0.10)
    turbolinks (5.2.1)
      turbolinks-source (~> 5.2)
    turbolinks-source (5.2.0)
    tzinfo (1.2.6)
      thread_safe (~> 0.1)
    uglifier (4.2.0)
      execjs (>= 0.3.0, < 3)
    web-console (3.7.0)
      actionview (>= 5.0)
      activemodel (>= 5.0)
      bindex (>= 0.4.0)
      railties (>= 5.0)
    webdrivers (4.1.3)
      nokogiri (~> 1.6)
      rubyzip (>= 1.3.0)
      selenium-webdriver (>= 3.0, < 4.0)
    websocket-driver (0.7.1)
      websocket-extensions (>= 0.1.0)
    websocket-extensions (0.1.4)
    xpath (3.2.0)
      nokogiri (~> 1.8)

PLATFORMS
  ruby

DEPENDENCIES
  bcrypt
  byebug
  cancancan
  capybara
  capybara-chromedriver-logger
  capybara-screenshot
  coffee-rails
  cucumber-rails
  daemons
  database_cleaner
  delayed_job_active_record
  email_spec
  factory_bot_rails
  faker
  guard-rspec
  jbuilder
  jquery-rails
  launchy
  libnotify
  listen
  nokogiri
  pg
  puma
  rails (= 5.2.4)
  rb-inotify
  record_tag_helper
  redis
  responders
  rgl
  rspec
  rspec-rails
  sass-rails
  selenium-webdriver
  sendgrid-ruby
  shoulda
  simplecov
  spring
  spring-watcher-listen
  sprockets (>= 4.0)
  sprockets-rails
  therubyracer
  turbolinks
  uglifier
  web-console
  webdrivers

RUBY VERSION
   ruby 2.6.3p62

BUNDLED WITH
   2.0.2

通常在测试时会使用 async actioncable 适配器(而不是 redis 适配器)并且您需要在应用程序中(在测试环境中)将 actioncable 配置为 运行 ) - https://guides.rubyonrails.org/action_cable_overview.html#in-app - 为了在 Capybara 启动应用程序时启动它。