A fake Pusher server for development and testing.
It's intended to fully replace the Pusher service with a local version for testing, but can also be used for development purposes. It is not intended to be a replacement for production usage.
<script>
<% 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 %>
</script>
require "pusher-fake/support/rspec"
require "pusher-fake/support/cucumber"
require "pusher-fake/support/base"
# Reset the channels after each test:
PusherFake::Channel.reset
In a Rails initializer, or any file executed during loading:
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:
if ENV["PUSHER_FAKE"]
require "pusher-fake/support/base"
end
web: PUSHER_FAKE=1 bundle exec unicorn ...
worker: bundle exec ...
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
end
- pusher-fake-example - An example of using pusher-fake with Cucumber to test a Rails application.
Fully recreate the Pusher API service for development and testing.
- Using a remote API for testing is slow.
- Working offline is currently impossible.
- Wasting connections and messages in development is unreasonable.
- Stubbing the JavaScript, such as with pusher-test-stub, is suboptimal and tedious for integration tests.
pusher-fake uses the MIT license. See LICENSE for more details.