Skip to content

Commit d294837

Browse files
Add basic testing suite
1 parent 2ecd852 commit d294837

13 files changed

+48
-6
lines changed

Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ group :development, :test do
77
gem 'byebug', platform: [:ruby], require: false
88
gem 'rubocop', require: false
99
gem 'rspec-rails', '~> 3.6'
10+
gem 'capybara', '~> 2.16'
11+
gem 'pry-rails'
1012
end
1113

1214
# HACK: npm install on bundle

app_container_name

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
criticalpathcss_ruby

config.ru

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
require 'rubygems'
22
require 'bundler'
3+
require 'combustion'
34

4-
Bundler.require :default, :development
5-
6-
Combustion.initialize! :all
5+
Combustion.initialize! :action_controller, :action_view
76
run Combustion::Application

docker-compose.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ services:
44
build:
55
context: .
66
dockerfile: docker/ruby/Dockerfile
7+
ports:
8+
- 9292:9292
79
volumes:
810
- .:/app:rw
911
volumes_from:
1012
- data
1113
env_file: docker/ruby/.env
1214
container_name: criticalpathcss_ruby
13-
1415
data:
1516
build:
1617
context: .

docker/ruby/startup.dev

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
bundle check || bundle install
44

5-
tail -f /dev/null
5+
bundle exec rackup --host 0.0.0.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class RootController < ActionController::Base
2+
def index; end
3+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<html>
2+
<head></head>
3+
<body><%= yield %></body>
4+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p><%= CriticalPathCss.fetch(request.path) %></p>
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
defaults: &defaults
2+
base_url: http://0.0.0.0:9292
3+
css_path: /test.css
4+
routes:
5+
- /
6+
7+
development:
8+
<<: *defaults
9+
10+
test:
11+
<<: *defaults

spec/internal/config/routes.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Rails.application.routes.draw do
2-
#
2+
root 'root#index'
33
end

spec/internal/public/test.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
p {
2+
color: red;
3+
}

spec/spec_helper.rb

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Combustion.initialize! :action_controller, :action_view
88

99
require 'rspec/rails'
10+
require 'capybara/rails'
1011

1112
RSpec.configure do |config|
1213
config.use_transactional_fixtures = true
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require 'spec_helper.rb'
2+
3+
RSpec.describe 'fetching the critical css' do
4+
before do
5+
CriticalPathCss.generate_all
6+
end
7+
8+
context 'on the root page' do
9+
let(:route) { '/' }
10+
11+
it 'displays the correct critical CSS' do
12+
visit route
13+
expect(page).to have_content 'color: red;'
14+
end
15+
end
16+
end

0 commit comments

Comments
 (0)