Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #21 from trotzig/rspec
Browse files Browse the repository at this point in the history
Rspec
  • Loading branch information
trotzig committed Jul 31, 2015
2 parents e042cec + be366b3 commit 3a161d1
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: ruby
rvm:
- "2.2.1"

script: bash headless_rspec.sh
install: gem install rspec headless; bundle install;
before_install:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gemspec
4 changes: 4 additions & 0 deletions headless_rspec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ruby <<RUBY
require 'headless'
exit(Headless.ly { system('rspec') ? 0 : 1 })
RUBY
152 changes: 152 additions & 0 deletions spec/likadan_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
require 'yaml'
require 'tmpdir'

describe 'likadan' do
let(:config) do
{
'source_files' => ['examples.js']
}
end

let(:example_config) { '{}' }

let(:examples_js) { <<-EOS }
likadan.define('foo', function() {
var elem = document.createElement('div');
elem.innerHTML = 'Foo';
document.body.appendChild(elem);
return elem;
}, #{example_config})
EOS

before do
@tmp_dir = Dir.mktmpdir

File.open(File.join(@tmp_dir, '.likadan.yaml'), 'w') do |f|
f.write(config.to_yaml)
end

File.open(File.join(@tmp_dir, 'examples.js'), 'w') do |f|
f.write(examples_js)
end
end

after do
FileUtils.remove_entry_secure @tmp_dir
end

def run_likadan
pwd = Dir.pwd
Dir.chdir @tmp_dir do
system("ruby -I#{pwd}/lib #{pwd}/bin/likadan")
end
end

describe 'with no previous run' do
it 'generates a baseline' do
run_likadan
expect(
File.exist?(
File.join(@tmp_dir, 'snapshots', 'foo', '@large', 'baseline.png')
)
).to be(true)
end

it 'does not generate a diff' do
run_likadan
expect(
File.exist?(
File.join(@tmp_dir, 'snapshots', 'foo', '@large', 'diff.png')
)
).to be(false)
end

it 'does not create a candidate file' do
run_likadan
expect(
File.exist?(
File.join(@tmp_dir, 'snapshots', 'foo', '@large', 'candidate.png')
)
).to be(false)
end
end

describe 'with a previous run' do
context 'and no diff' do
before do
run_likadan
end

it 'keeps the baseline' do
run_likadan
expect(
File.exist?(
File.join(@tmp_dir, 'snapshots', 'foo', '@large', 'baseline.png')
)
).to be(true)
end

it 'does not generate a diff' do
run_likadan
expect(
File.exist?(
File.join(@tmp_dir, 'snapshots', 'foo', '@large', 'diff.png')
)
).to be(false)
end

it 'does not create a candidate file' do
run_likadan
expect(
File.exist?(
File.join(@tmp_dir, 'snapshots', 'foo', '@large', 'candidate.png')
)
).to be(false)
end
end

context 'and there is a diff' do
before do
run_likadan

File.open(File.join(@tmp_dir, 'examples.js'), 'w') do |f|
f.write(<<-EOS)
likadan.define('foo', function() {
var elem = document.createElement('div');
elem.innerHTML = 'Football';
document.body.appendChild(elem);
return elem;
}, #{example_config})
EOS
end
end

it 'keeps the baseline' do
run_likadan
expect(
File.exist?(
File.join(@tmp_dir, 'snapshots', 'foo', '@large', 'baseline.png')
)
).to be(true)
end

it 'generates a diff' do
run_likadan
expect(
File.exist?(
File.join(@tmp_dir, 'snapshots', 'foo', '@large', 'diff.png')
)
).to be(true)
end

it 'generates a candidate file' do
run_likadan
expect(
File.exist?(
File.join(@tmp_dir, 'snapshots', 'foo', '@large', 'candidate.png')
)
).to be(true)
end
end
end
end

0 comments on commit 3a161d1

Please sign in to comment.