spec/device/stdout_spec.rb in logstash-logger-0.6.2 vs spec/device/stdout_spec.rb in logstash-logger-0.7.0
- old
+ new
@@ -1,14 +1,31 @@
require 'logstash-logger'
describe LogStashLogger::Device::Stdout do
+ let(:stdout) { $stdout }
+
it "writes to $stdout" do
- expect(subject.to_io).to eq($stdout)
- expect($stdout).to receive(:write).once
+ expect(subject.to_io).to eq(stdout)
+ expect(stdout).to receive(:write).once
subject.write("test")
end
it "ignores #close" do
- expect($stdout).not_to receive(:close)
+ expect(stdout).not_to receive(:close)
subject.close
+ end
+
+ context "when the default $stdout has been overridden" do
+ before { $stdout = StringIO.new }
+ after { $stdout = STDOUT }
+
+ let(:injected_stdout) { STDOUT }
+
+ subject { described_class.new(io: injected_stdout) }
+
+ it "accepts an injectable reference to stdout" do
+ expect(subject.to_io).to eq(injected_stdout)
+ expect(injected_stdout).to receive(:write).once
+ subject.write("test")
+ end
end
end