spec/converters/video_converters/webm_spec.rb
require 'spec_helper'

describe Voyeur::Webm do
  context "New Media" do
    let(:converter) { Voyeur::Converter.create(format: :webm) }
    let(:media) { Voyeur::Media.new(filename: 'test_media.webm') }

    it "uses the correct factory" do
      converter.class.to_s.should == "Voyeur::Webm"
    end

    context "#convert_options" do
      it "default convert string" do
        converter.convert_options.should == "-b 1500k -vcodec libvpx -acodec libvorbis -ab 160000 -f webm -g 30"
      end

      it "raises an exception if no media is passed" do
        media = nil
        -> { converter.convert(media: media) }.should raise_error Voyeur::Exceptions::NoMediaPresent
      end

      it "returns a media" do
        converter.convert(media: media)
        converter.input_media.should == media
      end
    end
  end

  context "An invalid Media" do
    let(:converter) { Voyeur::Converter.create(format: :webm) }
    let(:media) { Voyeur::Media.new(filename: 'test_media.mpeg') }

    context "File does not exist" do
      it "returns conversion status indicating failure" do
        result = converter.convert(media: media)
        result[:status].should == 1
        result[:media].should == converter.output_media
        result[:error_message].should match(/test_media.mpeg: No such file or directory/)
        result[:stderr].nil?.should == false
      end
    end
  end
end
