Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test with Rspec and ActionController::Live while writing to stream in Rails 4?

I am currently experimenting with ActionController::Live and I can't figure out how to test this properly.

In my controller I have this written

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

But when I inspect the object in my rspec test I see this

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

When I write the "data" to the stream, I can't figure out whyit doesn't show up in the array. When I remove the first response.stream.write line the buf returns an empty array.

like image 900
ericraio Avatar asked May 27 '13 18:05

ericraio


1 Answers

Figured out the issue. Calling to_json in the stream.write doesn't add the stream into the buf instance variable. so I stubbed out to_json and forced a return value, now I can make sure that the stream is writing properly

like image 194
ericraio Avatar answered Oct 01 '22 21:10

ericraio