streamline tests, switch to minitest
This commit is contained in:
Родитель
88be09541f
Коммит
0ca86d31fc
7
Rakefile
7
Rakefile
|
@ -4,10 +4,9 @@ $:.unshift(lib_path) unless $:.include?(lib_path)
|
|||
load './tasks/bower.rake'
|
||||
|
||||
require 'rake/testtask'
|
||||
Rake::TestTask.new do |t|
|
||||
t.libs << "test"
|
||||
t.test_files = FileList['test/*_test.rb']
|
||||
t.verbose = true
|
||||
task :test do |t|
|
||||
$: << File.expand_path('test/')
|
||||
Dir.glob('./test/**/*_test.rb').each { |file| require file }
|
||||
end
|
||||
|
||||
desc 'Dumps output to a CSS file for testing'
|
||||
|
|
|
@ -14,11 +14,14 @@ Gem::Specification.new do |s|
|
|||
s.add_runtime_dependency 'sass', '~> 3.2'
|
||||
|
||||
# Testing dependencies
|
||||
s.add_development_dependency 'test-unit', '~> 2.5.5'
|
||||
s.add_development_dependency 'minitest', '~> 5.4.0'
|
||||
s.add_development_dependency 'minitest-reporters', '~> 1.0.5'
|
||||
# Integration testing
|
||||
s.add_development_dependency 'capybara'
|
||||
s.add_development_dependency 'poltergeist'
|
||||
# Dummy Rails app dependencies
|
||||
s.add_development_dependency 'actionpack', '>= 4.1.5'
|
||||
s.add_development_dependency 'activesupport', '>= 4.1.5'
|
||||
s.add_development_dependency 'json', '>= 1.8.1'
|
||||
s.add_development_dependency 'sprockets-rails', '>= 2.1.3'
|
||||
s.add_development_dependency 'autoprefixer-rails', '~> 1.1'
|
||||
|
|
|
@ -3,7 +3,7 @@ module Bootstrap
|
|||
class Engine < ::Rails::Engine
|
||||
initializer 'bootstrap-sass.assets.precompile' do |app|
|
||||
%w(stylesheets javascripts fonts images).each do |sub|
|
||||
app.config.assets.paths << root.join('assets', sub)
|
||||
app.config.assets.paths << root.join('assets', sub).to_s
|
||||
end
|
||||
app.config.assets.precompile << %r(bootstrap/glyphicons-halflings-regular\.(?:eot|svg|ttf|woff)$)
|
||||
end
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
require 'find'
|
||||
require 'bootstrap-sass'
|
||||
require 'json'
|
||||
require 'pathname'
|
||||
|
||||
|
@ -13,6 +12,7 @@ namespace :bower do
|
|||
|
||||
desc 'update main and version in bower.json'
|
||||
task :generate do
|
||||
require 'bootstrap-sass'
|
||||
Dir.chdir Bootstrap.gem_path do
|
||||
spec = JSON.parse(File.read 'bower.json')
|
||||
js_paths = File.read(File.join Bootstrap.javascripts_path, 'bootstrap-sprockets.js').lines.map do |line|
|
||||
|
|
|
@ -89,7 +89,7 @@ class Converter
|
|||
when 'variables.less'
|
||||
file = insert_default_vars(file)
|
||||
file = unindent <<-SCSS + "\n" + file, 14
|
||||
// When true, asset path helpers are used, otherwise regular `url()`` is used.
|
||||
// When true, asset path helpers are used, otherwise the regular CSS `url()` is used.
|
||||
// When there no function is defined, `fn('')` is parsed as string that equals the right hand side
|
||||
// NB: in Sass 3.3 there is a native function: function-exists(twbs-font-path)
|
||||
$bootstrap-sass-asset-helper: #{sass_fn_exists('twbs-font-path')} !default;
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
require 'test_helper'
|
||||
|
||||
class CompassTest < Test::Unit::TestCase
|
||||
class CompassTest < Minitest::Test
|
||||
def test_create_project
|
||||
command = 'rm -rf tmp/new-compass-project; bundle exec compass create tmp/new-compass-project -r bootstrap-sass --using bootstrap --trace --force'
|
||||
success = if ENV['VERBOSE']
|
||||
system command
|
||||
else
|
||||
silence_stream(STDOUT) { system(command) }
|
||||
end
|
||||
success = silence_stdout_if(!ENV['VERBOSE']) { system(command) }
|
||||
assert success, 'Compass project creation failed!'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
require 'test_helper'
|
||||
require 'fileutils'
|
||||
require 'sass'
|
||||
|
||||
class CompilationTest < Test::Unit::TestCase
|
||||
class CompilationTest < Minitest::Test
|
||||
def test_compilation
|
||||
path = 'assets/stylesheets'
|
||||
%w(_bootstrap bootstrap/_theme).each do |file|
|
||||
engine = Sass::Engine.for_file("#{path}/#{file}.scss", syntax: :scss, load_paths: [path])
|
||||
assert_nothing_raised do
|
||||
FileUtils.mkdir_p("tmp/#{File.dirname(file)}")
|
||||
File.open("tmp/#{file}.css", 'w') { |f|
|
||||
f.write engine.render
|
||||
}
|
||||
end
|
||||
FileUtils.mkdir_p("tmp/#{File.dirname(file)}")
|
||||
File.open("tmp/#{file}.css", 'w') { |f|
|
||||
f.write engine.render
|
||||
}
|
||||
assert true # nothing was raised
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
== README
|
||||
|
||||
This is a dummy app for testing REP
|
||||
This is a minimal Rails app for testing
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
||||
load Gem.bin_path('bundler', 'bundle')
|
|
@ -1,4 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
||||
require_relative '../config/boot'
|
||||
require 'rails/commands'
|
|
@ -1,4 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
require_relative '../config/boot'
|
||||
require 'rake'
|
||||
Rake.application.run
|
|
@ -1,6 +1,15 @@
|
|||
require File.expand_path('../boot', __FILE__)
|
||||
|
||||
require 'rails/all'
|
||||
require 'rails'
|
||||
|
||||
%w(
|
||||
action_controller
|
||||
action_view
|
||||
sprockets
|
||||
).each do |framework|
|
||||
require "#{framework}/railtie"
|
||||
end
|
||||
|
||||
require 'slim-rails'
|
||||
require 'jquery-rails'
|
||||
require 'compass'
|
||||
|
@ -10,6 +19,12 @@ require 'uglifier'
|
|||
module Dummy
|
||||
class Application < Rails::Application
|
||||
config.assets.enabled = true if config.assets.respond_to?(:enabled)
|
||||
config.to_prepare do
|
||||
if ENV['VERBOSE']
|
||||
STDERR.puts "Loaded Rails #{Rails::VERSION::STRING}, Sprockets #{Sprockets::VERSION}",
|
||||
"Asset paths: #{Rails.application.config.assets.paths}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>The page you were looking for doesn't exist (404)</title>
|
||||
<style>
|
||||
body {
|
||||
background-color: #EFEFEF;
|
||||
color: #2E2F30;
|
||||
text-align: center;
|
||||
font-family: arial, sans-serif;
|
||||
}
|
||||
|
||||
div.dialog {
|
||||
width: 25em;
|
||||
margin: 4em auto 0 auto;
|
||||
border: 1px solid #CCC;
|
||||
border-right-color: #999;
|
||||
border-left-color: #999;
|
||||
border-bottom-color: #BBB;
|
||||
border-top: #B00100 solid 4px;
|
||||
border-top-left-radius: 9px;
|
||||
border-top-right-radius: 9px;
|
||||
background-color: white;
|
||||
padding: 7px 4em 0 4em;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 100%;
|
||||
color: #730E15;
|
||||
line-height: 1.5em;
|
||||
}
|
||||
|
||||
body > p {
|
||||
width: 33em;
|
||||
margin: 0 auto 1em;
|
||||
padding: 1em 0;
|
||||
background-color: #F7F7F7;
|
||||
border: 1px solid #CCC;
|
||||
border-right-color: #999;
|
||||
border-bottom-color: #999;
|
||||
border-bottom-left-radius: 4px;
|
||||
border-bottom-right-radius: 4px;
|
||||
border-top-color: #DADADA;
|
||||
color: #666;
|
||||
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<!-- This file lives in public/404.html -->
|
||||
<div class="dialog">
|
||||
<h1>The page you were looking for doesn't exist.</h1>
|
||||
<p>You may have mistyped the address or the page may have moved.</p>
|
||||
</div>
|
||||
<p>If you are the application owner check the logs for more information.</p>
|
||||
</body>
|
||||
</html>
|
|
@ -1,58 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>The change you wanted was rejected (422)</title>
|
||||
<style>
|
||||
body {
|
||||
background-color: #EFEFEF;
|
||||
color: #2E2F30;
|
||||
text-align: center;
|
||||
font-family: arial, sans-serif;
|
||||
}
|
||||
|
||||
div.dialog {
|
||||
width: 25em;
|
||||
margin: 4em auto 0 auto;
|
||||
border: 1px solid #CCC;
|
||||
border-right-color: #999;
|
||||
border-left-color: #999;
|
||||
border-bottom-color: #BBB;
|
||||
border-top: #B00100 solid 4px;
|
||||
border-top-left-radius: 9px;
|
||||
border-top-right-radius: 9px;
|
||||
background-color: white;
|
||||
padding: 7px 4em 0 4em;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 100%;
|
||||
color: #730E15;
|
||||
line-height: 1.5em;
|
||||
}
|
||||
|
||||
body > p {
|
||||
width: 33em;
|
||||
margin: 0 auto 1em;
|
||||
padding: 1em 0;
|
||||
background-color: #F7F7F7;
|
||||
border: 1px solid #CCC;
|
||||
border-right-color: #999;
|
||||
border-bottom-color: #999;
|
||||
border-bottom-left-radius: 4px;
|
||||
border-bottom-right-radius: 4px;
|
||||
border-top-color: #DADADA;
|
||||
color: #666;
|
||||
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<!-- This file lives in public/422.html -->
|
||||
<div class="dialog">
|
||||
<h1>The change you wanted was rejected.</h1>
|
||||
<p>Maybe you tried to change something you didn't have access to.</p>
|
||||
</div>
|
||||
<p>If you are the application owner check the logs for more information.</p>
|
||||
</body>
|
||||
</html>
|
|
@ -1,57 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>We're sorry, but something went wrong (500)</title>
|
||||
<style>
|
||||
body {
|
||||
background-color: #EFEFEF;
|
||||
color: #2E2F30;
|
||||
text-align: center;
|
||||
font-family: arial, sans-serif;
|
||||
}
|
||||
|
||||
div.dialog {
|
||||
width: 25em;
|
||||
margin: 4em auto 0 auto;
|
||||
border: 1px solid #CCC;
|
||||
border-right-color: #999;
|
||||
border-left-color: #999;
|
||||
border-bottom-color: #BBB;
|
||||
border-top: #B00100 solid 4px;
|
||||
border-top-left-radius: 9px;
|
||||
border-top-right-radius: 9px;
|
||||
background-color: white;
|
||||
padding: 7px 4em 0 4em;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 100%;
|
||||
color: #730E15;
|
||||
line-height: 1.5em;
|
||||
}
|
||||
|
||||
body > p {
|
||||
width: 33em;
|
||||
margin: 0 auto 1em;
|
||||
padding: 1em 0;
|
||||
background-color: #F7F7F7;
|
||||
border: 1px solid #CCC;
|
||||
border-right-color: #999;
|
||||
border-bottom-color: #999;
|
||||
border-bottom-left-radius: 4px;
|
||||
border-bottom-right-radius: 4px;
|
||||
border-top-color: #DADADA;
|
||||
color: #666;
|
||||
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<!-- This file lives in public/500.html -->
|
||||
<div class="dialog">
|
||||
<h1>We're sorry, but something went wrong.</h1>
|
||||
</div>
|
||||
<p>If you are the application owner check the logs for more information.</p>
|
||||
</body>
|
||||
</html>
|
|
@ -1,7 +1,7 @@
|
|||
require 'test_helper'
|
||||
require 'json'
|
||||
|
||||
class NodeMincerTest < Test::Unit::TestCase
|
||||
class NodeMincerTest < Minitest::Test
|
||||
DUMMY_PATH = 'test/dummy_node_mincer'
|
||||
|
||||
def test_font_helper_without_suffix
|
||||
|
@ -21,13 +21,14 @@ class NodeMincerTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def setup
|
||||
tmp_dir = File.join Bootstrap.gem_path, 'tmp/node-mincer'
|
||||
tmp_dir = File.join GEM_PATH, 'tmp/node-mincer'
|
||||
command = "node manifest.js #{tmp_dir}"
|
||||
Dir.chdir DUMMY_PATH do
|
||||
assert silence_stream(STDOUT) {
|
||||
success = Dir.chdir DUMMY_PATH do
|
||||
silence_stdout_if !ENV['VERBOSE'] do
|
||||
system(command)
|
||||
}, 'Node.js Mincer compilation failed'
|
||||
end
|
||||
end
|
||||
assert success, 'Node.js Mincer compilation failed'
|
||||
manifest = JSON.parse(File.read("#{tmp_dir}/manifest.json"))
|
||||
css_name = manifest["assets"]["application.css"]
|
||||
@css = File.read("#{tmp_dir}/#{css_name}")
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
require 'test_helper'
|
||||
require 'fileutils'
|
||||
|
||||
class NodeSassTest < Test::Unit::TestCase
|
||||
class NodeSassTest < Minitest::Test
|
||||
def test_node_sass_compilation
|
||||
path = 'assets/stylesheets'
|
||||
%w(bootstrap bootstrap/_theme).each do |file|
|
||||
FileUtils.mkdir_p "tmp/node-sass"
|
||||
FileUtils.mkdir_p 'tmp/node-sass'
|
||||
command = "node-sass #{path}/#{file} -o tmp/node-sass/#{File.basename file}.css"
|
||||
assert silence_stream(STDOUT) {
|
||||
system(command)
|
||||
}, 'node-sass compilation failed'
|
||||
success = silence_stderr_if !ENV['VERBOSE'] do
|
||||
system command
|
||||
end
|
||||
assert success, 'node-sass compilation failed'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'test_helper_rails'
|
||||
|
||||
class PagesTest < ActionDispatch::IntegrationTest
|
||||
include ::IntegrationTest
|
||||
include ::DummyRailsIntegration
|
||||
|
||||
def test_visit_root
|
||||
visit root_path
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require 'test_helper'
|
||||
require 'shellwords'
|
||||
|
||||
class SassTest < Test::Unit::TestCase
|
||||
class SassTest < Minitest::Test
|
||||
DUMMY_PATH = 'test/dummy_sass_only'
|
||||
|
||||
def test_font_helper
|
||||
|
@ -12,13 +13,14 @@ class SassTest < Test::Unit::TestCase
|
|||
%x[rm -rf .sass-cache/]
|
||||
%x[bundle]
|
||||
end
|
||||
css_path = File.join Bootstrap.gem_path, 'tmp/bootstrap-sass-only.css'
|
||||
command = "bundle exec ruby compile.rb #{css_path}"
|
||||
Dir.chdir DUMMY_PATH do
|
||||
assert silence_stream(STDOUT) {
|
||||
css_path = File.join GEM_PATH, 'tmp/bootstrap-sass-only.css'
|
||||
command = "bundle exec ruby compile.rb #{Shellwords.escape css_path}"
|
||||
success = Dir.chdir DUMMY_PATH do
|
||||
silence_stdout_if !ENV['VERBOSE'] do
|
||||
system(command)
|
||||
}, 'Sass-only compilation failed'
|
||||
end
|
||||
end
|
||||
assert success, 'Sass-only compilation failed'
|
||||
@css = File.read(css_path)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,12 +3,18 @@ require 'fileutils'
|
|||
require 'find'
|
||||
require 'shellwords'
|
||||
|
||||
class SprocketsRailsTest < ActiveSupport::TestCase
|
||||
class SprocketsRailsTest < Minitest::Test
|
||||
|
||||
def test_sprockets_digest_asset_refs
|
||||
system "cd #{Shellwords.escape Rails.root.to_s} && bundle exec rake assets:precompile GEMFILE=#{Bootstrap.gem_path}/Gemfile RAILS_ENV=production"
|
||||
Dir.glob(Rails.root.join('public', 'assets', 'app*.*')) do |path|
|
||||
next unless path =~ /\.(css|js)$/
|
||||
root = 'test/dummy_rails'
|
||||
command = "bundle exec rake assets:precompile GEMFILE=#{GEM_PATH}/Gemfile RAILS_ENV=production"
|
||||
compiled = Dir.chdir root do
|
||||
silence_stderr_if !ENV['VERBOSE'] do
|
||||
system(command)
|
||||
end
|
||||
end
|
||||
assert compiled, 'Could not precompile assets'
|
||||
Dir.glob(File.join(root, 'public', 'assets', 'app*.{css,js}')) do |path|
|
||||
File.open(path, 'r') do |f|
|
||||
f.read.scan /url\("?[^"]+\.(?:jpg|png|eot|woff|ttf|svg)[^"]*"?\)/ do |m|
|
||||
assert_match /-[0-9a-f]{12,}\./, m
|
||||
|
@ -16,6 +22,6 @@ class SprocketsRailsTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
ensure
|
||||
system "rm -rf #{Rails.root}/public/assets/ #{Rails.root}/tmp/cache/"
|
||||
FileUtils.rm_rf %W(#{root}/public/assets/ #{root}/tmp/cache/), secure: true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
require 'capybara'
|
||||
require 'fileutils'
|
||||
module DummyRailsIntegration
|
||||
include Capybara::DSL
|
||||
|
||||
def setup
|
||||
super
|
||||
FileUtils.rm_rf('test/dummy_rails/tmp/cache', secure: true)
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
Capybara.reset_sessions!
|
||||
Capybara.use_default_driver
|
||||
end
|
||||
|
||||
def screenshot!
|
||||
path = "tmp/#{name}.png"
|
||||
page.driver.render(File.join(GEM_PATH, path), full: true)
|
||||
STDERR.puts "Screenshot saved to #{path}"
|
||||
end
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
require 'capybara'
|
||||
module IntegrationTest
|
||||
include Capybara::DSL
|
||||
|
||||
def setup
|
||||
super
|
||||
%x[rm -rf test/dummy_rails/tmp/cache]
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
Capybara.reset_sessions!
|
||||
Capybara.use_default_driver
|
||||
end
|
||||
|
||||
def screenshot!
|
||||
screenshot_dir = File.expand_path('../../tmp/', File.dirname(__FILE__))
|
||||
page.driver.render(File.join(screenshot_dir, "#{name}.png"), :full => true)
|
||||
source = page.evaluate_script("document.getElementsByTagName('html')[0].outerHTML") rescue nil
|
||||
File.open(File.join(screenshot_dir, "#{name}.html"), 'w') { |f| f.write(source) } if source
|
||||
end
|
||||
end
|
|
@ -0,0 +1,17 @@
|
|||
module Kernel
|
||||
def silence_stdout_if(cond, &run)
|
||||
silence_stream_if(cond, STDOUT, &run)
|
||||
end
|
||||
|
||||
def silence_stderr_if(cond, &run)
|
||||
silence_stream_if(cond, STDERR, &run)
|
||||
end
|
||||
|
||||
def silence_stream_if(cond, stream, &run)
|
||||
if cond
|
||||
silence_stream(stream, &run)
|
||||
else
|
||||
run.call
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,12 +1,17 @@
|
|||
$:.unshift("#{File.dirname(__FILE__)}/..")
|
||||
require 'minitest/autorun'
|
||||
require 'minitest/reporters'
|
||||
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
||||
|
||||
require 'test-unit'
|
||||
require 'sass'
|
||||
require 'active_support/core_ext/kernel/reporting'
|
||||
|
||||
Dir[File.expand_path('./support/**/*.rb', File.dirname(__FILE__))].each do |file|
|
||||
require file
|
||||
Dir.chdir 'test' do
|
||||
Dir['support/**/*.rb'].each do |file|
|
||||
require file
|
||||
end
|
||||
end
|
||||
|
||||
GEM_PATH = File.expand_path('../', File.dirname(__FILE__))
|
||||
|
||||
#= Capybara + Poltergeist
|
||||
require 'capybara/poltergeist'
|
||||
|
||||
|
@ -16,7 +21,7 @@ Capybara.register_driver :poltergeist do |app|
|
|||
# inspector: '/Applications/Chromium.app/Contents/MacOS/Chromium', # open in inspector: page.driver.debug
|
||||
window_size: [1280, 1024],
|
||||
timeout: 90,
|
||||
js_errors: true, debug: true
|
||||
js_errors: true
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
ENV['RAILS_ENV'] = ENV['RACK_ENV'] = 'test'
|
||||
|
||||
require 'test_helper'
|
||||
require 'test/dummy_rails/config/environment'
|
||||
require 'dummy_rails/config/environment'
|
||||
require 'rails/test_help'
|
||||
require 'capybara/rails'
|
||||
|
|
Загрузка…
Ссылка в новой задаче