spec/unit/queue_spec.rb in fake_sqs-0.3.1 vs spec/unit/queue_spec.rb in fake_sqs-0.4.0

- old
+ new

@@ -30,20 +30,40 @@ options = { "MessageBody" => "abc" } expect(message_factory).to receive(:new).with(options) send_message(options) end + it "should set the message's SentTimestamp attribute" do + expect(send_message.attributes["SentTimestamp"]).to eq (Time.now.to_i * 1000) + end + + it "should set the SenderId of the sender" do + sender_id = send_message.attributes["SenderId"] + expect(sender_id).to be_a String + expect(sender_id.length).to eq 21 + end end describe "#receive_message" do it "gets the message" do sent = send_message received = receive_message expect(received.values.first).to eq sent end + it "gets the message with 'DelaySeconds' option" do + delay_seconds = 3 + sent = send_message({ "DelaySeconds" => delay_seconds }) + received = receive_message + expect(received.values.first).to be_nil + + allow(Time).to receive(:now).and_return(Time.now + delay_seconds) + received = receive_message + expect(received.values.first).to eq sent + end + it "gets you a random message" do indexes = { :first => 0, :second => 0 } sample_group = 1_000 half_sample_group = sample_group / 2 ten_percent = half_sample_group / 0.1 @@ -114,9 +134,28 @@ it "won't error on empty queues" do expect(receive_message).to eq({}) end + it "should increment the ApproximateReceiveCount" do + sent_message = send_message + expect(sent_message.attributes["ApproximateReceiveCount"]).to eq 0 + queue.change_message_visibility(receive_message.keys.first, 0) + expect(sent_message.attributes["ApproximateReceiveCount"]).to eq 1 + receive_message + expect(sent_message.attributes["ApproximateReceiveCount"]).to eq 2 + end + + it "should set the ApproximateFirstReceiveTimestamp only when the message is first received" do + sent_message = send_message + expect(sent_message.attributes["ApproximateFirstReceiveTimestamp"]).to eq nil + receive_time = (Time.now.to_i * 1000) + queue.change_message_visibility(receive_message.keys.first, 0) + expect(sent_message.attributes["ApproximateFirstReceiveTimestamp"]).to eq receive_time + sleep 1 + receive_message + expect(sent_message.attributes["ApproximateFirstReceiveTimestamp"]).to eq receive_time + end end describe "#delete_message" do it "deletes by the receipt" do