spec/models/concerns/publishable_spec.rb in reactor-0.8.2 vs spec/models/concerns/publishable_spec.rb in reactor-0.8.3

- old
+ new

@@ -26,58 +26,58 @@ @@called = true end end describe Reactor::Publishable do - before { TestSubscriber.destroy_all } + before do + TestSubscriber.destroy_all + TestSubscriber.class_variable_set(:@@called, false) + end + describe 'publish' do let(:pet) { Pet.create! } let(:auction) { Auction.create!(pet: pet, start_at: DateTime.new(2012,12,21)) } it 'publishes an event with actor_id and actor_type set as self' do auction - expect(Reactor::Event).to receive(:publish) do |name, data| - expect(name).to eq(:an_event) - expect(data[:what]).to eq('the') - expect(data[:actor]).to eq(auction) - end + expect(Reactor::Event).to receive(:publish).with(:an_event, what: 'the', actor: auction) auction.publish(:an_event, {what: 'the'}) end it 'publishes an event with provided actor and target methods' do - expect(Reactor::Event).to receive(:publish) do |name, data| - expect(name).to eq(:woof) - expect(data[:actor]).to eq(pet) - end + allow(Reactor::Event).to receive(:publish).exactly(5).times auction + expect(Reactor::Event).to have_received(:publish).with(:woof, a_hash_including(actor: pet, target: auction)) end it 'reschedules an event when the :at time changes' do start_at = auction.start_at new_start_at = start_at + 1.week expect(Reactor::Event).to receive(:reschedule).with :ring, anything - expect(Reactor::Event).to receive(:reschedule).with :begin, - hash_including( + expect(Reactor::Event).to receive(:reschedule).with(:begin, + a_hash_including( at: new_start_at, actor: auction, was: start_at, additional_info: 'curtis was here' ) + ) auction.start_at = new_start_at auction.save! end it 'reschedules an event when the :watch field changes' do ring_time = auction.ring_timeout new_start_at = auction.start_at + 1.week new_ring_time = new_start_at + 30.seconds expect(Reactor::Event).to receive(:reschedule).with :begin, anything - expect(Reactor::Event).to receive(:reschedule).with :ring, - hash_including( + expect(Reactor::Event).to receive(:reschedule).with(:ring, + a_hash_including( at: new_ring_time, actor: auction, was: ring_time ) + ) auction.start_at = new_start_at auction.save! end it 'supports immediate events (on create) that get fired once' do