spec/sms_spec.rb in mblox-0.0.2 vs spec/sms_spec.rb in mblox-0.0.3

- old
+ new

@@ -31,38 +31,61 @@ it "will be truncated when the message is longer than 160 characters if configured to do so" do message = "A"+"ABCDEFGHIJ"*16 Mblox.config.on_message_too_long = :truncate expect { @mblox = Mblox::Sms.new("2"*10, message) }.to_not raise_error - expect(@mblox.message).to eq(message[0,160]) + expect(@mblox.message).to eq([message[0,160]]) end it "cannot be longer than 160 characters if configured to raise error" do Mblox.config.on_message_too_long = :raise_error expect { Mblox::Sms.new("2"*10, "A"*161) }.to raise_error(Mblox::SmsError, "Message cannot be longer than 160 characters") end - it "should be safe from changing" do + it "should be split into multiple messages when longer than 160 characters if configured to split and even split" do + message = "ABCDEFGHIJ"*58 + Mblox.config.on_message_too_long = :split + expect { @mblox = Mblox::Sms.new("2"*10, message) }.to_not raise_error + expect(@mblox.message).to eq(["(MSG 1/4): #{message[0,145]}", "(MSG 2/4): #{message[145,145]}", "(MSG 3/4): #{message[290,145]}", "(MSG 4/4): #{message[435,145]}"]) + expect(@mblox.send).to eq(Array.new(4, result_unroutable)) + end + + it "should be split into multiple messages when longer than 160 characters if configured to split and not even split" do + message = "ABCDEFGHIJ"*32 + Mblox.config.on_message_too_long = :split + expect { @mblox = Mblox::Sms.new("2"*10, message) }.to_not raise_error + expect(@mblox.message).to eq(["(MSG 1/3): #{message[0,145]}", "(MSG 2/3): #{message[145,145]}", "(MSG 3/3): #{message[290..-1]}"]) + expect(@mblox.send).to eq(Array.new(3, result_unroutable)) + end + + it "should be safe from changing when short" do msg = the_message mblox = Mblox::Sms.new(TEST_NUMBER,msg) msg[1..3] = '' - expect(mblox.message).to eq(the_message) + expect(mblox.message).to eq([the_message]) end + + it "should be safe from changing when long" do + msg = the_message * 10 + mblox = Mblox::Sms.new(TEST_NUMBER,msg) + msg[1..3] = '' + expect(mblox.message[0][11, 20]).to eq(the_message[0,20]) + end end describe "SMS messages" do it "should be sent when the phone number is a Fixnum" do - expect(Mblox::Sms.new(TEST_NUMBER.to_i,the_message).send).to eq(result_ok) + expect(Mblox::Sms.new(TEST_NUMBER.to_i,the_message).send).to eq([result_ok]) end it "should be sent when the phone number is a String" do - expect(Mblox::Sms.new(TEST_NUMBER.to_s,the_message).send).to eq(result_ok) + expect(Mblox::Sms.new(TEST_NUMBER.to_s,the_message).send).to eq([result_ok]) end it "should allow 160-character messages" do - expect(Mblox::Sms.new(TEST_NUMBER,"A"*160).send).to eq(result_ok) + expect(Mblox::Sms.new(TEST_NUMBER,"A"*160).send).to eq([result_ok]) end it "should fail when sent to a landline" do - expect(Mblox::Sms.new("6176354500",the_message).send).to eq(result_unroutable) + expect(Mblox::Sms.new("6176354500",the_message).send).to eq([result_unroutable]) end end