tristandunn/pusher-fake

Thin Server Not Starting Fake

Closed this issue · 4 comments

I'm doing something wrong here... hopefully something simple. I'm try to run the pusher-fake in development with the rails s command. I'm running rails 4.2.9 with pusher-fake 1.8.0 and pusher 0.18.0.

In my config/environments/development.rb, I have:

  require 'pusher'
  
  # 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"
  PusherFake.configuration.verbose = true
  PusherFake.configuration.logger  = Rails.logger

In my application code I have:

    <%- if defined?(PusherFake) -%>
      var pusher = <%= PusherFake.javascript %>;
    <%- else -%>
      var PusherOptions = { encrypted: <%= Settings.pusher.encrypted %> };
      var pusher = new Pusher('<%= Settings.pusher.key %>', PusherOptions);
      pusher.port = 443;
    <%- end -%>

When I start the server with rails s, I get:

=> Booting Thin
=> Rails 4.2.9 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Thin web server (v1.7.2 codename Bachmanity)
Maximum connections set to 1024
Listening on localhost:3000, CTRL+C to stop

Notice there is no mention of the pusher-fake running.

When I try to run it in irb (bundle exec irb), then:

require 'pusher'
Pusher.app_id = "MY_TEST_ID"
Pusher.key    = "MY_TEST_KEY"
Pusher.secret = "MY_TEST_SECRET"
require "pusher-fake/support/base"

I get this error:

NameError: uninitialized constant PusherFake
Did you mean?  Pusher

What am I missing?

The uninitialized constant error is because you need to require "pusher-fake". When running bundle exec irb it's not actually loading anything from your Gemfile. If you have the dependency in the test group, then it also won't work if you run bundle exec rails console unless you run RAILS_ENV=test bundle exec rails console.

Perhaps I should add require "pusher-fake" to the base support file, instead of assuming it's being loaded elsewhere. Not sure, since that could also be confusing in some cases.

That being said, it seems like you should be seeing the same error when running the server. Can you provide the group and line for pusher-fake in your Gemfile?

You are correct.

I fixed the problem by putting require 'pusher-fake' before the require 'pusher-fake/support/base'

Additionally I had to escape the html in the application:

      var pusher = <%= PusherFake.javascript.html_safe %>;

@debaillie Awesome. Let me know if I can help out with anything else.

FYI added a warning for this case: 29d2e4c