old_style 1.4.1
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 +7 -0
- data/.document +5 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +64 -0
- data/LICENSE.txt +20 -0
- data/README.md +71 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/app/assets/stylesheets/fake3.css.scss +13 -0
- data/app/assets/stylesheets/fake4.css +4 -0
- data/app/views/fake/fake.html.erb +13 -0
- data/app/views/fake/fake2.html +4 -0
- data/base.css +131 -0
- data/bin/old_style +6 -0
- data/lib/format.rb +112 -0
- data/lib/html_parser.rb +40 -0
- data/lib/load_dir.rb +35 -0
- data/lib/old_style.rb +5 -0
- data/lib/parse_dir.rb +92 -0
- data/old_style/index.css +131 -0
- data/old_style/index.html +5 -0
- data/old_style.gemspec +83 -0
- data/test/helper.rb +39 -0
- data/test/test_format.rb +53 -0
- data/test/test_html_parser.rb +67 -0
- data/test/test_load_dir.rb +28 -0
- data/test/test_old_style.rb +2 -0
- data/test/test_parse_dir.rb +86 -0
- metadata +158 -0
data/lib/parse_dir.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'css_parser'
|
2
|
+
require 'load_dir'
|
3
|
+
require 'format'
|
4
|
+
require 'html_parser'
|
5
|
+
|
6
|
+
class ParseDir < LoadDir
|
7
|
+
include Format
|
8
|
+
include HtmlParser
|
9
|
+
include CssParser
|
10
|
+
|
11
|
+
attr_accessor :css, :html
|
12
|
+
|
13
|
+
def initialize(args)
|
14
|
+
super(args)
|
15
|
+
@css = {}
|
16
|
+
@html = {}
|
17
|
+
self.segregate
|
18
|
+
self.parse_css
|
19
|
+
end
|
20
|
+
|
21
|
+
def css?(file)
|
22
|
+
true if /\.css\S*\z/.match(file)
|
23
|
+
end
|
24
|
+
|
25
|
+
def html?(file)
|
26
|
+
true if/\.html\S*\z/.match(file)
|
27
|
+
end
|
28
|
+
|
29
|
+
def segregate
|
30
|
+
self.files.each do |file, path|
|
31
|
+
if self.css?(file)
|
32
|
+
self.css[file] = path
|
33
|
+
elsif self.html?(file)
|
34
|
+
self.html[file] = path
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def parse_css
|
40
|
+
hash = {}
|
41
|
+
self.css.each do |file, path|
|
42
|
+
parser = CssParser::Parser.new
|
43
|
+
parser.load_file!(file, path, :all)
|
44
|
+
parser.each_selector(:all) do |selector, dec, spec|
|
45
|
+
unless /(^\/|\$|@|\d|:hover)/.match(selector)
|
46
|
+
hash[selector] = dec
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
hash
|
51
|
+
end
|
52
|
+
|
53
|
+
def found hash=self.parse_css
|
54
|
+
tmp = {}
|
55
|
+
self.html.each do |file|
|
56
|
+
hash.each do |sel, des|
|
57
|
+
if sel.match("#")
|
58
|
+
tmp[sel] = des if id_exists?(sel, file.last) == true
|
59
|
+
elsif sel.match(/^\./)
|
60
|
+
tmp[sel] = des if class_exists?(sel, file.last) == true
|
61
|
+
elsif sel.match(/^\w/)
|
62
|
+
tmp[sel] = des if parent_exists?(sel, file.last) == true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
tmp
|
67
|
+
end
|
68
|
+
|
69
|
+
def empty
|
70
|
+
hash = {}
|
71
|
+
all = self.parse_css.inject([]) {|a, k| a << k}
|
72
|
+
found_css = self.found.inject([]) {|a, k| a << k}
|
73
|
+
empty_css = all - found_css
|
74
|
+
empty_css.each {|arr| hash[arr.first] = arr.last}
|
75
|
+
hash
|
76
|
+
end
|
77
|
+
|
78
|
+
def success?
|
79
|
+
if self.write_index
|
80
|
+
ParseDir.success_message
|
81
|
+
else
|
82
|
+
ParseDir.failure_message
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.success_message
|
87
|
+
puts Time.now.strftime("%B %d %Y %r")
|
88
|
+
puts "Your report was generated at #{Dir.pwd}/old_style/index/html"
|
89
|
+
true
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
data/old_style/index.css
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
|
2
|
+
li {list-style: none;}
|
3
|
+
|
4
|
+
a {text-decoration: none;
|
5
|
+
}
|
6
|
+
|
7
|
+
body {background-color: #efefef;
|
8
|
+
margin: 0 0 0 0;
|
9
|
+
}
|
10
|
+
|
11
|
+
#header{height: 50px;
|
12
|
+
width: 100%;
|
13
|
+
background-color: #3EA4ED;
|
14
|
+
font-family: "HelveticaNeue-Light",
|
15
|
+
}
|
16
|
+
|
17
|
+
#main-heading {padding: 20px 0 20px 5%;
|
18
|
+
font-size: 20px;
|
19
|
+
color: #B2D4ED;
|
20
|
+
}
|
21
|
+
|
22
|
+
#content {padding: 30px 5% 5% 5%;
|
23
|
+
line-height: 1.4;
|
24
|
+
font-family: "HelveticaNeue-Light",
|
25
|
+
"Helvetica Neue Light",
|
26
|
+
"Helvetica Neue",
|
27
|
+
"Helvetica Helvetica",
|
28
|
+
"Helvetica",
|
29
|
+
"Arial",
|
30
|
+
"Lucida Grande",
|
31
|
+
"sans-serif";
|
32
|
+
font-weight 300;
|
33
|
+
}
|
34
|
+
|
35
|
+
#dir-heading {border-bottom: 1px solid #cccaca;}
|
36
|
+
|
37
|
+
#looked-in {width:100%;
|
38
|
+
padding-bottom: 50px;
|
39
|
+
}
|
40
|
+
|
41
|
+
#looked-css {width: 200px;
|
42
|
+
float: left;
|
43
|
+
border-right: 2px solid #cccaca;
|
44
|
+
padding-right: 10px;
|
45
|
+
}
|
46
|
+
|
47
|
+
#css-heading {border-bottom: 1px solid #cccaca;
|
48
|
+
font-size: 20px;
|
49
|
+
font-weight: bold;
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
#html-heading {border-bottom: 1px solid #cccaca;
|
54
|
+
font-size: 20px;
|
55
|
+
font-weight: bold;
|
56
|
+
}
|
57
|
+
#looked-html {width: 200px;
|
58
|
+
float: left;
|
59
|
+
padding-left: 10px;
|
60
|
+
}
|
61
|
+
|
62
|
+
#css-file:hover {color: blue;}
|
63
|
+
#html-file:hover {color: blue;}
|
64
|
+
|
65
|
+
#found-wrapper{padding: 30px 0 30px 0;
|
66
|
+
width: 100%;
|
67
|
+
float: left;
|
68
|
+
color: green;
|
69
|
+
}
|
70
|
+
|
71
|
+
#found-title-wrapper {border-bottom: 1px solid #cccaca;}
|
72
|
+
|
73
|
+
|
74
|
+
#found-css {padding-right: 10px;
|
75
|
+
display: inline;
|
76
|
+
font-weight: bold;
|
77
|
+
font-size: 20px;
|
78
|
+
|
79
|
+
}
|
80
|
+
#good-percent {display: inline;
|
81
|
+
color: black;
|
82
|
+
}
|
83
|
+
|
84
|
+
#found-style-wrapper {padding-top:10px;}
|
85
|
+
|
86
|
+
#empty-wrapper {color: red;
|
87
|
+
float: left;
|
88
|
+
width: 100%;
|
89
|
+
}
|
90
|
+
|
91
|
+
#empty-title-wrapper {border-bottom: 1px solid #cccaca;
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
#empty-css {padding-right: 10px;
|
96
|
+
display: inline;
|
97
|
+
font-weight: bold;
|
98
|
+
font-size: 20px;
|
99
|
+
|
100
|
+
}
|
101
|
+
|
102
|
+
#bad-percent {display: inline;
|
103
|
+
color: black;
|
104
|
+
}
|
105
|
+
|
106
|
+
#empty-style-wrapper {padding: 10px 0 40px 0;}
|
107
|
+
|
108
|
+
|
109
|
+
#style {color: green;}
|
110
|
+
|
111
|
+
#footer {width: 100%;
|
112
|
+
float: left;
|
113
|
+
height: 200px;
|
114
|
+
background-color: #ADB3B8;
|
115
|
+
padding-top: 50px;
|
116
|
+
line-height: 1.4;
|
117
|
+
font-family: "HelveticaNeue-Light";
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
#footer-info {padding: 0 0 0 5%;
|
122
|
+
font-size: 20px;
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
#footer-caption {color: #efefef;}
|
127
|
+
|
128
|
+
#issues-link:hover {color: blue;}
|
129
|
+
|
130
|
+
|
131
|
+
|
@@ -0,0 +1,5 @@
|
|
1
|
+
<div id='header'><li id='main-heading'>
|
2
|
+
1 Controller evaluated </li></div><body><head><link rel='stylesheet' type='text/css' href=/Users/hayduke19us/my_gems/old_style/old_style/index.css></head><div id='content'><div id='directories'><h2 id='dir-heading'>["fake"]</h2></div><h4>2 css files compared to
|
3
|
+
2 html files
|
4
|
+
</h4><div id='looked-in'><div id='looked-css'><div id='css-heading'>Css</div><li><a id='css-file' href=/Users/hayduke19us/my_gems/old_style/app/assets/stylesheets/fake3.css.scss>fake3.css.scss<a></li><li><a id='css-file' href=/Users/hayduke19us/my_gems/old_style/app/assets/stylesheets/fake4.css>fake4.css<a></li></div><div id='looked-html'><div id='html-heading'>Html</div><li><a id='html-file' href=/Users/hayduke19us/my_gems/old_style/app/views/fake/fake.html.erb>fake.html.erb<a></li><li><a id='html-file' href=/Users/hayduke19us/my_gems/old_style/app/views/fake/fake2.html>fake2.html<a></li></div></div><div id='found-wrapper'><div id='found-title-wrapper'><li id='found-css'>Good</li><li id='good-percent'> 57.14%</li></div><div id='found-style-wrapper'><li id='style'>#franny {padding: 100%;}</li><li id='style'>#salinger {color: blue;}</li><li id='style'>#test-id {border: 1px solid #efefef;}</li><li id='style'>div.well {}</li></div></div><div id='empty-wrapper'><div id='empty-title-wrapper'><h4 id='empty-css'>Bad</h4><li id='bad-percent'> 42.85%</li></div><div id='empty-style-wrapper'><li id='empty_style'>#find {color: blue;}</li><li id='empty_style'>.franny {padding: 50%;}</li><li id='empty_style'>.zooey {width: 5px;}</li></div></div></div></body><div id='footer'><div id='footer-info'><li id='footer-caption'>If you find any issues please let me know
|
5
|
+
at </li><a id ='issues-link' href = 'https://github.com/hayduke19us/old_style/issues?state=open'>old_style's issues page on github<a></div></div>
|
data/old_style.gemspec
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: old_style 1.4.1 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "old_style"
|
9
|
+
s.version = "1.4.1"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.authors = ["hayduke19us"]
|
13
|
+
s.date = "2014-02-11"
|
14
|
+
s.description = "Rails helper. Finds the irrelevent styles in your \n stylesheet and generates a html report to keep you informed."
|
15
|
+
s.email = "hayduke19us@gmail.com"
|
16
|
+
s.executables = ["old_style"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.md"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.md",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"app/assets/stylesheets/fake3.css.scss",
|
30
|
+
"app/assets/stylesheets/fake4.css",
|
31
|
+
"app/views/fake/fake.html.erb",
|
32
|
+
"app/views/fake/fake2.html",
|
33
|
+
"base.css",
|
34
|
+
"bin/old_style",
|
35
|
+
"lib/format.rb",
|
36
|
+
"lib/html_parser.rb",
|
37
|
+
"lib/load_dir.rb",
|
38
|
+
"lib/old_style.rb",
|
39
|
+
"lib/parse_dir.rb",
|
40
|
+
"old_style.gemspec",
|
41
|
+
"old_style/index.css",
|
42
|
+
"old_style/index.html",
|
43
|
+
"test/helper.rb",
|
44
|
+
"test/test_format.rb",
|
45
|
+
"test/test_html_parser.rb",
|
46
|
+
"test/test_load_dir.rb",
|
47
|
+
"test/test_old_style.rb",
|
48
|
+
"test/test_parse_dir.rb"
|
49
|
+
]
|
50
|
+
s.homepage = "http://github.com/hayduke19us/old_style"
|
51
|
+
s.licenses = ["MIT"]
|
52
|
+
s.require_paths = ["lib"]
|
53
|
+
s.rubygems_version = "2.1.11"
|
54
|
+
s.summary = "Get rid of those old css styles"
|
55
|
+
|
56
|
+
if s.respond_to? :specification_version then
|
57
|
+
s.specification_version = 4
|
58
|
+
|
59
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
60
|
+
s.add_runtime_dependency(%q<css_parser>, [">= 0"])
|
61
|
+
s.add_development_dependency(%q<minitest>, [">= 0"])
|
62
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
63
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
64
|
+
s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
|
65
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
66
|
+
else
|
67
|
+
s.add_dependency(%q<css_parser>, [">= 0"])
|
68
|
+
s.add_dependency(%q<minitest>, [">= 0"])
|
69
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
70
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
71
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
72
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
73
|
+
end
|
74
|
+
else
|
75
|
+
s.add_dependency(%q<css_parser>, [">= 0"])
|
76
|
+
s.add_dependency(%q<minitest>, [">= 0"])
|
77
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
78
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
79
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
80
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
module SimpleCov::Configuration
|
4
|
+
def clean_filters
|
5
|
+
@filters = []
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
SimpleCov.configure do
|
10
|
+
clean_filters
|
11
|
+
load_profile 'test_frameworks'
|
12
|
+
end
|
13
|
+
|
14
|
+
ENV["COVERAGE"] && SimpleCov.start do
|
15
|
+
add_filter "/.rvm/"
|
16
|
+
end
|
17
|
+
require 'rubygems'
|
18
|
+
require 'bundler'
|
19
|
+
begin
|
20
|
+
Bundler.setup(:default, :development)
|
21
|
+
rescue Bundler::BundlerError => e
|
22
|
+
$stderr.puts e.message
|
23
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
24
|
+
exit e.status_code
|
25
|
+
end
|
26
|
+
require 'minitest/autorun'
|
27
|
+
require 'minitest/pride'
|
28
|
+
|
29
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
30
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
31
|
+
require 'load_dir'
|
32
|
+
require 'format'
|
33
|
+
require 'parse_dir'
|
34
|
+
require 'html_parser'
|
35
|
+
|
36
|
+
class MiniTest::Unit::TestCase
|
37
|
+
end
|
38
|
+
|
39
|
+
MiniTest.autorun
|
data/test/test_format.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'helper'
|
2
|
+
module Format
|
3
|
+
class KlassTest < Minitest::Test
|
4
|
+
|
5
|
+
include Format
|
6
|
+
|
7
|
+
def test_if_old_style_index_html_exist_new_or_open_index_returns_IO_stream
|
8
|
+
new_or_open_index
|
9
|
+
assert_equal File, new_or_open_index.class
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_create_css_file
|
13
|
+
create_css_file?
|
14
|
+
assert File.exist?(Format::PATH + "/old_style/index.css")
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_if_css_file_exist_#create_css_file_returns_nil
|
18
|
+
create_css_file?
|
19
|
+
assert_equal nil, create_css_file?
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_css_path
|
23
|
+
assert_equal Format::PATH + "/old_style/index.css", css_path
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_base_css_file_exist
|
27
|
+
assert File.exists?("base.css")
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_base_file_can_be_read
|
31
|
+
assert_equal 131, File.readlines("base.css").count
|
32
|
+
end
|
33
|
+
|
34
|
+
# the following two test are in sequence
|
35
|
+
# the first deletes the contents of the css file
|
36
|
+
# the next one adds the css to file
|
37
|
+
|
38
|
+
def test_index_css_is_empty
|
39
|
+
#deletes file contents by File.new ('w+')
|
40
|
+
file = File.new(css_path, 'w+')
|
41
|
+
assert_equal 0, File.readlines(file).count
|
42
|
+
file.close
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_file_index_css_has_lines
|
46
|
+
#write the css from base.css file in gem
|
47
|
+
write_css
|
48
|
+
assert_equal 131, File.readlines(css_path).count
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class KlassTest < Minitest::Test
|
4
|
+
include HtmlParser
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@file = File.expand_path("../../app", __FILE__) + "/views/fake/fake.html.erb"
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_read_html_should_put_document_into_an_array
|
11
|
+
refute read_html(@file).empty?
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_remove_extras_should_remove_all_punctuation_and_whitespace
|
15
|
+
refute remove_extras(@file).join.match(/(:|<|>|=|'|')/)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_remove_extras_should_also_remove_all_whitespace
|
19
|
+
refute remove_extras(@file).join.match(' ')
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_extras_should_return_an_Array
|
23
|
+
assert_equal Array, remove_extras(@file).class
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_selector_can_match_a_tag_in_the_html_erb_doc
|
27
|
+
#and id of id: test-id id in the file
|
28
|
+
array = []
|
29
|
+
remove_extras(@file).each do |line|
|
30
|
+
array << line if line.match(/(idtest-id|idpeace)/)
|
31
|
+
refute line.match('idtear-id'), "incorrect match"
|
32
|
+
refute line.match('idtesx-id'), "incorrect match"
|
33
|
+
refute line.match('idtest-im'), "incorrect match"
|
34
|
+
end
|
35
|
+
|
36
|
+
refute array.empty?, "correct match"
|
37
|
+
assert_equal 2, array.count
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_#id_exists_then_return_true
|
41
|
+
assert_equal true, id_exists?("#test-id", @file)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_#id_doesn't_exist_returns_false
|
45
|
+
assert_equal false, id_exists?("#test-ix", @file)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_#class_exists_then_return_true
|
49
|
+
assert_equal true, class_exists?(".row", @file)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_#class_doesn't_doesn't_exist_then_return_false
|
53
|
+
refute_equal true, class_exists?(".container", @file)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_using_#class_as_a_control_structure
|
57
|
+
if class_exists?(".container", @file) == true
|
58
|
+
success = true
|
59
|
+
end
|
60
|
+
refute_equal true, success
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_id_exists
|
64
|
+
assert_equal true, id_exists?("#test-id", @file)
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class LoadDirTest < MiniTest::Test
|
4
|
+
def setup
|
5
|
+
@load_dir = LoadDir.new("fake")
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_HTML_PATH_should_be_for_views
|
9
|
+
assert_equal '/Users/hayduke19us/my_gems/old_style/app/views', LoadDir::HTML_PATH
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_CSS_PATH_should_be_for_assets_stylesheets
|
13
|
+
assert_equal '/Users/hayduke19us/my_gems/old_style/app/assets/stylesheets', LoadDir::CSS_PATH
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_LoadDir_args_is_an_array_of_dir
|
17
|
+
assert_equal Array, @load_dir.directories.class
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_directories_count_is_proper
|
21
|
+
assert_equal 1, @load_dir.directories.count
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_html_files_attribute_is_populated_after_initialization
|
25
|
+
assert_equal 4, @load_dir.files.keys.count
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'benchmark'
|
3
|
+
|
4
|
+
class ParseDirTest < MiniTest::Test
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@parse = ParseDir.new("fake")
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_attributes_of_Load_Dir
|
11
|
+
refute @parse.directories.empty?
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_html_directories_and_css_directories
|
15
|
+
refute @parse.files.empty?
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_true_if_css?
|
19
|
+
file = "playlist.css"
|
20
|
+
assert @parse.css?(file)
|
21
|
+
end
|
22
|
+
|
23
|
+
def false_if_html_with_css?
|
24
|
+
file = "playlist.html"
|
25
|
+
refute @parse.css?(file)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_true_if_html?
|
29
|
+
file = "playlist.css"
|
30
|
+
refute @parse.html?(file)
|
31
|
+
end
|
32
|
+
|
33
|
+
def false_if_css_for_html?
|
34
|
+
file = "playlist.css"
|
35
|
+
refute @parse.html?(file)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_ParseDir#segregate_puts_css_files_in_an_array
|
39
|
+
assert_equal 2, @parse.css.count
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_ParseDir#segregate_puts_html_files_in_an_array
|
43
|
+
assert_equal 2, @parse.html.count
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_parse_css_returns_hash_of_all_selectors_no_comments_no_SASS
|
47
|
+
assert_equal 7, @parse.parse_css.keys.count
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_parse_css_keys_content
|
51
|
+
a = ["#salinger", "#find", "div.well",
|
52
|
+
".franny", "#franny", ".zooey", "#test-id"]
|
53
|
+
assert_equal a, @parse.parse_css.keys
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_found_css_finds_the_relevent_css
|
57
|
+
assert_equal 4, @parse.found.keys.count
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_empty_css_returns_a_hash_of_false_selectors
|
61
|
+
assert_equal "#find", @parse.empty.keys.first
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_if_Format#write_index_returns_true
|
65
|
+
assert_equal true, @parse.write_index
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_good_percent
|
69
|
+
assert_equal "57.14%", @parse.good_percent
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_success_message_if_Format#write_index_is_true
|
73
|
+
assert @parse.success?
|
74
|
+
end
|
75
|
+
|
76
|
+
#Preformance
|
77
|
+
=begin
|
78
|
+
def test_performance_of_found
|
79
|
+
n = 10000
|
80
|
+
Benchmark.bmbm do |x|
|
81
|
+
x.report("found:") {n.times do @parse.found end}
|
82
|
+
end
|
83
|
+
end
|
84
|
+
=end
|
85
|
+
|
86
|
+
end
|