diff --git a/spec/lib/tasks/email_logger_spec.rb b/spec/lib/tasks/email_logger_spec.rb new file mode 100644 index 00000000..1f8d0c5d --- /dev/null +++ b/spec/lib/tasks/email_logger_spec.rb @@ -0,0 +1,22 @@ +require 'rails_helper' + + +RSpec.describe EmailLogger do + + describe "#format_message" do + subject { described_class.new(STDOUT) } + + it "returns message parameter as string with a newline appended" do + expect(subject.format_message(nil, nil, nil, 1001)).to eq "1001\n" + end + end + + + describe "constants" do + it do + expect(EMAIL_LOGGER.class).to eq EmailLogger + end + end + + skip "Add a test for code in module outside of class" +end diff --git a/spec/lib/tasks/null_virus_scanner_spec.rb b/spec/lib/tasks/null_virus_scanner_spec.rb new file mode 100644 index 00000000..b8be8763 --- /dev/null +++ b/spec/lib/tasks/null_virus_scanner_spec.rb @@ -0,0 +1,18 @@ +require 'rails_helper' + + +RSpec.describe NullVirusScanner do + + describe "#initialize" do + before { + allow(AbstractVirusScanner).to receive(:new).with "the file" + } + it "calls parent initialize method" do + expect(AbstractVirusScanner).to receive(:new).with "the file" + + NullVirusScanner.new("the file") + end + end + + +end \ No newline at end of file diff --git a/spec/lib/tasks/rack_multipart_buf_size_setter_spec.rb b/spec/lib/tasks/rack_multipart_buf_size_setter_spec.rb new file mode 100644 index 00000000..7015e88e --- /dev/null +++ b/spec/lib/tasks/rack_multipart_buf_size_setter_spec.rb @@ -0,0 +1,33 @@ +require 'rails_helper' + +class MockApp + def call(env) + end +end + + + +RSpec.describe RackMultipartBufSizeSetter do + + let(:rack_app) { MockApp.new } + subject { described_class.new(rack_app) } + + describe "#initialize" do + it "sets @app variable" do + rack = RackMultipartBufSizeSetter.new(rack_app) + + expect(rack.instance_variable_get(:@app)).to eq rack_app + end + end + + + describe "#call" do + envtest = {} + it "merges key and value into env hash and @app calls env" do + expect(rack_app).to receive(:call).with(Rack::RACK_MULTIPART_BUFFER_SIZE => 1024 * 1024) + + subject.call(envtest) + expect(envtest).to eq Rack::RACK_MULTIPART_BUFFER_SIZE => 1024 * 1024 + end + end +end diff --git a/spec/lib/tasks/task_logger_spec.rb b/spec/lib/tasks/task_logger_spec.rb new file mode 100644 index 00000000..1ee9531e --- /dev/null +++ b/spec/lib/tasks/task_logger_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' +require_relative '../../../lib/tasks/task_logger' + +RSpec.describe Deepblue::TaskLogger do + + describe "#format_message" do + subject { described_class.new(STDOUT) } + + it "returns message parameter as string with a newline appended" do + expect(subject.format_message(nil, nil, nil, "the message")).to eq "the message\n" + end + end + +end diff --git a/spec/lib/tasks/task_pacifier_spec.rb b/spec/lib/tasks/task_pacifier_spec.rb new file mode 100644 index 00000000..9a604f7a --- /dev/null +++ b/spec/lib/tasks/task_pacifier_spec.rb @@ -0,0 +1,164 @@ +require 'rails_helper' +require_relative '../../../lib/tasks/task_pacifier' + + +RSpec.describe Deepblue::TaskPacifier do + + subject { described_class.new(out: STDOUT, count_nl: 100) } + + describe "#initialize" do + it "sets instance variables" do + pacifier = Deepblue::TaskPacifier.new(out: STDOUT, count_nl: 100) + + expect(pacifier.instance_variable_get(:@out)).to eq STDOUT + expect(pacifier.instance_variable_get(:@count)).to eq 0 + expect(pacifier.instance_variable_get(:@count_nl)).to eq 100 + expect(pacifier.instance_variable_get(:@active)).to eq true + end + end + + + describe "#active?" do + it "returns the value of @active" do + expect(subject.active?).to eq true + end + end + + + describe "#pacify" do + context "when @active is false" do + before { + subject.instance_variable_set(:@active, false) + } + it "returns nil" do + expect(subject.pacify).to be_nil + end + end + + context "when @active is true" do + before { + allow(STDOUT).to receive(:flush) + } + + context "when length of x parameter as string is less than @count_nl" do + before { + allow(STDOUT).to receive(:print).with "quixotic" + } + it "prints parameter as output and flushes output" do + expect(STDOUT).to receive(:print).with "quixotic" + expect(subject).not_to receive(:nl) + subject.pacify("quixotic") + + expect(subject.instance_variable_get(:@count)).to eq 8 + end + end + + context "when length of x parameter as string is greater than @count_nl" do + lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." + before { + allow(STDOUT).to receive(:print).with lorem + allow(subject).to receive(:nl) + } + it "prints parameter as output, calls nl, and flushes output" do + expect(STDOUT).to receive(:print).with lorem + expect(subject).to receive(:nl) + subject.pacify(lorem) + + expect(subject.instance_variable_get(:@count)).to eq 123 + end + end + + after { + expect(STDOUT).to have_received(:flush) + } + end + end + + + describe "#pacify_bracket" do + context "when @active is false" do + before { + subject.instance_variable_set(:@active, false) + } + it "returns nil" do + expect(subject.pacify_bracket(nil)).to be_nil + end + end + + context "when @active is true" do + context "when length of x parameter as a string is less than or equal to 1" do + before { + allow(subject).to receive(:pacify).with("9") + } + it "calls pacify with x parameter withOUT brackets" do + expect(subject).to receive(:pacify).with("9") + + subject.pacify_bracket(9) + end + end + + context "when length of x parameter as a string is greater than 1" do + before { + allow(subject).to receive(:pacify).with("{deoxyribonucleic acid}") + } + it "calls pacify with x parameter with brackets" do + expect(subject).to receive(:pacify).with("{deoxyribonucleic acid}") + + subject.pacify_bracket("deoxyribonucleic acid", bracket_open: '{', bracket_close: '}') + end + end + end + end + + + describe "#nl" do + context "when @active is false" do + before { + subject.instance_variable_set(:@active, false) + } + it "returns nil" do + expect(subject.nl).to be_nil + end + end + + context "when @active is true" do + before { + subject.instance_variable_set(:@count, 55) + allow(STDOUT).to receive(:print).with("\n") + allow(STDOUT).to receive(:flush) + } + it "prints newline character, flushes output, and sets @count to 0" do + expect(STDOUT).to receive(:print).with("\n") + expect(STDOUT).to receive(:flush) + + subject.nl + + expect(subject.instance_variable_get(:@count)).to eq 0 + end + end + end + + + describe "#reset" do + context "when @active is false" do + before { + subject.instance_variable_set(:@active, false) + } + it "returns nil" do + expect(subject.reset).to be_nil + end + end + + context "when @active is true" do + before { + subject.instance_variable_set(:@count, 144) + } + it "sets @count to 0" do + subject.reset + + expect(subject.instance_variable_get(:@count)).to eq 0 + end + end + end + +end diff --git a/spec/lib/tasks/task_reporter_spec.rb b/spec/lib/tasks/task_reporter_spec.rb new file mode 100644 index 00000000..567a467e --- /dev/null +++ b/spec/lib/tasks/task_reporter_spec.rb @@ -0,0 +1,104 @@ +require 'rails_helper' +require_relative '../../../lib/tasks/task_reporter' +require_relative '../../../lib/tasks/task_pacifier' +require_relative '../../../lib/tasks/task_logger' + +class MockTaskReporter + include Deepblue::TaskReporter +end + +class MockTaskLogger + + def level=(level) + end +end + + +RSpec.describe Deepblue::TaskReporter do + + attr_accessor :log, :pacifier + + subject { MockTaskReporter.new } + + + describe "#log" do + context "when @log has a value" do + before { + subject.instance_variable_set(:@log, "log") + } + it "returns value of @log" do + expect(subject).not_to receive(:initialize_log) + + expect(subject.log).to eq "log" + end + end + + context "when @log has NO value" do + before { + allow(subject).to receive(:initialize_log).and_return "log initialized" + } + it "calls initialize_log, sets and returns the value of @log" do + expect(subject).to receive(:initialize_log) + expect(subject.log).to eq "log initialized" + + expect(subject.instance_variable_get(:@log)).to eq "log initialized" + end + end + end + + + describe "#pacifier" do + context "when @pacifier has a value" do + before { + subject.instance_variable_set(:@pacifier, "pacifier") + } + it "returns value of @pacifier" do + expect(subject).not_to receive(:initialize_pacifier) + + expect(subject.pacifier).to eq "pacifier" + end + end + + context "when @pacifier has NO value" do + before { + allow(subject).to receive(:initialize_pacifier).and_return "pacifier initialized" + } + it "calls initialize_pacifier, sets and returns the value of @pacifier" do + expect(subject).to receive(:initialize_pacifier) + expect(subject.pacifier).to eq "pacifier initialized" + + expect(subject.instance_variable_get(:@pacifier)).to eq "pacifier initialized" + end + end + end + + + describe "#initialize_log" do + task_logger = MockTaskLogger.new + + before { + allow(Deepblue::TaskLogger).to receive(:new).with( STDOUT ).and_return task_logger + } + it "calls Deepblue::TaskLogger.new" do + expect(Deepblue::TaskLogger).to receive(:new).with( STDOUT ) + expect(task_logger).to receive(:level=).with(Logger::INFO) + expect(Rails).to receive(:logger=).with(task_logger) + + subject.send(:initialize_log) + end + end + + + describe "#initialize_pacifier" do + before { + allow(Deepblue::TaskPacifier).to receive(:new).with( out: STDOUT ) + } + + it "calls Deepblue::TaskPacifier.new" do + expect(Deepblue::TaskPacifier).to receive(:new).with( out: STDOUT ) + + subject.send(:initialize_pacifier) + end + end + +end diff --git a/spec/lib/tasks/upload_logger_spec.rb b/spec/lib/tasks/upload_logger_spec.rb new file mode 100644 index 00000000..a43e97ca --- /dev/null +++ b/spec/lib/tasks/upload_logger_spec.rb @@ -0,0 +1,22 @@ +require 'rails_helper' + + +RSpec.describe Deepblue::UploadLogger do + + describe "#format_message" do + subject { described_class.new(STDOUT) } + + it "returns message parameter as string with a newline appended" do + expect(subject.format_message(nil, nil, nil, "the message")).to eq "the message\n" + end + end + + + describe "constants" do + it do + expect(Deepblue::UPLOAD_LOGGER.class).to eq Deepblue::UploadLogger + end + end + + skip "Add a test for code in module outside of class" +end