refactor: message_body into rantly extension

Phillip Davis created

Change summary

test/property/rantly_extensions/data_extensions.rb |  7 +++++++
test/property/test_badwords.rb                     |  6 +-----
test/property/test_invisible_separator.rb          | 10 ++--------
test/property/test_non_nanp_oob.rb                 |  8 ++------
test/property/test_to_catapult.rb                  |  6 +-----
5 files changed, 13 insertions(+), 24 deletions(-)

Detailed changes

test/property/rantly_extensions/data_extensions.rb 🔗

@@ -103,6 +103,13 @@ class Rantly
 				)
 			end
 
+			# @return [String]
+			def message_body
+				words = array(range(1, 6)) { sized(range(3, 10)) { string(:alnum) } }
+				guard(words.none? { |w| BADWORD_LIST.include?(w.downcase) })
+				words.join(" ")
+			end
+
 			# @return [String]
 			def media_url
 				user_id = sized(range(3, 10)) { string(:alnum) }

test/property/test_badwords.rb 🔗

@@ -53,12 +53,8 @@ class BadwordsPropertyTest < Minitest::Test
 
 	def test_message_without_badwords_is_not_rejected_as_unavailable
 		property_of {
-			words = array(range(1, 6)) { sized(range(3, 10)) { string(:alnum) } }
-			guard(words.none? { |w| BADWORD_LIST.include?(w.downcase) })
-			body = words.join(" ")
-
 			dest = nanpa_phone
-			[body, dest]
+			[message_body, dest]
 		}.check { |body, dest|
 			reset_stanzas!
 			reset_redis!

test/property/test_invisible_separator.rb 🔗

@@ -17,9 +17,7 @@ class InvisibleSeparatorPropertyTest < Minitest::Test
 
 	def test_message_containing_invisible_separator_is_rejected
 		property_of {
-			words = array(range(1, 6)) { sized(range(3, 10)) { string(:alnum) } }
-			guard(words.none? { |w| BADWORD_LIST.include?(w.downcase) })
-			chars = words.join(" ").chars
+			chars = message_body.chars
 			insertions = range(1, 3)
 			insertions.times { chars.insert(range(0, chars.length), "\u2063") }
 			body = chars.join
@@ -53,12 +51,8 @@ class InvisibleSeparatorPropertyTest < Minitest::Test
 
 	def test_message_without_invisible_separator_is_not_rejected_as_unavailable
 		property_of {
-			words = array(range(1, 6)) { sized(range(3, 10)) { string(:alnum) } }
-			guard(words.none? { |w| BADWORD_LIST.include?(w.downcase) })
-			body = words.join(" ")
-
 			dest = nanpa_phone
-			[body, dest]
+			[message_body, dest]
 		}.check { |body, dest|
 			reset_stanzas!
 			reset_redis!

test/property/test_non_nanp_oob.rb 🔗

@@ -23,11 +23,9 @@ class NonNanpOobPropertyTest < Minitest::Test
 	def test_non_nanp_oob_sends_url_as_text_not_mms
 		property_of {
 			dest = non_nanp_phone
-			body = choose("", sized(range(5, 40)) { string(:alnum) })
-			guard(!body.downcase.match?(BADWORDS))
 			oob_path = sized(range(3, 12)) { string(:alnum) }
 			oob_url = "https://example.com/media/#{oob_path}.jpg"
-			[dest, body, oob_url]
+			[dest, message_body, oob_url]
 		}.check { |dest, body, oob_url|
 			reset_stanzas!
 			reset_redis!
@@ -54,11 +52,9 @@ class NonNanpOobPropertyTest < Minitest::Test
 	def test_nanp_oob_attempts_mms
 		property_of {
 			dest = nanpa_phone
-			body = sized(range(5, 40)) { string(:alnum) }
-			guard(!body.downcase.match?(BADWORDS))
 			oob_path = sized(range(3, 12)) { string(:alnum) }
 			oob_url = "https://example.com/media/#{oob_path}.jpg"
-			[dest, body, oob_url]
+			[dest, message_body, oob_url]
 		}.check { |dest, body, oob_url|
 			reset_stanzas!
 			reset_redis!

test/property/test_to_catapult.rb 🔗

@@ -11,15 +11,11 @@ class ToCatapultPropertyTest < Minitest::Test
 			dest = nanpa_phone
 			guard(dest != "+15550000000")
 
-			words = array(range(1, 4)) { sized(range(3, 8)) { string(:alnum) } }
-			guard(words.none? { |w| BADWORD_LIST.include?(w.downcase) })
-			body = words.join(" ")
-
 			stanza_id = maybe_http_escapable_string
 			resource = maybe_http_escapable_string
 			status = choose(201, 202)
 
-			[dest, body, stanza_id, resource, status]
+			[dest, message_body, stanza_id, resource, status]
 		}.check { |dest, body, stanza_id, resource, status|
 			reset_stanzas!
 			reset_redis!