spec/acceptance/realtime/channel_history_spec.rb in ably-0.2.0 vs spec/acceptance/realtime/channel_history_spec.rb in ably-0.6.2

- old
+ new

@@ -2,11 +2,11 @@ require 'securerandom' describe Ably::Realtime::Channel do include RSpec::EventMachine - [:msgpack, :json].each do |protocol| + [:json].each do |protocol| # :msgpack, context "over #{protocol}" do let(:default_options) { options.merge(api_key: api_key, environment: environment, protocol: protocol) } let(:client) do Ably::Realtime::Client.new(default_options) @@ -22,53 +22,65 @@ let(:payload) { SecureRandom.hex(4) } let(:messages) { [] } let(:options) { { :protocol => :json } } - it 'retrieves real-time history' do + it 'returns a Deferrable' do run_reactor do channel.publish('event', payload) do |message| - history = channel.history - expect(history.length).to eql(1) - expect(history[0].data).to eql(payload) + expect(channel.history).to be_a(EventMachine::Deferrable) stop_reactor end end end + it 'retrieves real-time history' do + run_reactor do + channel.publish('event', payload) do |message| + channel.history do |history| + expect(history.length).to eql(1) + expect(history[0].data).to eql(payload) + stop_reactor + end + end + end + end + it 'retrieves real-time history across two channels' do run_reactor do channel.publish('event', payload) do |message| channel2.publish('event', payload) do |message| - history = channel2.history - expect(history.length).to eql(2) - expect(history.map(&:data).uniq).to eql([payload]) - stop_reactor + channel2.history do |history| + expect(history.length).to eql(2) + expect(history.map(&:data).uniq).to eql([payload]) + stop_reactor + end end end end end context 'with multiple messages' do let(:messages_sent) { 20 } let(:limit) { 10 } def check_limited_history(direction) - history = channel.history(direction: direction, limit: limit) - expect(history.length).to eql(limit) - limit.times do |index| - expect(history[index].data).to eql("history#{index}") - end + channel.history(direction: direction, limit: limit) do |history| + expect(history.length).to eql(limit) + limit.times do |index| + expect(history[index].data).to eql("history#{index}") + end - history = history.next_page + history.next_page do |history| + expect(history.length).to eql(limit) + limit.times do |index| + expect(history[index].data).to eql("history#{index + limit}") + end + expect(history.last_page?).to eql(true) - expect(history.length).to eql(limit) - limit.times do |index| - expect(history[index].data).to eql("history#{index + limit}") + stop_reactor + end end - expect(history.last_page?).to eql(true) - - stop_reactor end context 'as one ProtocolMessage' do it 'retrieves limited history forwards with pagination' do run_reactor(5) do