Skip to content
This repository has been archived by the owner on May 25, 2018. It is now read-only.

Testing Faye with RSpec #76

Open
toomus opened this issue Mar 27, 2015 · 5 comments
Open

Testing Faye with RSpec #76

toomus opened this issue Mar 27, 2015 · 5 comments

Comments

@toomus
Copy link

toomus commented Mar 27, 2015

Hi. Is it possible to test Faye with RSpec?

@toomus
Copy link
Author

toomus commented Apr 2, 2015

OK, i know, that i have to use EventMachine, but now i have other problem. I want to test, that when I create new ChatMessage, it is published. When i subscribe to channel in my spec, messages published by model observer don't come. I wait for subscription and nothing happen. I put some prints to model observer and i see it is working.

EventMachine.run do
  client = Faye::Client.new('http://localhost:3000/faye')

  sub = client.subscribe("/chat/1") do |message|
    @message = message
    EventMachine.stop_event_loop
  end

  sub.callback do
    ChatMessage.create(content: "test message")
  end

  EventMachine.add_timer(4) do
    EventMachine.stop_event_loop
  end
end
expect(@message).not_to be_nil

What I am doing wrong? THX form help.

@toomus
Copy link
Author

toomus commented Apr 2, 2015

OK, the problem is, although client subscribe channel, and receive success, it really doesn't subscribe. Server receives good message, but outgoing message looks like {"id"=>"4", "channel"=>"/chat/1", "successful"=>true}, so i think it mean, nobody is subscribing that channel. Am I right?

@mike927
Copy link

mike927 commented Aug 26, 2015

I have the same issue as you, have you resolved it ?

@toomus
Copy link
Author

toomus commented Aug 26, 2015

Hi. The only way, to get this to work is to run your app before RSpec in 'test' env. You need also use DatabaseCleaner, and set in spec_helper.rb

   DatabaseCleaner.strategy = :deletion

to avoid problems with data visibility.

@mike927
Copy link

mike927 commented Aug 27, 2015

Thanks for you reply then

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants