pusher-fake 0 travis-ci ruby Rubygems

A fake Pusher server for development and testing.

3 years after

pusher-fake Build Status Dependency Status Code Climate Coverage Status

A fake Pusher server for development and testing.

When run, an entire fake service is started on two random open ports. Connections can then be made to the service without needing a Pusher account. The host and port for the socket and web servers can be found by checking the configuration.

The project is intended to fully replace the Pusher service with a local version for testing and development purposes. It is not intended to be a replacement for production usage!


  1. Using a remote API for testing is slow.
  2. Working offline is currently impossible.
  3. Wasting connections and messages in development is unreasonable.
  4. Stubbing the JavaScript, such as with pusher-test-stub, is suboptimal and tedious for integration tests.


Test Environment

1. Use the PusherFake JS for the Pusher JS instance.

  <% if defined?(PusherFake) %>
    // Test environment.
    // Note: Ensure output is not HTML escaped, such as with the raw helper in Rails.
    var instance = <%= PusherFake.javascript %>;
  <% else %>
    // Other environments, such as production.
    var instance = new Pusher(...);
  <% end %>

2. Start PusherFake in your environment.

require "pusher-fake/support/rspec"
require "pusher-fake/support/cucumber"

A custom plan is required. See an example plan for the configuration necessary.

require "pusher-fake/support/base"

# Reset the channels after each test:

Development Environment

In a Rails initializer, or any file executed during loading:

# Ensure it's only run in a development environment if it's a global file.
if Rails.env.development?
  # Ensure Pusher configuration is set if you're not doing so elsewhere.
  Pusher.app_id = "MY_TEST_ID"
  Pusher.key    = "MY_TEST_KEY"
  Pusher.secret = "MY_TEST_SECRET"

  # Require the base file, which immediately starts the socket and web servers.
  # If you're including this file in multiple processes, you may want to add an
  # additional check or even possibly hard code the socket and web ports.
  require "pusher-fake/support/base"

If you're using Foreman, or something similar, you'll only want to run the fake for a single process:

  require "pusher-fake/support/base"
web: PUSHER_FAKE=1 bundle exec unicorn ...
worker: bundle exec ...


If you're creating a Pusher::Client instance and wish to use the fake, you need to provide the options.

  key:    Pusher.key,
  app_id: Pusher.app_id,
  secret: Pusher.secret


Note that the application ID, API key, and token are automatically set to the Pusher values when using an included support file.


Setting Description
app_id The Pusher application ID.
key The Pusher API key.
logger An IO instance for verbose logging.
secret The Pusher API token.
socket_options Socket server options. See EventMachine::WebSocket.start for options.
verbose Enable verbose logging.
web_options Web server options. See Thin::Server for options.
webhooks Array of webhook URLs.


# Single setting.
PusherFake.configuration.verbose = true

# Multiple settings.
PusherFake.configure do |configuration|
  configuration.logger  = Rails.logger
  configuration.verbose = true


The WebSocket server is provided all socket_options, allowing you to set the secure and tls_options options to create a secure server.

The web server passes all web_options, besides host and port, to the Thin backend via attribute writers, allowing you to set the ssl and ssl_options options.


  • pusher-fake-example - An example of using pusher-fake with RSpec to test a Rails application.


pusher-fake uses the MIT license. See LICENSE for more details.

Related Repositories



A collection of awesome Ruby libraries, tools, frameworks and software ...



A curated list about OKR (Objective - Key Results) ...



:books::100: Collection of learning resources i like ...



Synchronization of active record models across multiple clients using Pusher, Ac ...



An example of using Cucumber to test WebSocket interactions between two users. ...

Top Contributors

tristandunn mthorn hcatlin twalpole Simbul christopheralcock markoa matthieua


-   v1.6.0 zip tar
-   v1.5.0 zip tar
-   v1.4.0 zip tar
-   v1.3.0 zip tar
-   v1.2.0 zip tar
-   v1.1.0 zip tar
-   v1.0.1 zip tar
-   v1.0.0 zip tar
-   v0.14.0 zip tar
-   v0.13.0 zip tar
-   v0.12.0 zip tar
-   v0.11.0 zip tar
-   v0.10.0 zip tar
-   v0.9.0 zip tar
-   v0.8.0 zip tar
-   v0.7.0 zip tar
-   v0.6.0 zip tar
-   v0.5.0 zip tar
-   v0.4.0 zip tar
-   v0.3.0 zip tar
-   v0.2.0 zip tar
-   v0.1.5 zip tar
-   v0.1.4 zip tar
-   v0.1.3 zip tar
-   v0.1.2 zip tar
-   v0.1.1 zip tar
-   v0.1.0 zip tar