spec/unit/post_spec.rb in ayadn-1.8.2 vs spec/unit/post_spec.rb in ayadn-2.0

- old
+ new

@@ -14,17 +14,18 @@ name: :yellow, source: :blue, symbols: :green, index: :blue, date: :cyan, - link: :magenta + link: :magenta, + excerpt: :green }, timeline: { - show_real_name: true, - show_date: true, - show_symbols: true, - show_source: true + name: true, + date: true, + symbols: true, + source: true }, formats: {table: {width: 75}}, counts: { default: 33 } @@ -66,58 +67,68 @@ x = post.post({text: 'whatever'}) expect(x['data']['text']).to eq 'TEST' end end - describe "#text_is_empty?" do - it "checks if empty" do - expect(post.text_is_empty?(["allo"])).to be false - expect(post.text_is_empty?([""])).to be true - expect(post.text_is_empty?([])).to be true - end - end - describe "#markdown_extract" do it "splits markdown" do expect(post.markdown_extract("[ayadn](http://ayadn-app.net)")).to eq ["ayadn", "http://ayadn-app.net"] end end - describe "#get_markdown_text" do + describe "#keep_text_from_markdown_links" do it "extracts markdown text" do - expect(post.get_markdown_text("[ayadn](http://ayadn-app.net)")).to eq "ayadn" + expect(post.keep_text_from_markdown_links("[ayadn](http://ayadn-app.net)")).to eq "ayadn" end end - describe "#post_size" do - it "tests if size of post string is ok" do - printed = capture_stderr do - expect(lambda {post.post_size("Black malt berliner weisse, filter. Ibu degrees plato alcohol. ipa hard cider ester infusion conditioning tank. Dry stout bottom fermenting yeast wort chiller wort chiller lager hand pump ! All-malt dunkle bright beer grainy, original gravity wheat beer glass.")}).to raise_error(SystemExit) - end - expect(printed).to include 'Canceled: too long. 256 max, 4 characters to remove.' + describe "#post_size_ok?" do + it "checks excessive post length" do + expect(post.post_size_ok?(["1" * 257].join())).to eq false end - end - - describe "#check_post_length" do - it "checks normal post length" do - expect(post.check_post_length(["allo", "wtf"])).to be nil #no error + it "checks excessive post length with markdown" do + expect(post.post_size_ok?(["1" * 251, "[aya.io](http://aya.io)"].join())).to eq false end + it "checks empty post length" do + expect(post.post_size_ok?("")).to eq false + end + it "checks full post length" do + expect(post.post_size_ok?(["1" * 256].join())).to eq true + end + it "checks full post length" do + expect(post.post_size_ok?(["Y😈" * 128].join())).to eq true + end it "checks excessive post length" do - printed = capture_stderr do - expect(lambda {post.check_post_length(["allo", "wtf dude", "ok whatever pfff", "Black malt berliner weisse, filter. Ibu degrees plato alcohol. ipa hard cider ester infusion conditioning tank. Dry stout bottom fermenting yeast wort chiller wort chiller lager hand pump ! All-malt dunkle bright beer grainy, original gravity wheat beer glass."])}).to raise_error(SystemExit) - end - expect(printed).to include 'Canceled: too long. 256 max, 32 characters to remove.' + expect(post.post_size_ok?(["😈" * 257].join())).to eq false end + it "checks post length" do + expect(post.post_size_ok?(["."].join())).to eq true + end + it "checks full post length" do + expect(post.post_size_ok?(["1\n" * 128].join())).to eq true + end + it "checks excessive post length" do + expect(post.post_size_ok?(["1\n" * 128, "\n"].join())).to eq false + end + it "checks full post length with markdown" do + expect(post.post_size_ok?(["1" * 250, "[aya.io](http://aya.io)"].join())).to eq true + end end - describe "#check_message_length" do + describe "#message_size_ok?" do it "checks normal message length" do - expect(post.check_message_length(["allo", "wtf"])).to be nil #no error + expect(post.message_size_ok?(["1" * 2048].join())).to eq true end + it "checks normal message length with markdown" do + expect(post.message_size_ok?(["1" * 2042, "[aya.io](http://aya.io)"].join())).to eq true + end + it "checks empty message length" do + expect(post.message_size_ok?("")).to eq false + end it "checks excessive message length" do - printed = capture_stderr do - expect(lambda {post.check_message_length(["Black malt berliner weisse, filter. Ibu degrees plato alcohol. ipa hard cider ester infusion conditioning tank. Dry stout bottom fermenting yeast wort chiller wort chiller lager hand pump ! All-malt dunkle bright beer grainy, original gravity wheat beer glass!!" * 8])}).to raise_error(SystemExit) - end - expect(printed).to include 'Canceled: too long. 2048 max, 40 characters to remove.' + expect(post.message_size_ok?(["1" * 2049].join())).to eq false + end + it "checks excessive message length with markdown" do + expect(post.message_size_ok?(["1" * 2043, "[aya.io](http://aya.io)"].join())).to eq false end end end