Test screenshot pixel values separately, outside of request/controller

private-asciicasts
Marcin Kulik 9 years ago
parent 04004c490d
commit 3abad5023f

@ -1,11 +1,11 @@
require 'rails_helper'
describe "oEmbed provider" do
describe "oEmbed provider", needs_phantomjs_2_bin: true do
let(:asciicast) { create(:asciicast) }
it "responds with status 200 for JSON" do
get "/oembed?url=http://localhost:3000/a/#{asciicast.id}&format=json"
get "/oembed?url=http://localhost:3000/a/#{asciicast.id}&format=json&maxwidth=500&maxheight=300"
expect(response.status).to eq(200)
end

@ -15,29 +15,4 @@ feature "Asciicast page", :js => true do
expect(page).to have_selector('.cinema .play-button')
end
def rgb(color)
[ChunkyPNG::Color.r(color), ChunkyPNG::Color.g(color), ChunkyPNG::Color.b(color)]
end
scenario 'Requesting PNG', needs_phantomjs_2_bin: true do
visit asciicast_path(asciicast, format: :png)
expect(current_path).to match(%r{/uploads/test/asciicast/image/\d+/\w+\.png$})
png = ChunkyPNG::Image.from_file("#{Rails.root}/public/#{current_path}")
# make sure there are black-ish borders
expect(rgb(png[1, 1])).to eq([18, 19, 20])
expect(rgb(png[png.width - 2, png.height - 2])).to eq([18, 19, 20])
# check content color (blue background)
expect(rgb(png[15, 15])).to eq([0, 175, 255])
# make sure white SVG play icon is rendered correctly
expect(rgb(png[png.width / 2, (png.height / 2) - 10])).to eq([255, 255, 255])
# make sure PowerlineSymbols are rendered
expect(rgb(png[144, 795])).to eq([0, 95, 255])
end
end

@ -0,0 +1,13 @@
require 'rails_helper'
feature "asciicast-as-png", needs_phantomjs_2_bin: true do
let(:asciicast) { create(:asciicast) }
scenario "Requesting PNG" do
visit asciicast_path(asciicast, format: :png)
expect(current_path).to match(%r{/uploads/test/asciicast/image/\d+/\w+\.png$})
end
end

@ -0,0 +1,42 @@
require 'rails_helper'
describe AsciicastImageGenerator, needs_phantomjs_2_bin: true do
let(:image_generator) { AsciicastImageGenerator.new(template_renderer) }
let(:template_renderer) { ApplicationController.new }
describe '#generate' do
let(:asciicast) { create(:asciicast) }
def rgb(color)
[ChunkyPNG::Color.r(color), ChunkyPNG::Color.g(color), ChunkyPNG::Color.b(color)]
end
before do
image_generator.generate(asciicast)
end
it 'generates screenshot of "snapshot frame"' do
png = ChunkyPNG::Image.from_file("#{Rails.root}/public/#{asciicast.image_url}")
# make sure there are black-ish borders
expect(rgb(png[1, 1])).to eq([18, 19, 20])
expect(rgb(png[png.width - 2, png.height - 2])).to eq([18, 19, 20])
# check content color (blue background)
expect(rgb(png[15, 15])).to eq([0, 175, 255])
# make sure white SVG play icon is rendered correctly
expect(rgb(png[png.width / 2, (png.height / 2) - 10])).to eq([255, 255, 255])
# make sure PowerlineSymbols are rendered
expect(rgb(png[144, 795])).to eq([0, 95, 255])
end
it 'sets image_width and image_height on the asciicast' do
expect(asciicast.image_width).to_not be(nil)
expect(asciicast.image_height).to_not be(nil)
end
end
end
Loading…
Cancel
Save