I
I
Ismail2020-04-27 14:38:30
Ruby on Rails
Ismail, 2020-04-27 14:38:30

Why does RSpec break on create method tests?

Good afternoon. There are integration tests on RSpec. When running tests, it displays the following message:

Failure/Error: ActionCable.server.broadcast "boards_channel_#{list_params[:board_id]}", serialized_data
SocketError:
       getaddrinfo: Name does not resolve


It breaks only when testing create methods.
Below is an example:
#create

def create
      @list = List.new(list_params)

      @board = Board.find(list_params[:board_id])

      if @list.save
        serialized_data = ActiveModelSerializers::Adapter::Json.new(
          ListSerializer.new(@list)
        ).serializable_hash
        ActionCable.server.broadcast "boards_channel_#{list_params[:board_id]}", serialized_data
        render json: @list.to_json, status: :ok
      end
    end



rspec

it "create" do
    params = {
      title: "Sample list",
      board_id: board.id
    }

    post api_v1_lists_path(list: params)

    expect(response).to have_http_status(:ok)
  end



Factory

FactoryBot.define do
  factory :list do
    title { FFaker::Skill.specialty }
    board

    trait :within_board do
      association :board
    end

    trait :with_cards do
      after :create do |list|
        cards = create_list :card, rand(0..5), list: list
      end
    end
  end
end



What is the problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question