Skip to content
Browse files

Add tests

  • Loading branch information...
1 parent bb084c5 commit 2f2fc963ae53d5f02032b4f7fe7dc770cf865c82 @kaishin kaishin committed
Showing with 131 additions and 2 deletions.
  1. +2 −0 Rakefile
  2. +0 −2 lib/tasks/install.rake
  3. +56 −0 lib/tasks/test.rake
  4. +10 −0 lib/tasks/tests/omega.rake
  5. +1 −0 neat.gemspec
  6. +31 −0 test/_omega.scss
  7. +28 −0 test/test.css
  8. +3 −0 test/test.scss
View
2 Rakefile
@@ -1,2 +1,4 @@
require 'bundler'
Bundler::GemHelper.install_tasks
+
+import 'lib/tasks/test.rake'
View
2 lib/tasks/install.rake
@@ -1,5 +1,3 @@
-# Needed for pre-3.1.
-
require "fileutils"
require "find"
View
56 lib/tasks/test.rake
@@ -0,0 +1,56 @@
+require "css_parser"
+require "fileutils"
+include CssParser
+
+Dir.glob("lib/tasks/tests/*.rake").each { |r| import r }
+
+task :test do
+ install_temporary_bourbon_folder
+ generate_css_file
+ parser = CssParser::Parser.new
+ parser.load_file!('test/test.css')
+ test_omega(parser)
+ remove_temporary_bourbon_directory
+end
+
+def test(parser, test_code, selector, declaration, value)
+ rules = parser.find_by_selector(selector)
+ rules.each do |rule|
+ rule_declaration, rule_value = rule.split(":")
+ rule_value.gsub!(/;|^ /, "")
+ if rule_declaration == declaration and rule_value == value
+ puts "#{test_code} "+ pass('PASSED') +" "+ css(selector) +" has property "+ css(declaration + ": " + value + ";") +" "
+ return
+ end
+ end
+ puts "#{test_code} " + fail('FAILED') + " Expected "+ css(selector) +" with "+ css(declaration + ": " + value + ";") +" but got "+ css(rules[0]) +" instead."
+end
+
+
+def install_temporary_bourbon_folder
+ system("bourbon install --path test")
+end
+
+def remove_temporary_bourbon_directory
+ FileUtils.rm_rf("test/bourbon")
+end
+
+def generate_css_file
+ system("sass test/test.scss:test/test.css")
+end
+
+def colorize(text, color_code)
+ "\e[#{color_code}m#{text}\e[0m"
+end
+
+def fail(text)
+ colorize(text, 31)
+end
+
+def pass(text)
+ colorize(text, 32)
+end
+
+def css(text)
+ colorize(text, 34)
+end
View
10 lib/tasks/tests/omega.rake
@@ -0,0 +1,10 @@
+def test_omega(parser)
+ test(parser, 'OMEGA 1', '.omega-default', 'margin-right', '0')
+ test(parser, 'OMEGA 2', '.omega-table', 'padding-right', '0')
+ test(parser, 'OMEGA 3', '.omega-block-left', 'margin-left', '0')
+ test(parser, 'OMEGA 4', '.omega-table-left', 'padding-left', '0')
+ test(parser, 'OMEGA 5', '.omega-nth-default:nth-child(4n)', 'margin-right', '0')
+ test(parser, 'OMEGA 6', '.omega-nth-table:nth-child(4n)', 'padding-right', '0')
+ test(parser, 'OMEGA 7', '.omega-nth-default-left:nth-child(4n)', 'padding-left', '0')
+ test(parser, 'OMEGA 8', '.omega-nth-table-left:nth-child(4n)', 'padding-left', '0')
+end
View
1 neat.gemspec
@@ -26,4 +26,5 @@ Neat is an open source grid framework built on top of Bourbon with the aim of be
s.add_development_dependency('aruba', '~> 0.4')
s.add_development_dependency('rake')
+ s.add_development_dependency('css_parser')
end
View
31 test/_omega.scss
@@ -0,0 +1,31 @@
+.omega-default {
+ @include omega;
+}
+
+.omega-table {
+ @include omega(table);
+}
+
+.omega-block-left {
+ @include omega(block, left);
+}
+
+.omega-table-left{
+ @include omega(table, left);
+}
+
+.omega-nth-default {
+ @include omega(4n)
+}
+
+.omega-nth-table {
+ @include omega(4n table);
+}
+
+.omega-nth-default-left {
+ @include omega(4n table, left);
+}
+
+.omega-nth-table-left {
+ @include omega(4n table, left);
+}
View
28 test/test.css
@@ -0,0 +1,28 @@
+* {
+ -webkit-box-sizing: border-box;
+ -moz-box-sizing: border-box;
+ box-sizing: border-box; }
+
+.omega-default {
+ margin-right: 0; }
+
+.omega-table {
+ padding-right: 0; }
+
+.omega-block-left {
+ margin-left: 0; }
+
+.omega-table-left {
+ padding-left: 0; }
+
+.omega-nth-default:nth-child(4n) {
+ margin-right: 0; }
+
+.omega-nth-table:nth-child(4n) {
+ padding-right: 0; }
+
+.omega-nth-default-left:nth-child(4n) {
+ padding-left: 0; }
+
+.omega-nth-table-left:nth-child(4n) {
+ padding-left: 0; }
View
3 test/test.scss
@@ -0,0 +1,3 @@
+@import 'bourbon/bourbon';
+@import 'app/assets/stylesheets/neat';
+@import 'omega';

0 comments on commit 2f2fc96

Please sign in to comment.
Something went wrong with that request. Please try again.