2013-09-25 17:29:57 +00:00
|
|
|
require 'spec_helper'
|
2014-02-11 16:49:22 +00:00
|
|
|
require 'stringio'
|
2013-09-25 17:29:57 +00:00
|
|
|
|
|
|
|
describe AsciicastParams do
|
|
|
|
|
2014-02-09 18:12:15 +00:00
|
|
|
describe '.build' do
|
2014-02-10 16:39:37 +00:00
|
|
|
subject { described_class.build(input, user_agent) }
|
2013-09-25 17:29:57 +00:00
|
|
|
|
2014-02-09 18:12:15 +00:00
|
|
|
let(:input) { {
|
2014-02-11 16:49:22 +00:00
|
|
|
meta: StringIO.new(meta.to_json),
|
2014-02-09 18:12:15 +00:00
|
|
|
stdout: stdout_data_file,
|
2014-02-11 16:49:22 +00:00
|
|
|
stdout_timing: stdout_timing_file,
|
2014-02-09 18:12:15 +00:00
|
|
|
} }
|
2014-02-11 16:49:22 +00:00
|
|
|
|
2014-02-10 16:39:37 +00:00
|
|
|
let(:user_agent) { 'asciinema/0.9.7' }
|
2013-09-25 17:29:57 +00:00
|
|
|
|
2014-02-09 18:12:15 +00:00
|
|
|
let(:stdout_data_file) { double('stdout_data_file') }
|
|
|
|
let(:stdout_timing_file) { double('stdout_timing_file') }
|
2013-09-25 17:29:57 +00:00
|
|
|
|
2014-02-11 16:49:22 +00:00
|
|
|
let(:meta) { {
|
|
|
|
command: '/bin/bash',
|
|
|
|
duration: 11.146430015563965,
|
|
|
|
shell: '/bin/zsh',
|
|
|
|
term: { lines: 26, columns: 96, type: 'screen-256color' },
|
|
|
|
title: 'bashing :)',
|
|
|
|
user_token: 'f33e6188-f53c-11e2-abf4-84a6c827e88b',
|
|
|
|
username: 'kill',
|
|
|
|
} }
|
|
|
|
|
|
|
|
let(:expected_attrs) { {
|
2014-02-09 18:12:15 +00:00
|
|
|
command: '/bin/bash',
|
2014-02-11 16:49:22 +00:00
|
|
|
duration: 11.146430015563965,
|
2014-02-09 18:12:15 +00:00
|
|
|
shell: '/bin/zsh',
|
2014-02-11 16:49:22 +00:00
|
|
|
stdin_data: nil,
|
|
|
|
stdin_timing: nil,
|
|
|
|
stdout_data: stdout_data_file,
|
|
|
|
stdout_timing: stdout_timing_file,
|
2014-02-09 18:12:15 +00:00
|
|
|
terminal_columns: 96,
|
|
|
|
terminal_lines: 26,
|
|
|
|
terminal_type: 'screen-256color',
|
2014-02-11 16:49:22 +00:00
|
|
|
title: 'bashing :)',
|
2014-02-15 20:37:05 +00:00
|
|
|
user: expected_user,
|
2014-02-09 18:12:15 +00:00
|
|
|
user_agent: 'asciinema/0.9.7',
|
2013-09-25 17:29:57 +00:00
|
|
|
} }
|
|
|
|
|
2014-02-15 20:37:05 +00:00
|
|
|
let(:expected_user) { existing_user }
|
|
|
|
let(:existing_user) { User.new }
|
|
|
|
|
2014-02-09 18:35:30 +00:00
|
|
|
before do
|
2014-02-11 16:49:22 +00:00
|
|
|
allow(User).to receive(:for_api_token).
|
2014-02-15 20:37:05 +00:00
|
|
|
with('f33e6188-f53c-11e2-abf4-84a6c827e88b') { existing_user }
|
2014-02-09 18:35:30 +00:00
|
|
|
end
|
2013-09-25 17:29:57 +00:00
|
|
|
|
2014-02-11 16:49:22 +00:00
|
|
|
it { should eq(expected_attrs) }
|
2013-10-13 10:29:30 +00:00
|
|
|
|
2014-02-15 20:37:05 +00:00
|
|
|
context "when given api token is not found" do
|
|
|
|
let(:expected_user) { dummy_user }
|
|
|
|
let(:dummy_user) { User.new }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(User).to receive(:for_api_token).
|
|
|
|
with('f33e6188-f53c-11e2-abf4-84a6c827e88b') { nil }
|
|
|
|
allow(User).to receive(:create_dummy).
|
|
|
|
with('f33e6188-f53c-11e2-abf4-84a6c827e88b', 'kill') { dummy_user }
|
|
|
|
end
|
|
|
|
|
|
|
|
it { should eq(expected_attrs) }
|
|
|
|
end
|
|
|
|
|
2014-02-11 16:49:22 +00:00
|
|
|
context "when uname given" do
|
2014-02-10 16:39:37 +00:00
|
|
|
before do
|
2014-02-11 16:49:22 +00:00
|
|
|
meta[:uname] = 'Linux 3.9.9-302.fc19.x86_64'
|
|
|
|
expected_attrs[:uname] = 'Linux 3.9.9-302.fc19.x86_64'
|
2014-02-10 16:39:37 +00:00
|
|
|
expected_attrs.delete(:user_agent)
|
|
|
|
end
|
|
|
|
|
2013-10-13 10:29:30 +00:00
|
|
|
it { should eq(expected_attrs) }
|
|
|
|
end
|
2013-09-25 17:29:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|