This repository has been archived by the owner on Jun 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from trotzig/rspec
Rspec
- Loading branch information
Showing
4 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
source 'https://rubygems.org' | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |