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

- old
+ new

@@ -11,23 +11,23 @@ name: :yellow, source: :blue, symbols: :green, index: :blue, date: :cyan, - link: :magenta + link: :magenta, + excerpt: :green }, timeline: { directed: 1, - deleted: 0, html: 0, annotations: 1, - show_source: true, - show_symbols: true, - show_real_name: true, - show_date: true, - show_spinner: true, - show_debug: false + source: true, + symbols: true, + name: true, + date: true, + spinner: true, + debug: false }, formats: { table: {width: 75}, list: {reverse: true} }, @@ -60,19 +60,19 @@ }, nicerank: { threshold: 2.1, cache: 48, filter: true, - filter_unranked: false + unranked: false }, backup: { - auto_save_sent_posts: false, - auto_save_sent_messages: false, - auto_save_lists: false + posts: false, + messages: false, + lists: false }, marker: { - update_messages: true + messages: true } }) Ayadn::Settings.stub(:config).and_return({ identity: { username: 'test', @@ -81,11 +81,10 @@ post_max_length: 256, message_max_length: 2048, version: 'wee', paths: { db: 'spec/mock/', - pagination: 'spec/mock/', log: 'spec/mock' } }) Ayadn::Settings.stub(:user_token).and_return('XYZ') Ayadn::Settings.stub(:load_config) @@ -111,10 +110,32 @@ Ayadn::SetScroll.new.timer('johnson') expect(Ayadn::Settings.options[:scroll][:timer]).to eq 3 end end + describe "#spinner" do + it "creates a default value" do + Ayadn::SetScroll.new.spinner('true') + expect(Ayadn::Settings.options[:scroll][:spinner]).to eq true + Ayadn::SetScroll.new.spinner('false') + expect(Ayadn::Settings.options[:scroll][:spinner]).to eq false + Ayadn::SetScroll.new.spinner('0') + expect(Ayadn::Settings.options[:scroll][:spinner]).to eq false + end + end + + describe "#date" do + it "creates a default value" do + Ayadn::SetScroll.new.date('true') + expect(Ayadn::Settings.options[:scroll][:date]).to eq true + Ayadn::SetScroll.new.date('false') + expect(Ayadn::Settings.options[:scroll][:date]).to eq false + Ayadn::SetScroll.new.date('0') + expect(Ayadn::Settings.options[:scroll][:date]).to eq false + end + end + after do File.delete('spec/mock/ayadn.log') end end @@ -164,14 +185,13 @@ it "creates a default list order" do Ayadn::SetFormats.new.send(:list, ['reverse', 'false']) expect(Ayadn::Settings.options[:formats][:list][:reverse]).to eq false end it "raises an error" do - printed = capture_stderr do + printed = capture_stdout do expect(lambda {Ayadn::SetFormats.new.send(:list, ['reverse', 'yolo'])}).to raise_error(SystemExit) end - expect(printed).to include 'You have to submit valid items' end end after do File.delete('spec/mock/ayadn.log') @@ -183,26 +203,18 @@ init_stubs end describe "#" do it "creates a default value" do - %w{directed html show_source show_symbols show_real_name show_date show_spinner show_debug compact}.each do |meth| + %w{directed source symbols name date debug compact}.each do |meth| command = meth.to_sym Ayadn::SetTimeline.new.send(command, 'true') expect(Ayadn::Settings.options[:timeline][command]).to eq true - printed = capture_stderr do + printed = capture_stdout do expect(lambda {Ayadn::SetTimeline.new.send(command, 'yolo')}).to raise_error(SystemExit) end - expect(printed).to include 'You have to submit valid items' end - ['deleted', 'annotations'].each do |meth| - command = meth.to_sym - printed = capture_stderr do - expect(lambda {Ayadn::SetTimeline.new.send(command, 'false')}).to raise_error(SystemExit) - end - expect(printed).to include 'This parameter is not modifiable' - end end end after do File.delete('spec/mock/ayadn.log') @@ -218,47 +230,28 @@ it "creates a default value" do %w{default unified global checkins conversations photos trending mentions convo posts messages search whoreposted whostarred whatstarred files}.each do |meth| command = meth.to_sym Ayadn::SetCounts.new.send(command, '199') expect(Ayadn::Settings.options[:counts][command]).to eq 199 - printed = capture_stderr do - expect(lambda {Ayadn::SetCounts.new.send(command, '333')}).to raise_error(SystemExit) + printed = capture_stdout do + Ayadn::SetCounts.new.send(command, '333') end - expect(printed).to include 'This paramater must be an integer between 1 and 200' end end end - - describe "#validate" do - it "raises error if incorrect count value" do - printed = capture_stderr do - expect(lambda {Ayadn::SetCounts.new.validate('0')}).to raise_error(SystemExit) - end - expect(printed).to include 'This paramater must be an integer between 1 and 200' - end - it "raises error if incorrect count value" do - printed = capture_stderr do - expect(lambda {Ayadn::SetCounts.new.validate('yolo')}).to raise_error(SystemExit) - end - expect(printed).to include 'This paramater must be an integer between 1 and 200' - end - end - after do - File.delete('spec/mock/ayadn.log') - end end describe Ayadn::SetMarker do before do init_stubs end - describe "#update_messages" do + describe "#messages" do it "creates a default value" do - expect(Ayadn::Settings.options[:marker][:update_messages]).to eq true - Ayadn::SetMarker.new.update_messages('0') - expect(Ayadn::Settings.options[:marker][:update_messages]).to eq false + expect(Ayadn::Settings.options[:marker][:messages]).to eq true + Ayadn::SetMarker.new.messages('0') + expect(Ayadn::Settings.options[:marker][:messages]).to eq false end end after do File.delete('spec/mock/ayadn.log') @@ -268,42 +261,41 @@ describe Ayadn::SetBackup do before do init_stubs end - describe "#auto_save_sent_posts" do + describe "#posts" do it "creates a default value" do - expect(Ayadn::Settings.options[:backup][:auto_save_sent_posts]).to eq false - Ayadn::SetBackup.new.auto_save_sent_posts('1') - expect(Ayadn::Settings.options[:backup][:auto_save_sent_posts]).to eq true + expect(Ayadn::Settings.options[:backup][:posts]).to eq false + Ayadn::SetBackup.new.posts('1') + expect(Ayadn::Settings.options[:backup][:posts]).to eq true end end - describe "#auto_save_sent_messages" do + describe "#messages" do it "creates a default value" do - expect(Ayadn::Settings.options[:backup][:auto_save_sent_messages]).to eq false - Ayadn::SetBackup.new.auto_save_sent_messages('True') - expect(Ayadn::Settings.options[:backup][:auto_save_sent_messages]).to eq true + expect(Ayadn::Settings.options[:backup][:messages]).to eq false + Ayadn::SetBackup.new.messages('True') + expect(Ayadn::Settings.options[:backup][:messages]).to eq true end end - describe "#auto_save_lists" do + describe "#lists" do it "creates a default value" do - expect(Ayadn::Settings.options[:backup][:auto_save_lists]).to eq false - Ayadn::SetBackup.new.auto_save_lists('YES') - expect(Ayadn::Settings.options[:backup][:auto_save_lists]).to eq true + expect(Ayadn::Settings.options[:backup][:lists]).to eq false + Ayadn::SetBackup.new.lists('YES') + expect(Ayadn::Settings.options[:backup][:lists]).to eq true end end describe "#validate" do it "validates a correct boolean" do value = Ayadn::SetBackup.new.validate('0') expect(value).to eq false end it "raises error if incorrect boolean" do - printed = capture_stderr do + printed = capture_stdout do expect(lambda {Ayadn::SetBackup.new.validate('yolo')}).to raise_error(SystemExit) end - expect(printed).to include "You have to submit valid items. See 'ayadn -sg' for a list of valid parameters and values" end end after do File.delete('spec/mock/ayadn.log') end @@ -350,54 +342,33 @@ expect(Ayadn::Settings.options[:nicerank][:threshold]).to eq 2.1 Ayadn::SetNiceRank.new.threshold('3') expect(Ayadn::Settings.options[:nicerank][:threshold]).to eq 3 Ayadn::SetNiceRank.new.threshold('3.2') expect(Ayadn::Settings.options[:nicerank][:threshold]).to eq 3.2 - printed = capture_stderr do - expect(lambda {Ayadn::SetNiceRank.new.threshold('6')}).to raise_error(SystemExit) - end - expect(printed).to include 'Please enter a value between 0.1 and 3.5, example: 2.1' - printed = capture_stderr do - expect(lambda {Ayadn::SetNiceRank.new.threshold('yolo')}).to raise_error(SystemExit) - end - expect(printed).to include 'Please enter a value between 0.1 and 3.5, example: 2.1' end end describe "#filter" do it "creates a new filter default" do expect(Ayadn::Settings.options[:nicerank][:filter]).to eq true Ayadn::SetNiceRank.new.filter('false') expect(Ayadn::Settings.options[:nicerank][:filter]).to eq false Ayadn::SetNiceRank.new.filter('1') expect(Ayadn::Settings.options[:nicerank][:filter]).to eq true - printed = capture_stderr do + printed = capture_stdout do expect(lambda {Ayadn::SetNiceRank.new.filter('6')}).to raise_error(SystemExit) end - expect(printed).to include "You have to submit valid items. See 'ayadn -sg' for a list of valid parameters and values." end end - describe "#filter_unranked" do - it "creates a new filter_unranked default" do - expect(Ayadn::Settings.options[:nicerank][:filter_unranked]).to eq false - Ayadn::SetNiceRank.new.filter_unranked('true') - expect(Ayadn::Settings.options[:nicerank][:filter_unranked]).to eq true - Ayadn::SetNiceRank.new.filter_unranked('0') - expect(Ayadn::Settings.options[:nicerank][:filter_unranked]).to eq false - printed = capture_stderr do - expect(lambda {Ayadn::SetNiceRank.new.filter_unranked('yolo')}).to raise_error(SystemExit) + describe "#unranked" do + it "creates a new unranked default" do + expect(Ayadn::Settings.options[:nicerank][:unranked]).to eq false + Ayadn::SetNiceRank.new.unranked('true') + expect(Ayadn::Settings.options[:nicerank][:unranked]).to eq true + Ayadn::SetNiceRank.new.unranked('0') + expect(Ayadn::Settings.options[:nicerank][:unranked]).to eq false + printed = capture_stdout do + expect(lambda {Ayadn::SetNiceRank.new.unranked('yolo')}).to raise_error(SystemExit) end - expect(printed).to include "You have to submit valid items. See 'ayadn -sg' for a list of valid parameters and values." - end - end - describe "#cache" do - it "creates a new cache default" do - expect(Ayadn::Settings.options[:nicerank][:cache]).to eq 48 - Ayadn::SetNiceRank.new.cache('72.4') - expect(Ayadn::Settings.options[:nicerank][:cache]).to eq 72 - printed = capture_stderr do - expect(lambda {Ayadn::SetNiceRank.new.cache('200')}).to raise_error(SystemExit) - end - expect(printed).to include "Please enter a number of hours between 1 and 168" end end after do File.delete('spec/mock/ayadn.log') end