class SlangerHelperMethods::HaveAttributes
Constants
- CHECKS
Attributes
attributes[R]
messages[R]
Public Class Methods
new(attributes)
click to toggle source
# File spec/have_attributes.rb, line 4 def initialize attributes @attributes = attributes end
Public Instance Methods
check(message)
click to toggle source
# File spec/have_attributes.rb, line 22 def check message send(message) == attributes[message.to_sym] or @failures << message end
failure_message()
click to toggle source
# File spec/have_attributes.rb, line 26 def failure_message @failures.map {|f| "expected #{f}: to equal #{attributes[f]} but got #{send(f)}"}.join "\n" end
matches?(messages)
click to toggle source
# File spec/have_attributes.rb, line 10 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
Private Instance Methods
check_connection_established()
click to toggle source
# File spec/have_attributes.rb, line 32 def check_connection_established if first_event != 'pusher:connection_established' @failures << :connection_established end end
check_id_present()
click to toggle source
# File spec/have_attributes.rb, line 38 def check_id_present if messages.first['data']['socket_id'] == nil @failures << :id_present end end
count()
click to toggle source
# File spec/have_attributes.rb, line 56 def count messages.length end
first_event()
click to toggle source
# File spec/have_attributes.rb, line 44 def first_event messages.first['event'] end
last_data()
click to toggle source
# File spec/have_attributes.rb, line 52 def last_data messages.last['data'] end
last_event()
click to toggle source
# File spec/have_attributes.rb, line 48 def last_event messages.last['event'] end