Created
June 30, 2015 18:31
-
-
Save daniel-nelson/18465dd73a2e8f5baff0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
After adding pubsub (using Pubnub.com) to our application, our headless specs were straight up breaking. Solved by creating a mock that we can trigger within the specs | |
Coffeescript required by application.js manifest: | |
class PubsubMock | |
subscribe: (obj) -> | |
@channels ||= {} | |
@channels[obj.channel] ||= [] | |
@channels[obj.channel].push(obj.message) | |
publish: (channel, message) -> | |
for callback in @channels[channel] | |
callback(message) | |
window.pubsub_listener ||= new PubsubMock() | |
spec/support/pubsub_mock.rb | |
module PubsubMock | |
def pubsub_publish(channel, message) | |
script = "window.pubsub_listener.publish('#{channel}', '#{message.to_json}')" | |
page.execute_script(script) | |
end | |
end | |
In a feature spec: | |
pubsub_publish('some channel', pubsub_address: user.pubsub_address, event: 'some event') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment