Skip to content

Commit 26ad228

Browse files
committed
Test with Rails master
Also test that Autoprefixer is applied
1 parent c3a74da commit 26ad228

9 files changed

Lines changed: 86 additions & 22 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ rvm:
44
- 2.2
55
gemfile:
66
- test/gemfiles/rails_4_2.gemfile
7+
- test/gemfiles/rails_head.gemfile
78
cache: bundler
89
bundler_args: --path ../../vendor/bundle --without debug
910
notifications:

Rakefile

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,49 @@ Rake::TestTask.new do |t|
88
t.verbose = true
99
end
1010

11+
desc 'Test all Gemfiles from test/*.gemfile'
12+
task :test_all_gemfiles do
13+
require 'term/ansicolor'
14+
require 'pty'
15+
require 'shellwords'
16+
cmd = 'bundle install --quiet && bundle exec rake --trace'
17+
statuses = Dir.glob('./test/gemfiles/*{[!.lock]}').map do |gemfile|
18+
env = {'BUNDLE_GEMFILE' => gemfile}
19+
cmd_with_env = " (#{env.map { |k, v| "export #{k}=#{Shellwords.escape v}" } * ' '}; #{cmd})"
20+
$stderr.puts Term::ANSIColor.cyan("Testing\n#{cmd_with_env}")
21+
PTY.spawn(env, cmd) do |r, _w, pid|
22+
begin
23+
r.each_line { |l| puts l }
24+
rescue Errno::EIO
25+
# Errno:EIO error means that the process has finished giving output.
26+
ensure
27+
::Process.wait pid
28+
end
29+
end
30+
[$? && $?.exitstatus == 0, cmd_with_env]
31+
end
32+
failed_cmds = statuses.reject(&:first).map { |(_status, cmd_with_env)| cmd_with_env }
33+
if failed_cmds.empty?
34+
$stderr.puts Term::ANSIColor.green('Tests pass with all gemfiles')
35+
else
36+
$stderr.puts Term::ANSIColor.red("Failing (#{failed_cmds.size} / #{statuses.size})\n#{failed_cmds * "\n"}")
37+
exit 1
38+
end
39+
end
40+
1141
desc 'Dumps output to a CSS file for testing'
1242
task :debug do
1343
require 'sass'
1444
require './lib/bootstrap'
1545
require 'term/ansicolor'
46+
require 'autoprefixer-rails'
1647
path = Bootstrap.stylesheets_path
1748
%w(_bootstrap _bootstrap-flex _bootstrap-reboot _bootstrap-grid).each do |file|
1849
engine = Sass::Engine.for_file("#{path}/#{file}.scss", syntax: :scss, load_paths: [path])
1950
out = File.join('tmp', "#{file[1..-1]}.css")
20-
File.write(out, engine.render)
51+
css = engine.render
52+
css = AutoprefixerRails.process(css)
53+
File.write(out, css)
2154
$stderr.puts Term::ANSIColor.green "Compiled #{out}"
2255
end
2356
end

bootstrap.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ Gem::Specification.new do |s|
1212
s.license = 'MIT'
1313

1414
s.add_runtime_dependency 'sass', '>= 3.4.18'
15-
s.add_runtime_dependency 'autoprefixer-rails', '>= 5.2.1.3'
15+
s.add_runtime_dependency 'autoprefixer-rails', '>= 6.0.3'
1616

1717
# Testing dependencies
1818
s.add_development_dependency 'minitest', '~> 5.8.0'
1919
s.add_development_dependency 'minitest-reporters', '~> 1.0.5'
2020
s.add_development_dependency 'compass', '~> 1.0.3'
21+
s.add_development_dependency 'term-ansicolor'
2122
# Integration testing
2223
s.add_development_dependency 'capybara'
2324
s.add_development_dependency 'poltergeist'

test/dummy_rails/config/application.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
module Dummy
2323
class Application < Rails::Application
2424
config.assets.enabled = true if config.assets.respond_to?(:enabled)
25+
config.assets.precompile += %w( application.css application.js )
2526
config.to_prepare do
2627
if ENV['VERBOSE']
2728
STDERR.puts "Loaded Rails #{Rails::VERSION::STRING}, Sprockets #{Sprockets::VERSION}",

test/gemfiles/rails_head.gemfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
source "https://rubygems.org"
2+
3+
gem 'actionpack', github: 'rails/rails'
4+
gem 'activesupport', github: 'rails/rails'
5+
6+
# Required git dependencies as per https://github.com/rails/rails/blob/51211a94bd7a34d80f2412a7f94fefe7366647a5/Gemfile:
7+
gem 'rack', github: 'rack/rack'
8+
gem 'sprockets', github: 'rails/sprockets'
9+
gem 'sprockets-rails', github: 'rails/sprockets-rails'
10+
gem 'sass-rails', github: 'rails/sass-rails', branch: 'master'
11+
12+
gem 'autoprefixer-rails', github: 'glebm/autoprefixer-rails', branch: 'rails5-compat'
13+
14+
source 'https://rails-assets.org' do
15+
gem 'rails-assets-tether', '>= 1.1.0'
16+
end
17+
18+
gemspec path: '../../'
19+

test/gemfiles/sass_3_3.gemfile

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/pages_test.rb

Lines changed: 0 additions & 14 deletions
This file was deleted.

test/rails_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require 'test_helper_rails'
2+
3+
class RailsTest < ActionDispatch::IntegrationTest
4+
include ::DummyRailsIntegration
5+
6+
def test_visit_root
7+
visit root_path
8+
# ^ will raise on JS errors
9+
10+
assert_equal 200, page.status_code
11+
12+
screenshot!
13+
end
14+
15+
def test_autoprefixer
16+
get ActionController::Base.helpers.stylesheet_path('application.css')
17+
assert_match /-webkit-(?:transition|transform)/, response.body
18+
end
19+
end

test/support/reporting.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,14 @@ def silence_stream_if(cond, stream, &run)
1414
run.call
1515
end
1616
end
17+
18+
def silence_stream(stream)
19+
old_stream = stream.dup
20+
stream.reopen(File::NULL)
21+
stream.sync = true
22+
yield
23+
ensure
24+
stream.reopen(old_stream)
25+
old_stream.close
26+
end unless method_defined?(:silence_stream)
1727
end

0 commit comments

Comments
 (0)