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 5
def initialize(attributes)
  @attributes = attributes
end

Public Instance Methods

check(message) click to toggle source
# File spec/have_attributes.rb, line 23
def check(message)
  send(message) == attributes[message.to_sym] or @failures << message
end
check_connection_established() click to toggle source

private

# File spec/have_attributes.rb, line 33
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 39
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 57
def count
  messages.length
end
failure_message() click to toggle source
# File spec/have_attributes.rb, line 27
def failure_message
  @failures.map { |f| "expected #{f}: to equal #{attributes[f]} but got #{send(f)}" }.join "\n"
end
first_event() click to toggle source
# File spec/have_attributes.rb, line 45
def first_event
  messages.first["event"]
end
last_data() click to toggle source
# File spec/have_attributes.rb, line 53
def last_data
  messages.last["data"]
end
last_event() click to toggle source
# File spec/have_attributes.rb, line 49
def last_event
  messages.last["event"]
end
matches?(messages) click to toggle source
# File spec/have_attributes.rb, line 11
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