require 'test_helper' # Cannot use require since file name has no extension. load File.join(File.dirname(__FILE__), '../bin/viewobs') class ViewobsTest < Test::Unit::TestCase context "Viewobs#view_line" do setup do @vo = Viewobs.new @vo.options = {} @line = File.readlines(fixture_file("double-obs.log")).first @attributes = LogParser.parse_line(@line) @observation = Observation.new(@attributes) end should "raise NoMethodError if there are two observations in one log line" do assert_raises(NoMethodError) { @vo.view_line(@attributes, @observation) } end end context "Viewobs when encountering a line with two observations" do setup do @argv = ARGV.dup ARGV.replace [fixture_file("double-obs.log")] @vo = Viewobs.new @vo.options = {}; @buffer = "" @stderr, $stderr = $stderr, StringIO.new(@buffer) end teardown do ARGV.replace @argv $stderr = @stderr if @stderr end should "not crash" do assert_nothing_raised { @vo.view_until_end } end should "report on stderr" do assert @buffer.empty? @vo.view_until_end assert ! @buffer.empty? end end end