2014-08-30 17:38:47 +00:00
|
|
|
require 'rails_helper'
|
2013-09-10 19:29:17 +00:00
|
|
|
|
|
|
|
describe AsciicastSnapshotUpdater do
|
|
|
|
|
|
|
|
let(:updater) { described_class.new }
|
|
|
|
|
|
|
|
describe '#update' do
|
2014-11-27 11:48:41 +00:00
|
|
|
let(:asciicast) { double('asciicast', duration: 5.0, stdout: stdout,
|
|
|
|
update_attribute: nil,
|
|
|
|
snapshot_at: snapshot_at) }
|
2013-09-10 19:29:17 +00:00
|
|
|
let(:stdout) { double('stdout') }
|
|
|
|
let(:terminal) { double('terminal') }
|
|
|
|
let(:film) { double('film', :snapshot_at => 'foo') }
|
2014-11-27 11:48:41 +00:00
|
|
|
let(:snapshot_at) { nil }
|
2013-09-10 19:29:17 +00:00
|
|
|
|
|
|
|
subject { updater.update(asciicast) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(asciicast).to receive(:with_terminal).and_yield(terminal)
|
|
|
|
allow(Film).to receive(:new).with(stdout, terminal) { film }
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it "updates asciicast's snapshot to the terminal's snapshot" do
|
|
|
|
expect(asciicast).to have_received(:update_attribute).
|
|
|
|
with(:snapshot, 'foo')
|
|
|
|
end
|
|
|
|
|
2014-11-27 11:48:41 +00:00
|
|
|
context "when no snapshot time set on asciicast nor custom time given" do
|
|
|
|
it "generates the snapshot at half of asciicast's duration" do
|
|
|
|
expect(film).to have_received(:snapshot_at).with(2.5)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when snapshot time set on asciicast" do
|
|
|
|
let(:snapshot_at) { 2.0 }
|
|
|
|
|
|
|
|
it "generates the snapshot at half of asciicast's duration" do
|
|
|
|
expect(film).to have_received(:snapshot_at).with(2.0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-09-10 19:29:17 +00:00
|
|
|
context "when snapshot time given" do
|
|
|
|
subject { updater.update(asciicast, 4.3) }
|
|
|
|
|
|
|
|
it "generates the snapshot at the given time" do
|
|
|
|
expect(film).to have_received(:snapshot_at).with(4.3)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|