Permalink
Browse files

Refactor matcher and add spec for outer-container

  • Loading branch information...
1 parent 89ca2d4 commit 3b3d02f82f192782d2083a44d4051f964714c053 Reda Lemeden committed Jan 29, 2013
@@ -7,12 +7,11 @@
$fg-column: $column;
$fg-gutter: $gutter;
$fg-max-columns: $grid-columns;
-$fg-max-width: $max-width;
-// outer wrapper center container
+// Outer wrapper
@mixin outer-container() {
@include clearfix;
- max-width: $fg-max-width;
+ max-width: $max-width;
margin: {
left: auto;
right: auto;
@@ -0,0 +1,17 @@
+require 'spec_helper'
+
+describe "@include outer-container()" do
+ let (:identifier) {"outer_container"}
+
+ before(:all) do
+ ParserSupport.parse_file(identifier)
+ end
+
+ it "adds clearfix" do
+ expect('.container-default:after').to have_rule('clear: both')
+ end
+
+ it "adds max-width" do
+ expect('.container-default').to have_rule('max-width: 960px')
+ end
+end
@@ -1,22 +1,33 @@
RSpec::Matchers.define :have_rule do |expected|
match do |actual|
- @rules = get_rules(actual) || []
+ @rules = rules_from_selector(actual)
@rules.include? expected
end
failure_message_for_should do |actual|
if @rules.empty?
%{no CSS rules for selector #{actual} were found}
else
- %{expected #{actual} to have CSS rule "#{expected}"}
+ %{expected selector #{actual} to have CSS rule "#{expected}"}
end
end
- def get_rules(actual)
- style_block = ParserSupport.parser.find_by_selector(actual)
- unless style_block.empty?
- rules = style_block[0].split(';')
- rules.map(&:strip)
+ def rules_from_selector(selector)
+ rulesets = ParserSupport.parser.find_by_selector(selector)
+ if rulesets.empty?
+ []
+ else
+ rules(rulesets)
+ end
+ end
+
+ def rules(rulesets)
+ rules = []
+ rulesets.map do |ruleset|
+ ruleset.split(';').each do |rule|
+ rules << rule.strip
+ end
end
+ rules
end
end
@@ -0,0 +1,7 @@
+@import 'setup';
+
+$max-width: 960px;
+
+.container-default {
+ @include outer-container;
+}

0 comments on commit 3b3d02f

Please sign in to comment.