Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Test Neat features using RSpec

Closes #54
  • Loading branch information...
commit 89ca2d4d4344a7e671fbeae9156a96330c08fe3b 1 parent 578c423
@kaishin kaishin authored
View
2  .rspec
@@ -0,0 +1,2 @@
+--color
+--format documentation
View
6 CONTRIBUTING.md
@@ -1,7 +1,8 @@
We love pull requests. Here's a quick guide:
-1. Fork the repo.
+1. Fork the repository.
2. Make your changes in a topic branch.
+3. Run `rake` to see if you changes are breaking any existing functionality.
3. Squash your commits into a single one (more on that [here](http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html)).
4. Rebase against `origin/master`, push to your fork and submit a pull request.
@@ -11,7 +12,8 @@ day). We may suggest some changes or improvements or alternatives.
Some things that will increase the chance that your pull request is accepted:
-* Fix a bug, refactor code or expand an existing feature
+* Fix a bug, refactor code or expand an existing feature.
+* Write [RSpec](https://www.relishapp.com/rspec) tests for your new features.
* Use the right syntax and naming conventions.
* Update parts of the documentation that are affected by your contribution.
View
6 Rakefile
@@ -1,2 +1,8 @@
+require 'rubygems'
require 'bundler'
+require 'rspec/core/rake_task'
Bundler::GemHelper.install_tasks
+
+RSpec::Core::RakeTask.new(:spec)
+
+task :default => :spec
View
2  lib/tasks/install.rake
@@ -1,5 +1,3 @@
-# Needed for pre-3.1.
-
require "fileutils"
require "find"
View
4 neat.gemspec
@@ -26,4 +26,8 @@ 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')
+ s.add_development_dependency('rspec')
+ s.add_development_dependency('rdoc')
+ s.add_development_dependency('bundler')
end
View
41 spec/neat/omega_spec.rb
@@ -0,0 +1,41 @@
+require 'spec_helper'
+
+describe "@include omega()" do
+ let (:identifier) {"omega"}
+
+ before(:all) do
+ ParserSupport.parse_file(identifier)
+ end
+
+ it "removes right margin with no argument" do
+ expect('.omega-default').to have_rule('margin-right: 0')
+ end
+
+ it "removes right padding with argument (table)" do
+ expect('.omega-table').to have_rule('padding-right: 0')
+ end
+
+ it "removes left margin with argument (block, left)" do
+ expect('.omega-block-left').to have_rule('margin-left: 0')
+ end
+
+ it "removes left padding with argument (table, left)" do
+ expect('.omega-table-left').to have_rule('padding-left: 0')
+ end
+
+ it "removes margin right of nth-child(4n) with argument (4n)" do
+ expect('.omega-nth-default:nth-child(4n)').to have_rule('margin-right: 0')
+ end
+
+ it "removes padding right of nth-child(4n) with argument (4n table)" do
+ expect('.omega-nth-table:nth-child(4n)').to have_rule('padding-right: 0')
+ end
+
+ it "removes margin left of nth-child(4n) with argument (4n block, left)" do
+ expect('.omega-nth-default-left:nth-child(4n)').to have_rule('margin-left: 0')
+ end
+
+ it "removes padding left of nth-child(4n) with argument (4n table, left)" do
+ expect('.omega-nth-table-left:nth-child(4n)').to have_rule('padding-left: 0')
+ end
+end
View
26 spec/spec_helper.rb
@@ -0,0 +1,26 @@
+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
+$LOAD_PATH.unshift(File.dirname(__FILE__))
+require 'rspec'
+require 'neat'
+require 'aruba/api'
+require 'css_parser'
+Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
+
+
+RSpec.configure do |config|
+ config.include BourbonSupport
+ config.include SassSupport
+ config.include CssParser
+ config.include ParserSupport
+ config.include Aruba::Api
+
+ config.before(:all) do
+ install_bourbon_files
+ generate_css
+ end
+
+ config.after(:all) do
+ remove_bourbon_files
+ clean_up
+ end
+end
View
9 spec/support/bourbon_support.rb
@@ -0,0 +1,9 @@
+module BourbonSupport
+ def install_bourbon_files
+ `bourbon install --path test`
+ end
+
+ def remove_bourbon_files
+ FileUtils.rm_rf('test/bourbon')
+ end
+end
View
22 spec/support/matchers/have_rule.rb
@@ -0,0 +1,22 @@
+RSpec::Matchers.define :have_rule do |expected|
+ match do |actual|
+ @rules = get_rules(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}"}
+ 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)
+ end
+ end
+end
View
9 spec/support/parser_support.rb
@@ -0,0 +1,9 @@
+module ParserSupport
+ def self.parser
+ @parser ||= CssParser::Parser.new
+ end
+
+ def self.parse_file(identifier)
+ self.parser.load_file!("tmp/#{identifier}.css")
+ end
+end
View
10 spec/support/sass_support.rb
@@ -0,0 +1,10 @@
+module SassSupport
+ def generate_css
+ _mkdir('tmp')
+ `sass --update test:tmp --style expanded`
+ end
+
+ def clean_up
+ FileUtils.rm_rf('tmp')
+ end
+end
View
2  test/_setup.scss
@@ -0,0 +1,2 @@
+@import 'bourbon/bourbon';
+@import 'app/assets/stylesheets/neat';
View
35 test/omega.scss
@@ -0,0 +1,35 @@
+@import 'setup';
+
+.omega-default {
+ @include omega;
+ color: #000;
+}
+
+.omega-table {
+ @include omega(table);
+}
+
+.omega-block-left {
+ @include omega(block, left);
+ color: #000;
+}
+
+.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 block, left);
+}
+
+.omega-nth-table-left {
+ @include omega(4n table, left);
+}
Please sign in to comment.
Something went wrong with that request. Please try again.