lib/chronicle/etl/loaders/json_loader.rb in chronicle-etl-0.5.0 vs lib/chronicle/etl/loaders/json_loader.rb in chronicle-etl-0.5.1

- old
+ new

@@ -7,14 +7,17 @@ setting :serializer setting :output, default: $stdout def start - if @config.output == $stdout - @output = @config.output + if @config.output.is_a?(IO) + # This might seem like a duplication of the default value ($stdout) + # but it's because rspec overwrites $stdout (in helper #capture) to + # capture output. + @output = $stdout.dup else - @output = File.open(@config.output, "w") + @output = File.open(@config.output, "w+") end end def load(record) serialized = serializer.serialize(record) @@ -29,10 +32,10 @@ end @output.puts encoded.to_json end def finish - @output.close + @output.close if @output.is_a?(IO) end private def serializer