rspec-respect_selector_limit 0.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 096466b4d88a48afd701c20cd7a7838cde822dd4
4
- data.tar.gz: f82f7f67882b73ceabc82301064bc42bfa724b82
3
+ metadata.gz: a3aa9950684452348b08065d14553d78c164d88a
4
+ data.tar.gz: a3c6ea3aa20c5d3ccf0c45597b58db08ffd9799f
5
5
  SHA512:
6
- metadata.gz: 5b2cb9c61b0cf3b8ddb4c4aab9ce76af62c2aa8959947a263ba7acf79f3155b095d9022a3f532d5cf9a0b391fdc7b30c4c933eded5546ba898650d029ba9645c
7
- data.tar.gz: 73e2ce2ceafe8b1494da5c3e0384ad75030b19075833c1d9f586a17d5a210551f0bd70f22f238510d2a8d80b09d728f1c27a8561d4f77aaf96c4b5ee3b1815d3
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
- # advanced protip to scan all precompiled CSS files
22
- it 'validates all CSS files' do
23
- css_files = Rails.application.assets.each_logical_path(*Rails.application.config.assets.precompile).to_a.grep(/\.css/)
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/expectations'
2
- require 'css_parser'
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
@@ -1,5 +1,5 @@
1
1
  module Rspec
2
2
  module RespectSelectorLimit
3
- VERSION = "0.0.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  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.1
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-08 00:00:00.000000000 Z
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: ''