Skip to content

Commit

Permalink
Update tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnAlbin committed Oct 17, 2015
1 parent 53cc2ec commit f55eb8b
Show file tree
Hide file tree
Showing 31 changed files with 30 additions and 22 deletions.
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# Configuration options are documented at:
# http://about.travis-ci.org/docs/user/languages/ruby/
language: ruby
bundler_args: --without development
rvm:
- 1.9.3
- 2.0.0
- 2.1.2
- 2.2.1
gemfile:
- tests/Gemfile
- test/Gemfile
branches:
only:
- master
- 2.x
script: cd tests; bundle exec rake
script: cd test; bundle exec rake
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"Nicolas Gallagher",
"John Albin Wilkins"
],
"scripts": {
"test": "cd test; bundle exec rake"
},
"license": [
"MIT",
"GPLv2"
Expand Down
7 changes: 4 additions & 3 deletions tests/Gemfile → test/Gemfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Pull gems from RubyGems
source 'https://rubygems.org'

gem 'sass', ">= 3.3.0"
gem 'compass', ">= 1.0.0"
gem 'sass', "~> 3.3"
gem 'compass', "~> 1.0"

group :test do
gem 'rake'
gem "diffy", "~> 3.0.1"
gem "diffy", "~> 3.0.1"
gem "colorize", "~> 0.6.0"
gem 'minitest', "~> 5.6"
end
File renamed without changes.
6 changes: 3 additions & 3 deletions tests/Rakefile → test/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ end
desc 'Compile baseline CSS'
task :compile do
require 'compass'
require 'compass/sass_compiler'
require 'compass/exec'

Compass.add_configuration 'config.rb'
Compass.configuration.project_path = Dir.pwd
# Compile into baseline directory instead of test output directory
Compass.configuration.css_dir = 'controls'
Compass.sass_compiler.clean!
Compass.sass_compiler.compile!
Compass.compiler.clean!
Compass.compiler.run
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
28 changes: 14 additions & 14 deletions tests/unit_tests.rb → test/unit_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

require 'compass'
require 'compass/exec'
require 'test/unit'
require 'minitest/autorun'
require 'diffy'
require 'colorize'
require 'pathname'

class TestCompassOutput < Test::Unit::TestCase
class TestCompassOutput < Minitest::Test

Compass.add_configuration 'config.rb'
Compass.configuration.project_path = Dir.pwd
Expand All @@ -20,35 +20,35 @@ class TestCompassOutput < Test::Unit::TestCase

define_method "test_#{test_name}_compile " do
# Compiled CSS file path
test_file_pwd = Compass.compiler.corresponding_css_file(sass_file)
css_file = Compass.compiler.corresponding_css_file(sass_file)

# Relative path of compiled CSS file from Tests directory
relative_pwd = Pathname.new(test_file_pwd).relative_path_from(Pathname.new("#{Dir.pwd}/output")).to_s
css_file_relative = Pathname.new(css_file).relative_path_from(Pathname.new("#{Dir.pwd}/output")).to_s

# Control files path
control_file_pwd = "#{Dir.pwd}/controls/" + relative_pwd
control_file = "#{Dir.pwd}/controls/" + css_file_relative

# The base path of the sub folders, making the folders if needed
base_pwd = relative_pwd.sub(File.basename(relative_pwd), '')
FileUtils.mkdir_p "#{Dir.pwd}/output/#{base_pwd}"
base_dir = File.dirname(css_file_relative)
FileUtils.mkdir_p "#{Dir.pwd}/output/#{base_dir}"

# Compiles Sass file
Compass.compiler.compile sass_file, test_file_pwd # Raises exception upon error
Compass.compiler.compile sass_file, css_file # Raises exception upon error

begin
# Assert that our test output matches our control output
passed = assert FileUtils.compare_file(test_file_pwd, control_file_pwd), "Compiled output for #{File.basename(sass_file)} does not match control output!".red
passed = assert FileUtils.compare_file(css_file, control_file), "Compiled output for #{File.basename(sass_file)} does not match control output!".red
ensure
# If there is a failure, generate a diff of the files and put it with the compiled file
if !passed
test_file = File.open(test_file_pwd).read;
control_file = File.open(control_file_pwd).read;
diff_pwd = "#{Dir.pwd}/output/#{relative_pwd}.diff"
test_file = File.open(css_file).read;
control_file = File.open(control_file).read;
diff_file = "#{css_file}.diff"
diff_content = Diffy::Diff.new(control_file, test_file, :include_diff_info => true)

File.open(diff_pwd, 'w') { |f| f.write(diff_content.to_s(:text)) }
File.open(diff_file, 'w') { |f| f.write(diff_content.to_s(:text)) }

puts "Control->Compiled diff output to ".yellow + "tests/output/#{relative_pwd}.diff".blue
puts "Control->Compiled diff output to ".yellow + "output/#{css_file_relative}.diff".blue
end
end
end
Expand Down

0 comments on commit f55eb8b

Please sign in to comment.