Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
shiro16 committed Aug 29, 2015
1 parent c4a5488 commit 7a818b2
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion lib/style_stats/css/selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ def initialize(name, declarations = [])
end

def identifier_count
self.name.split(/\>|\+|\~|\:|[\w\]]\.|[\w\]]\#|\[/).count
trimmed_name = self.name.gsub(/\s?([\>\+\~])\s?/) { $1 }
trimmed_name.gsub(/\s+/, ' ').split(/\s|\>|\+|\~|\:|[\w\]]\.|[\w\]]\#|\[/).count
end
end
end
2 changes: 1 addition & 1 deletion lib/style_stats/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(css, options = {})
def render
case @options[:format].to_sym
when :md, :html
text = File.read("#{File.dirname(__FILE__)}/lib/style_stats/templates/#{@options[:format]}.erb")
text = File.read("#{File.dirname(__FILE__)}/templates/#{@options[:format]}.erb")
ERB.new(text, nil, '-').run(binding)
when :json
puts @css.analyze.to_json
Expand Down
2 changes: 1 addition & 1 deletion spec/style_stats/css/selector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe StyleStats::Css::Selector do
describe '#identifier_count' do
it { expect(StyleStats::Css::Selector.new('.foo .bar > .baz + .qux ~ .quux:before').identifier_count).to eq(5) }
it { expect(StyleStats::Css::Selector.new('.foo .bar > .baz + .qux ~ .quux:before').identifier_count).to eq(6) }
it { expect(StyleStats::Css::Selector.new('.foo').identifier_count).to eq(1) }
end
end
12 changes: 6 additions & 6 deletions spec/style_stats/path_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@
describe '#fetch_files' do
context 'when path is directory' do
it do
expect(Dir).to receive(:entries).with(fixtures_path_for)
expect(Dir).to receive(:entries).with(fixtures_path_for).and_return([])
path_parser.send(:fetch_files, fixtures_path_for)
end

it {
expect(path_parser.send(:fetch_files, fixtures_path_for)).to eq([
'.',
'..',
'spec.css',
'spec.html',
'spec.txt'
fixtures_path_for('.'),
fixtures_path_for('..'),
fixtures_path_for('spec.css'),
fixtures_path_for('spec.html'),
fixtures_path_for('spec.txt')
])
}
end
Expand Down
2 changes: 1 addition & 1 deletion spec/support/path_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def fixtures_path_for(file=nil)
File.dirname(__FILE__) + '/../fixtures/' + file.to_s
'spec/fixtures/' + file.to_s
end

def spec_css_path
Expand Down

0 comments on commit 7a818b2

Please sign in to comment.