Skip to content

Commit

Permalink
New test setup and hopefully a more sane engine initializer.
Browse files Browse the repository at this point in the history
  • Loading branch information
metaskills committed Oct 9, 2011
1 parent 189fc68 commit 56ec18d
Show file tree
Hide file tree
Showing 20 changed files with 3,510 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -2,3 +2,5 @@
.bundle
Gemfile.lock
pkg/*
log/*
tmp/*
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,11 @@
CHANGELOG
=========

1.3.3 (unreleased)

* New test setup and hopefully a more sane engine initializer.


1.3.2 (Sept 28, 2011)
---------------------

Expand Down
3 changes: 3 additions & 0 deletions Gemfile
@@ -1,2 +1,5 @@
source :rubygems
gemspec

gem 'less-rails', :path => ENV['LESS_RAILS_PATH'] if ENV['LESS_RAILS_PATH']

5 changes: 5 additions & 0 deletions Guardfile
@@ -0,0 +1,5 @@
guard 'minitest' do
watch(%r|^lib/less/rails/bootstrap/(.*)\.rb|) { |m| "test/cases/#{m[1]}_spec.rb" }
watch(%r|^test/spec_helper\.rb|) { "test/cases" }
watch(%r|^test/cases/(.*)_spec\.rb|)
end
15 changes: 14 additions & 1 deletion Rakefile
@@ -1 +1,14 @@
require "bundler/gem_tasks"
require 'bundler'
require 'rake/testtask'

Bundler::GemHelper.install_tasks

Rake::TestTask.new do |t|
t.libs = ['lib','test']
t.test_files = Dir.glob("test/**/*_spec.rb").sort
t.verbose = true
end

task :default => [:test]
task :spec => [:test]

3 changes: 3 additions & 0 deletions less-rails-bootstrap.gemspec
Expand Up @@ -15,4 +15,7 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
s.add_runtime_dependency "less-rails", "~> 2.0.0"
s.add_development_dependency 'minitest'
s.add_development_dependency 'guard-minitest'
s.add_development_dependency 'rails', '~> 3.1.1'
end
4 changes: 2 additions & 2 deletions lib/less-rails-bootstrap.rb
Expand Up @@ -5,5 +5,5 @@ module Bootstrap
end
end

require 'less/rails'
require "less/rails/bootstrap"
require 'less-rails'
require 'less/rails/bootstrap'
5 changes: 2 additions & 3 deletions lib/less/rails/bootstrap/engine.rb
Expand Up @@ -3,9 +3,8 @@ module Rails
module Bootstrap
class Engine < ::Rails::Engine

config.after_initialize do |app|
bootstrap_less_files = config.root + 'vendor/stylesheets/twitter/bootstrap'
app.config.less.paths << bootstrap_less_files
initializer 'less-rails-bootstrap.setup', :after => 'less-rails.after.load_config_initializers', :group => :all do |app|
app.config.less.paths << File.join(config.root, 'vendor', 'assets', 'stylesheets')
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/less/rails/bootstrap/version.rb
@@ -1,7 +1,7 @@
module Less
module Rails
module Bootstrap
VERSION = "1.3.2"
VERSION = "1.3.3"
end
end
end
15 changes: 15 additions & 0 deletions test/cases/engine_spec.rb
@@ -0,0 +1,15 @@
require 'spec_helper'

class EngineSpec < Less::Rails::Bootstrap::Spec

it 'must be able to hook into a less-rails config' do
dummy_config.less.must_be_instance_of ActiveSupport::OrderedOptions
end

it 'must append engines assets stylesheets to less-rails load paths' do
dummy_config.less.paths.must_be_instance_of Array
dummy_config.less.paths.must_include project_root
end


end
72 changes: 72 additions & 0 deletions test/cases/usage_css_spec.rb
@@ -0,0 +1,72 @@
require 'spec_helper'

class UsageCssSpec < Less::Rails::Bootstrap::Spec

describe 'application.css' do

let(:app_css) { dummy_asset('application.css') }

it 'will render main bootstrap.less file and all included modules' do
app_css.must_include 'Bootstrap @VERSION', 'From boostrap.less'
app_css.must_include 'Forms.less', 'From forms.less'
app_css.must_include 'Snippets of reusable CSS', 'From mixins.less'
app_css.must_include 'Patterns.less', 'From patterns.less'
app_css.must_include 'Scaffolding', 'From scaffolding.less'
app_css.must_include 'Tables.less', 'From tables.less'
app_css.must_include 'Typography.less', 'From type.less'
app_css.must_include 'Variables.less', 'From variables.less'
end

it 'must include basic css afterward' do
app_css.must_include '#other-css { color: red; }', 'From our code afterward.'
end

end

describe 'framework.css.less' do

before { dummy_config.less.compress = true }

let(:framework_css) { dummy_asset('framework.css') }

it 'will render bootstrap functions' do
border_radius_line = line_for_framework_css('framework-border-radius')
border_radius_line.must_include '-webkit-border-radius:4px'
border_radius_line.must_include '-moz-border-radius:4px'
border_radius_line.must_include 'border-radius:4px'
end

it 'will render bootstrap variables' do
link_color_line = line_for_framework_css('framework-linkColor')
link_color_line.must_include 'color:#0069d6;'
end

end

describe 'individual.css.less' do

before { dummy_config.less.compress = true }

let(:individual_css) { dummy_asset('individual.css') }

it 'will render bootstrap variables and mixins' do
my_button_line = line_for_individual_css('individual-my-button')
my_button_line.must_include '-webkit-border-radius:10px'
my_button_line.must_include '-moz-border-radius:10px'
my_button_line.must_include 'border-radius:10px'
end

end


private

def line_for_framework_css(name)
framework_css.each_line.detect{ |line| line.include? name }.strip
end

def line_for_individual_css(name)
individual_css.each_line.detect{ |line| line.include? name }.strip
end

end
36 changes: 36 additions & 0 deletions test/cases/usage_js_spec.rb
@@ -0,0 +1,36 @@
require 'spec_helper'

class UsageJsSpec < Less::Rails::Bootstrap::Spec

describe 'application.js' do

let(:app_js) { dummy_asset('application.js') }

it 'will render main bootstrap.js file and all included modules' do
app_js.must_include 'bootstrap-alerts.js'
app_js.must_include 'bootstrap-dropdown.js'
app_js.must_include 'bootstrap-modal.js'
app_js.must_include 'bootstrap-popover.js'
app_js.must_include 'bootstrap-scrollspy.js'
app_js.must_include 'bootstrap-tabs.js'
app_js.must_include 'bootstrap-twipsy.js'
end

it 'must include basic js afterward' do
app_js.must_include '$(document).ready(function(){...});'
end

end

describe 'individual.css.less' do

let(:individual_js) { dummy_asset('individual.js') }

it 'will render bootstrap variables and mixins' do
individual_js.must_include 'bootstrap-modal.js'
end

end


end
3 changes: 3 additions & 0 deletions test/dummy_app/app/assets/javascripts/application.js
@@ -0,0 +1,3 @@
//= require twitter/bootstrap

$(document).ready(function(){...});
2 changes: 2 additions & 0 deletions test/dummy_app/app/assets/javascripts/individual.js
@@ -0,0 +1,2 @@
//= require twitter/bootstrap/modal

6 changes: 6 additions & 0 deletions test/dummy_app/app/assets/stylesheets/application.css
@@ -0,0 +1,6 @@
/*
*= require twitter/bootstrap
*/

#other-css { color: red; }

6 changes: 6 additions & 0 deletions test/dummy_app/app/assets/stylesheets/framework.css.less
@@ -0,0 +1,6 @@
@import "twitter/bootstrap";

#framework-start{color:red;}

#framework-border-radius { .border-radius(4px); }
#framework-linkColor { color: @linkColor; }
10 changes: 10 additions & 0 deletions test/dummy_app/app/assets/stylesheets/individual.css.less
@@ -0,0 +1,10 @@
@import "twitter/bootstrap/variables";
@import "twitter/bootstrap/mixins";

.myButton(@radius: 5px) {
.border-radius(@radius);
}

#individual-my-button {
.myButton(10px);
}
21 changes: 21 additions & 0 deletions test/dummy_app/init.rb
@@ -0,0 +1,21 @@
require 'sprockets/railtie'
require 'action_controller/railtie'
require 'action_view/railtie'
require 'action_view/base'
require 'action_controller/base'

module Dummy
class Application < ::Rails::Application

config.root = File.join __FILE__, '..'
config.active_support.deprecation = :stderr
config.cache_store = :memory_store
config.consider_all_requests_local = true

config.assets.enabled = true
config.assets.cache_store = config.cache_store

end
end

Dummy::Application.initialize!

0 comments on commit 56ec18d

Please sign in to comment.