【发布时间】:2018-08-23 21:24:33
【问题描述】:
这是我的通知频道
class NotificationChannel < ApplicationCable::Channel
def subscribed
stream_from "notification_user_#{user.id}"
end
def unsubscribed
stop_all_streams
end
end
- 如何为此 ActionCable 频道编写测试
这是我的 Rspec
require 'rails_helper'
require_relative 'stubs/test_connection'
RSpec.describe NotificationChannel, type: :channel do
before do
@user = create(:user)
@connection = TestConnection.new(@user)
@channel = NotificationChannel.new @connection, {}
@action_cable = ActionCable.server
end
let(:data) do
{
"category" => "regular",
"region" => "us"
}
end
it 'notify user' do
#error is in below line
expect(@action_cable).to receive(:broadcast).with("notification_user_#{@user.id}")
@channel.perform_action(data)
end
end
当我运行这个规范时,它给出了错误
Wrong number of arguments. Expected 2, got 1
我使用this 链接为存根和这个文件编写代码。
Rails 版本 - 5.0.0.1 Ruby 版本 - 2.3.1
【问题讨论】:
-
哪一行有错误?
-
错误在
expect(@action_cable)行。我用评论更新了我的问题
标签: ruby-on-rails rspec ruby-on-rails-5 actioncable