How to test Rspec and ActionController :: Live when writing to Rails 4?

I am currently experimenting with ActionController :: Live, and I cannot figure out how to verify this correctly.

In my controller I have written

response.stream.write("event: #{event}\n") response.stream.write("data: #{post.to_json}\n\n") 

But when I check the object in my rspec test, I see this

  (rdb:1) response.stream.instance_variable_get(:@buf) ["event: event\n"] 

When I write β€œdata” to a stream, I cannot understand why for some reason it does not appear in the array. When I delete the first line of response.stream.write, buf returns an empty array.

+6
source share
1 answer

I found out the problem. Calling to_json in stream.write does not add the stream to the buf instance variable. so I skipped to_json and forcedly returned the value, now I can make sure the thread is writing correctly

+3
source

Source: https://habr.com/ru/post/945956/


All Articles