[RAILS] I want to test Action Cable with RSpec test


It doesn't explain how to set up Rspec. Please refer to this article and set it up. https://qiita.com/tatsurou313/items/c923338d2e3c07dfd9ee

1. Set Capybara's server to puma.

After investigating, it seems that Capybara's default server is just running the Rails application in a separate thread, and you need to use puma to use Action Cable. Therefore, it was necessary to describe in rails_hepler etc. to use puma.


Capybara.server = :puma

I thought this was OK, but for some reason the test still fails.

       expect {
         fill_in "message_content", with: "Thanking you in advance."
         click_button "Send"
       }.to change(Message, :count).by(1)
       expected `Message.count` to have changed by 1, but was changed by 0

2. Set the waiting time with sleep.

It's easy to understand with a little thought, but probably because of asynchronous communication, the message table count did not increase immediately.


    expect {
      fill_in "message_content", with: "Thanking you in advance."
      click_button "Send"
      sleep 5
    }.to change(Message, :count).by(1)

So, if you put sleep like this, the test will pass successfully.

There were some articles about changing Capybara to puma, but I couldn't find an article about setting sleep, so I posted it.

Reference article

https://qiita.com/tatsurou313/items/c923338d2e3c07dfd9ee https://blog.willnet.in/entry/2017/06/05/092956

Recommended Posts

I want to test Action Cable with RSpec test
[Rails] I want to test with RSpec. We support your step [Introduction procedure]
[Java] I want to test standard input & standard output with JUnit
I want to use DBViewer with Eclipse 2018-12! !!
I want to RSpec even at Jest!
I want to write a unit test!
I rewrote the Rails tutorial test with RSpec
Introduction to RSpec 1. Test, RSpec
I want to use java8 forEach with index
[Rails] Test with RSpec
Test Nokogiri with Rspec.
I want to play with Firestore from Rails
I want to perform aggregation processing with spring-batch
[Rails] I want to load CSS with webpacker
I want to dark mode with the SWT app
I want to monitor a specific file with WatchService
I want to authenticate users to Rails with Devise + OmniAuth
I want to transition screens with kotlin and java!
I want to click a GoogleMap pin in RSpec
Introduction to RSpec 4. Create test data with Factory Bot
I want to get along with Map [Java beginner]
I want to redirect sound from Ubuntu with xrdp
I want to convert characters ...
Test Active Strage with RSpec
Test GraphQL resolver with rspec
Rspec: I want to test the post-execution state when I set a method on subject
I want to randomly generate information when writing test code
I want to push an app made with Rails 6 to GitHub
I want to make a list with kotlin and java!
I want to make a function with kotlin and java!
How to test a private method with RSpec for yourself
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
I want to manually send an authorization email with Devise
I want to distinct the duplicated data with has_many through
How to erase test image after running Rspec test with CarrierWave
I want to implement various functions with kotlin and java!
I want to pass the startup command to postgres with docker-compose.
Swift: I want to chain arrays
Real-time comment function with Action Cable (2/2)
Test with RSpec + Capybara + selenium + chromedriver
I want to use FormObject well
I want to convert InputStream to String
I tried to interact with Java
I want to docker-compose up Next.js!
Real-time comment function with Action Cable (1/2)
Copy and paste test with RSpec
[RSpec] How to write test code
Let's unit test with [rails] Rspec!
I want to make a button with a line break with link_to [Note]
I want to connect SONY headphones WH-1000XM4 with LDAC on ubuntu 20.04! !!
I want to convert an array to Active Record Relation with Rails
I want to hook log file generation / open with log4j # FileAppender
I want to add a browsing function with ruby on rails
I want to return to the previous screen with kotlin and java!
I want to INSERT Spring Local Time with MySQL Time (also milliseconds)
I want to avoid OutOfMemory when outputting large files with POI
I want to operate cron with GUI, so I will install Dkron
[Java] I want to perform distinct with the key in the object
[Rails] I want to add data to Params when transitioning with link_to
I want to perform asynchronous processing and periodic execution with Rail !!!
I want to extract between character strings with a regular expression