rspec-respect_selector_limit 0.0.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -6
- data/lib/rspec/respect_selector_limit.rb +2 -23
- data/lib/rspec/respect_selector_limit/precompiled_css_files.rb +11 -0
- data/lib/rspec/respect_selector_limit/respect_selector_limit_matcher.rb +32 -0
- data/lib/rspec/respect_selector_limit/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3aa9950684452348b08065d14553d78c164d88a
|
4
|
+
data.tar.gz: a3c6ea3aa20c5d3ccf0c45597b58db08ffd9799f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0491155d7f03396f8a26ed2e39d7912babf03e4095c5b44f35b02c18ef9a6e90ad50aaf45297783c232abe76e11f66ec83cc0746f3265c203e0a528de55b70f
|
7
|
+
data.tar.gz: 741e3e1d00d67fc75a8aa18015f9b056e9ec55c1885e4fca032785429c0cea34ee5fef741e477168a0f44f8be38d56297cddafdefd5d6cf1d5bb99cd64714b23
|
data/README.md
CHANGED
@@ -18,12 +18,9 @@ it 'validates application.css' do
|
|
18
18
|
expect('application.css').to respect_selector_limit
|
19
19
|
end
|
20
20
|
|
21
|
-
#
|
22
|
-
it 'validates all CSS files' do
|
23
|
-
|
24
|
-
css_files.each do |file|
|
25
|
-
expect(file).to respect_selector_limit
|
26
|
-
end
|
21
|
+
# (optional) validate all configured CSS files
|
22
|
+
it 'validates all precompiled CSS files' do
|
23
|
+
expect(precompiled_css_files).to respect_selector_limit
|
27
24
|
end
|
28
25
|
```
|
29
26
|
|
@@ -1,23 +1,2 @@
|
|
1
|
-
require 'rspec/
|
2
|
-
require '
|
3
|
-
|
4
|
-
RSpec::Matchers.define :respect_selector_limit do
|
5
|
-
def max_selectors
|
6
|
-
4095
|
7
|
-
end
|
8
|
-
|
9
|
-
match do |asset|
|
10
|
-
css = Rails.application.assets[asset].body
|
11
|
-
|
12
|
-
parser = CssParser::Parser.new
|
13
|
-
parser.add_block!(css)
|
14
|
-
|
15
|
-
@count = 0
|
16
|
-
parser.each_selector { @count += 1 }
|
17
|
-
@count < max_selectors
|
18
|
-
end
|
19
|
-
|
20
|
-
failure_message do |asset|
|
21
|
-
"expected #{asset} to have less than #{max_selectors} css selectors but had #{@count}"
|
22
|
-
end
|
23
|
-
end
|
1
|
+
require 'rspec/respect_selector_limit/precompiled_css_files'
|
2
|
+
require 'rspec/respect_selector_limit/respect_selector_limit_matcher'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module PrecompiledCssFiles
|
2
|
+
def precompiled_css_files
|
3
|
+
app = Rails.application
|
4
|
+
precompiled_assets = app.config.assets.precompile
|
5
|
+
app.assets.each_logical_path(*precompiled_assets).to_a.grep(/\.css\z/)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.include PrecompiledCssFiles
|
11
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rspec/expectations'
|
2
|
+
require 'css_parser'
|
3
|
+
|
4
|
+
RSpec::Matchers.define :respect_selector_limit do
|
5
|
+
def max_selectors
|
6
|
+
4095
|
7
|
+
end
|
8
|
+
|
9
|
+
def valid_asset?(asset)
|
10
|
+
css = Rails.application.assets[asset].body
|
11
|
+
|
12
|
+
parser = CssParser::Parser.new
|
13
|
+
parser.add_block!(css)
|
14
|
+
|
15
|
+
@count = 0
|
16
|
+
parser.each_selector { @count += 1 }
|
17
|
+
@count < max_selectors
|
18
|
+
end
|
19
|
+
|
20
|
+
match do |assets|
|
21
|
+
@failed_assets = []
|
22
|
+
Array(assets).each do |asset|
|
23
|
+
@failed_assets << asset unless valid_asset?(asset)
|
24
|
+
end
|
25
|
+
|
26
|
+
@failed_assets.empty?
|
27
|
+
end
|
28
|
+
|
29
|
+
failure_message do |asset|
|
30
|
+
"#{@failed_assets} have more than #{max_selectors} CSS selectors"
|
31
|
+
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-respect_selector_limit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Sonnek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -79,6 +79,8 @@ files:
|
|
79
79
|
- README.md
|
80
80
|
- Rakefile
|
81
81
|
- lib/rspec/respect_selector_limit.rb
|
82
|
+
- lib/rspec/respect_selector_limit/precompiled_css_files.rb
|
83
|
+
- lib/rspec/respect_selector_limit/respect_selector_limit_matcher.rb
|
82
84
|
- lib/rspec/respect_selector_limit/version.rb
|
83
85
|
- rspec-respect_selector_limit.gemspec
|
84
86
|
homepage: ''
|