test/pocket/article_test.rb in pocket-ruby-0.2.1 vs test/pocket/article_test.rb in pocket-ruby-0.3.0

- old
+ new

@@ -38,10 +38,15 @@ test "excerpt" do assert_include article.excerpt, "list of things" end + test "excerpt is nil if field not present" do + parsed_response.delete("excerpt") + assert_nil article.excerpt + end + test "article?" do assert article.article? end test "has_image?" do @@ -62,10 +67,15 @@ test "word_count" do assert_equal 3197, article.word_count end + test "word_count is nil is field not present" do + parsed_response.delete("word_count") + assert_nil article.word_count + end + test "resolved_id" do assert_equal 229279689, article.resolved_id end test "thumbnail" do @@ -148,9 +158,47 @@ end test "authors returns an empty array if there are no tags" do parsed_response.delete("authors") assert_equal [], article.authors + end + + test "time_to_read" do + assert_equal 14, article.time_to_read + end + + test "time_to_read returns nil if field not present" do + parsed_response.delete("time_to_read") + assert_nil article.time_to_read + end + + test "time_to_read returns nil if value is 0" do + parsed_response["time_to_read"] = 0 + assert_nil article.time_to_read + end + + test "time_to_read_category" do + parsed_response.delete("time_to_read") + assert_nil article.time_to_read_category + + parsed_response["time_to_read"] = 0 + assert_nil article.time_to_read_category + + parsed_response["time_to_read"] = 25 + assert_equal "very_long", article.time_to_read_category + + parsed_response["time_to_read"] = 15 + assert_equal "long", article.time_to_read_category + + parsed_response["time_to_read"] = 8 + assert_equal "medium", article.time_to_read_category + + parsed_response["time_to_read"] = 3 + assert_equal "quick", article.time_to_read_category + end + + test "domain_metadata" do + assert_equal "The Verge", article.domain_metadata.name end private def article