tristandunn / pusher-fake

A fake Pusher server for development and testing.
https://rubygems.org/gems/pusher-fake
MIT License
173 stars 32 forks source link

Fail to use Pusher fake #6

Closed sebfie closed 11 years ago

sebfie commented 12 years ago

Hello,

I am trying to use your gem. So i added this to my test_helper :

# Pusher fake configuration
# Use the same API key and secret as the live version.
PusherFake.configure do |configuration|
  configuration.app_id = Pusher.app_id
  configuration.key    = Pusher.key
  configuration.secret = Pusher.secret
end

# Set the host and port to the fake web server.
Pusher.host = PusherFake.configuration.web_host
Pusher.port = PusherFake.configuration.web_port

# Start the fake web server.
fork { PusherFake::Server.start }.tap do |id|
   at_exit { Process.kill("KILL", id) }
end

I added this to my javascript :

<% if defined?(PusherFake) %>
  Pusher.host    = <%== PusherFake.configuration.socket_host.to_json %>;
  Pusher.ws_port = <%== PusherFake.configuration.socket_port.to_json %>;
<% end %>

It renders :

$(function () {
  // Init pusher instance
  Pusher.channel_auth_endpoint = '/a/50754ceaa8fb0eb8d7000004/pusher/auth'; 
  Pusher.host = "127.0.0.1";
  Pusher.ws_port = 8080;
  mypusher = new Pusher('MY_API_KEY'); // uses your API KEY
  mypusher.subscribe('private-4');
});

But my browser can't connect to the server. I got this logs :

Pusher : Connecting : ws://127.0.0.1:8080/app/MY_API_KEY?protocol=5&client=js&version=1.12.3&flash=false application.js:135
Pusher : Connecting : wss://127.0.0.1:443/app/MY_API_KEY?protocol=5&client=js&version=1.12.3&flash=false application.js:135
Pusher : Connecting : ws://127.0.0.1:8080/app/MY_API_KEY?protocol=5&client=js&version=1.12.3&flash=false application.js:135
Pusher : Connecting : wss://127.0.0.1:443/app/MY_API_KEY?protocol=5&client=js&version=1.12.3&flash=false application.js:135
Pusher : Connecting : ws://127.0.0.1:8080/app/MY_API_KEY?protocol=5&client=js&version=1.12.3&flash=false application.js:135
Pusher : State changed : connecting -> unavailable  

Any idea?

tristandunn commented 12 years ago

Can you try running pusher-fake-example? It's the simplest implementation I have. If it works then then there's an issue specific to your setup.

I noticed you mentioned adding the setup to test_helper. What type of tests are you attempting to use it with? The instructions I provide are specifically meant for Cucumber.

I also appear to be a patch versions behind on the JS library. I'll update it soon to ensure that's not the issue.

tristandunn commented 11 years ago

Any update?