spec/unit/post_spec.rb in ayadn-1.0.1 vs spec/unit/post_spec.rb in ayadn-1.0.2
- old
+ new
@@ -34,63 +34,41 @@
username: 'test',
handle: '@test'
},
post_max_length: 256,
message_max_length: 2048,
- version: Ayadn::VERSION
+ version: 'wee'
})
- Ayadn::Settings.stub(:user_token).and_return('XXX')
+ Ayadn::Settings.stub(:user_token).and_return('XYZ')
+ Ayadn::Settings.stub(:check_for_accounts)
Ayadn::Errors.stub(:warn).and_return("warned")
Ayadn::Logs.stub(:rec).and_return("logged")
end
let(:post) { Ayadn::Post.new }
+ let(:rest) {Ayadn::CNX = double} #verbose in RSpec output, but useful
describe "#post" do
+ before do
+ rest.stub(:post).and_return(File.read("spec/mock/posted.json"))
+ end
it "should raise an error if args are empty" do
printed = capture_stdout do
post.post([])
end
expect(printed).to include "You should provide some text."
end
+ it "posts a post" do
+ expect(rest).to receive(:post).with("https://alpha-api.app.net/stream/0/posts/?include_annotations=1&access_token=XYZ", {"text"=>"YOLO", "entities"=>{"parse_markdown_links"=>true, "parse_links"=>true}, "annotations"=>[{"type"=>"com.ayadn.user", "value"=>{"+net.app.core.user"=>{"user_id"=>"@test", "format"=>"basic"}}}, {"type"=>"com.ayadn.client", "value"=>{"url"=>"http://ayadn-app.net", "author"=>{"name"=>"Eric Dejonckheere", "username"=>"ericd", "id"=>"69904", "email"=>"eric@aya.io"}, "version"=>"wee"}}]})
+ x = post.post(['YOLO'])
+ end
+ it "returns the posted post" do
+ x = post.post(['whatever'])
+ expect(x['data']['text']).to eq 'TEST'
+ end
end
- # let(:rest) {RestClient = double}
- # let(:res) {response = double}
- # let(:db) {Ayadn::Databases = double}
-
- # describe "#post" do
- # before do
- # db.stub(:blacklist) {"x"}
- # res.stub(:code) {200}
- # rest.stub(:post) {File.read("spec/mock/posted.json")}
- # end
- # # Those 2 tests return a fake response, but this fake
- # # response wouldn't be returned if the tests failed
- # # I should intercept what goes into the fake RestClient
- # # instead, but have no idea how to do it at the moment ¯\(ツ)/¯
- # #
- # # As their warning messages are pretty annoying, I disabled
- # # them but you can uncomment to run the test
- # it "sends a post" do
- # a = post.post(["TEST"])
- # printed = capture_stdout do
- # Ayadn::View.new.show_posted(a)
- # end
- # expect(printed).to include '@aya_tests'
- # expect(printed).to include 'TEST'
- # end
- # it "sends a message" do
- # a = post.send_message(666, 'TEST')
- # printed = capture_stdout do
- # Ayadn::View.new.show_posted(a)
- # end
- # expect(printed).to include '@aya_tests'
- # expect(printed).to include 'TEST'
- # end
- # end
-
describe "#reply" do
it "formats a reply" do
new_post = "Hey guys!"
replied_to = {1=>{:handle => "@test",:username => "test", :mentions => ["user1", "user2"]}}
post.reply(new_post, replied_to).should eq "@test Hey guys! @user1 @user2"
@@ -123,14 +101,25 @@
describe "#check_post_length" do
it "checks normal post length" do
post.check_post_length(["allo", "wtf"]).should be nil #no error
end
+ it "checks excessive post length" do
+ printed = capture_stderr do
+ 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."])}.should raise_error(SystemExit)
+ end
+ expect(printed).to include 'Canceled: too long. 256 max, 32 characters to remove.'
+ end
end
describe "#check_message_length" do
it "checks normal message length" do
post.check_message_length(["allo", "wtf"]).should be nil #no error
end
+ it "checks excessive message length" do
+ printed = capture_stderr do
+ 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])}.should raise_error(SystemExit)
+ end
+ expect(printed).to include 'Canceled: too long. 2048 max, 40 characters to remove.'
+ end
end
-
end