It doesn't explain how to set up Rspec. Please refer to this article and set it up. https://qiita.com/tatsurou313/items/c923338d2e3c07dfd9ee
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.
rails_htpler.rb
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
It's easy to understand with a little thought, but probably because of asynchronous communication, the message table count did not increase immediately.
messages_spec.rb
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.
https://qiita.com/tatsurou313/items/c923338d2e3c07dfd9ee https://blog.willnet.in/entry/2017/06/05/092956
Recommended Posts