Permalink
Browse files

rather than just EventMachineHelperMethods these are more Slanger rel…

…ated
  • Loading branch information...
1 parent b59d2e6 commit b15cc66cf7629ed7b5472017adeab4183a735f01 @markburns markburns committed May 13, 2012
@@ -0,0 +1,64 @@
+module SlangerHelperMethods
+ class HaveAttributes
+ attr_reader :messages, :attributes
+ def initialize attributes
+ @attributes = attributes
+ end
+
+ CHECKS = %w(first_event last_event last_data )
+
+ def matches?(messages)
+ @messages = messages
+ @failures = []
+
+ check_connection_established if attributes[:connection_established]
+ check_id_present if attributes[:id_present]
+
+ CHECKS.each { |a| attributes[a.to_sym] ? check(a) : true }
+
+ @failures.empty?
+ end
+
+ def check message
+ send(message) == attributes[message.to_sym] or @failures << message
+ end
+
+ def failure_message
+ @failures.map {|f| "expected #{f}: to equal #{attributes[f]} but got #{send(f)}"}.join "\n"
+ end
+
+ private
+
+ def check_connection_established
+ if first_event != 'pusher:connection_established'
+ @failures << :connection_established
+ end
+ end
+
+ def check_id_present
+ if messages.first['data']['socket_id'] == nil
+ @failures << :id_present
+ end
+ end
+
+ def first_event
+ messages.first['event']
+ end
+
+ def last_event
+ messages.last['event']
+ end
+
+ def last_data
+ messages.last['data']
+ end
+
+ def count
+ messages.length
+ end
+ end
+
+ def have_attributes attributes
+ HaveAttributes.new attributes
+ end
+end
@@ -1,5 +1,4 @@
-module EventMachineHelperMethods
-
+module SlangerHelperMethods
def start_slanger_with_options options={}
# Fork service. Our integration tests MUST block the main thread because we want to wait for i/o to finish.
@server_pid = EM.fork_reactor do
@@ -75,8 +74,8 @@ def stream websocket, messages
end
def auth_from options
- id = options[:message]['data']['socket_id']
- name = options[:name]
+ id = options[:message]['data']['socket_id']
+ name = options[:name]
user_id = options[:user_id]
Pusher['presence-channel'].authenticate(id, {user_id: user_id, user_info: {name: name}})
end
@@ -94,70 +93,4 @@ def private_channel websocket, message
auth: auth } }.to_json)
end
-
- class HaveAttributes
- attr_reader :messages, :attributes
- def initialize attributes
- @attributes = attributes
- end
-
- CHECKS = %w(first_event last_event last_data )
-
- def matches?(messages)
- @messages = messages
- @failures = []
-
- check_connection_established if attributes[:connection_established]
- check_id_present if attributes[:id_present]
-
- CHECKS.each { |a| attributes[a.to_sym] ? check(a) : true }
-
- @failures.empty?
- end
-
- def check message
- send(message) == attributes[message.to_sym] or @failures << message
- end
-
- def failure_message
- @failures.map {|f| "expected #{f}: to equal #{attributes[f]} but got #{send(f)}"}.join "\n"
- end
-
- private
-
- def check_connection_established
- if first_event != 'pusher:connection_established'
- @failures << :connection_established
- end
- end
-
- def check_id_present
- if messages.first['data']['socket_id'] == nil
- @failures << :id_present
- end
- end
-
- def first_event
- messages.first['event']
- end
-
- def last_event
- messages.last['event']
- end
-
- def last_data
- messages.last['data']
- end
-
- def count
- messages.length
- end
- end
-
- def have_attributes attributes
- HaveAttributes.new attributes
- end
end
-
-
-
View
@@ -6,7 +6,8 @@
require 'em-http-request'
require 'pusher'
require 'thin'
-require 'event_machine_helper_methods'
+require 'slanger_helper_methods'
+require 'have_attributes'
require 'openssl'
require 'socket'
require 'simplecov'
@@ -19,7 +20,7 @@ def errback
end
RSpec.configure do |config|
- config.include EventMachineHelperMethods
+ config.include SlangerHelperMethods
config.fail_fast = true
config.after(:each) { stop_slanger }
config.before :all do

0 comments on commit b15cc66

Please sign in to comment.