asciinema.org/spec/models/asciicast_params_spec.rb

82 lines
2.2 KiB
Ruby
Raw Normal View History

2014-08-30 17:38:47 +00:00
require 'rails_helper'
2014-02-11 16:49:22 +00:00
require 'stringio'
describe AsciicastParams do
2014-02-09 18:12:15 +00:00
describe '.build' do
subject { described_class.build(input, user_agent) }
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
let(:user_agent) { 'asciinema/0.9.7' }
2014-02-09 18:12:15 +00:00
let(:stdout_data_file) { double('stdout_data_file') }
let(:stdout_timing_file) { double('stdout_timing_file') }
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 :)',
user: expected_user,
2014-02-09 18:12:15 +00:00
user_agent: 'asciinema/0.9.7',
} }
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).
with('f33e6188-f53c-11e2-abf4-84a6c827e88b') { existing_user }
2014-02-09 18:35:30 +00:00
end
2014-02-11 16:49:22 +00:00
it { should eq(expected_attrs) }
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
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'
expected_attrs.delete(:user_agent)
end
it { should eq(expected_attrs) }
end
end
end