Add missing feature specs

This commit is contained in:
Marcin Kulik 2013-05-27 21:25:29 +02:00
parent 62a3ffed92
commit 61ac829715
7 changed files with 137 additions and 56 deletions

View File

@ -12,6 +12,7 @@ FactoryGirl.define do
terminal_lines 25 terminal_lines 25
shell "/bin/bash" shell "/bin/bash"
uname "uname" uname "uname"
views_count 1
stdout do stdout do
fixture_file_upload("spec/fixtures/stdout", "application/octet-stream") fixture_file_upload("spec/fixtures/stdout", "application/octet-stream")
end end

View File

@ -0,0 +1,18 @@
require 'spec_helper'
feature "Asciicast page", :js => true do
let(:asciicast) { load_asciicast(1) }
scenario 'Visiting as guest' do
visit asciicast_path(asciicast)
expect(page).to have_content('Recorded')
expect(page).to have_content('Viewed')
expect(page).to have_content('OS')
expect(page).to have_content('SHELL')
expect(page).to have_content('TERM')
expect(page).to have_selector('.play-button')
end
end

View File

@ -1,66 +1,25 @@
require 'spec_helper' require 'spec_helper'
def uploaded_file(path, type) feature "Asciicast lists" do
ActionDispatch::Http::UploadedFile.new(
:filename => File.basename(path),
:tempfile => File.open(path),
:type => type
)
end
describe 'Asciicast playback', :type => :feature, :js => true do let!(:asciicast) { load_asciicast(1) }
def load_asciicast(id) scenario 'Visiting all' do
FactoryGirl.create( visit browse_path
:asciicast,
:meta => uploaded_file( expect(page).to have_content(/All Asciicasts/i)
"spec/fixtures/asciicasts/#{id}/meta.json", expect_browse_section
'application/json' expect(page).to have_link("##{asciicast.id}")
), expect(page).to have_selector('.supplimental .play-button')
:stdout => fixture_file_upload(
"spec/fixtures/asciicasts/#{id}/stdout",
"application/octet-stream"
),
:stdout_timing => fixture_file_upload(
"spec/fixtures/asciicasts/#{id}/stdout.time",
"application/octet-stream"
)
)
end end
def visit_asciicast(id) scenario 'Visiting popular' do
asciicast = load_asciicast(id) visit popular_path
visit "/a/#{asciicast.id}/raw?speed=5"
end
def inject_on_finished_callback expect(page).to have_content(/Popular Asciicasts/i)
page.execute_script(<<EOS) expect_browse_section
window.player.movie.on('finished', function() { expect(page).to have_link("##{asciicast.id}")
$('body').append('<span class=\"finished\"></span>'); expect(page).to have_selector('.supplimental .play-button')
})
EOS
end
Dir['spec/fixtures/asciicasts/*'].each do |dir|
id = dir[/\d+/]
describe "from fixture #{id}" do
before do
@old_wait_time = Capybara.default_wait_time
Capybara.default_wait_time = 120
end
after do
Capybara.default_wait_time = @old_wait_time
end
it "is successful" do
visit_asciicast(id)
find(".play-button").find(".arrow").click
inject_on_finished_callback
page.should have_selector('body .finished')
end
end
end end
end end

View File

@ -0,0 +1,19 @@
require 'spec_helper'
feature "Homepage", :js => true do
let!(:asciicast) { load_asciicast(1) }
scenario 'Visiting' do
visit root_path
expect(page).to have_content(/Recent Asciicasts/i)
page.save_screenshot 'a.png'
expect(page).to have_link('Browse')
expect(page).to have_link('Record')
expect_browse_section
expect(page).to have_link("##{asciicast.id}")
expect(page).to have_selector('#about .play-button')
end
end

View File

@ -0,0 +1,40 @@
require 'spec_helper'
describe 'Asciicast playback', :js => true, :slow => true do
def visit_asciicast(id)
asciicast = load_asciicast(id)
visit "/a/#{asciicast.id}/raw?speed=5"
end
def inject_on_finished_callback
page.execute_script(<<EOS)
window.player.movie.on('finished', function() {
$('body').append('<span class=\"finished\"></span>');
})
EOS
end
Dir['spec/fixtures/asciicasts/*'].each do |dir|
id = dir[/\d+/]
describe "from fixture #{id}" do
before do
@old_wait_time = Capybara.default_wait_time
Capybara.default_wait_time = 120
end
after do
Capybara.default_wait_time = @old_wait_time
end
it "is successful" do
visit_asciicast(id)
find(".play-button").find(".arrow").click
inject_on_finished_callback
page.should have_selector('body .finished')
end
end
end
end

View File

@ -27,6 +27,7 @@ RSpec.configure do |config|
config.infer_base_class_for_anonymous_controllers = false config.infer_base_class_for_anonymous_controllers = false
config.include FactoryGirl::Syntax::Methods config.include FactoryGirl::Syntax::Methods
config.include AsciiIo::FeatureHelpers
config.include AsciiIo::ControllerMacros, :type => :controller config.include AsciiIo::ControllerMacros, :type => :controller
config.before(:suite) do config.before(:suite) do

View File

@ -0,0 +1,43 @@
module AsciiIo
module FeatureHelpers
def uploaded_file(path, type)
ActionDispatch::Http::UploadedFile.new(
:filename => File.basename(path),
:tempfile => File.open(path),
:type => type
)
end
def load_asciicast(id)
FactoryGirl.create(
:asciicast,
:meta => uploaded_file(
"spec/fixtures/asciicasts/#{id}/meta.json",
'application/json'
),
:stdout => fixture_file_upload(
"spec/fixtures/asciicasts/#{id}/stdout",
"application/octet-stream"
),
:stdout_timing => fixture_file_upload(
"spec/fixtures/asciicasts/#{id}/stdout.time",
"application/octet-stream"
)
)
end
def load_all_asciicasts
Dir['spec/fixtures/asciicasts/*'].each do |dir|
id = dir[/\d+/]
load_asciicast(id)
end
end
def expect_browse_section
expect(page).to have_link('All')
expect(page).to have_link('Popular')
end
end
end