deadweight 0.1.3 → 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.
- data/README.md +123 -0
- data/lib/deadweight.rb +37 -11
- data/lib/deadweight/hijack.rb +13 -0
- data/lib/deadweight/hijack/rails.rb +35 -0
- data/lib/deadweight/rack/capturing_middleware.rb +26 -0
- data/vendor/gems/{css_parser-1.0.0 → css_parser-1.1.5}/lib/css_parser.rb +25 -12
- data/vendor/gems/{css_parser-1.0.0 → css_parser-1.1.5}/lib/css_parser/parser.rb +120 -54
- data/vendor/gems/{css_parser-1.0.0 → css_parser-1.1.5}/lib/css_parser/regexps.rb +1 -1
- data/vendor/gems/{css_parser-1.0.0 → css_parser-1.1.5}/lib/css_parser/rule_set.rb +24 -13
- data/vendor/gems/{css_parser-1.0.0 → css_parser-1.1.5}/test/fixtures/import-circular-reference.css +0 -0
- data/vendor/gems/{css_parser-1.0.0 → css_parser-1.1.5}/test/fixtures/import-with-media-types.css +0 -0
- data/vendor/gems/{css_parser-1.0.0 → css_parser-1.1.5}/test/fixtures/import1.css +0 -0
- data/vendor/gems/{css_parser-1.0.0 → css_parser-1.1.5}/test/fixtures/simple.css +0 -0
- data/vendor/gems/{css_parser-1.0.0 → css_parser-1.1.5}/test/fixtures/subdir/import2.css +0 -0
- data/vendor/gems/{css_parser-1.0.0 → css_parser-1.1.5}/test/test_css_parser_basic.rb +4 -1
- data/vendor/gems/css_parser-1.1.5/test/test_css_parser_loading.rb +139 -0
- data/vendor/gems/{css_parser-1.0.0 → css_parser-1.1.5}/test/test_css_parser_media_types.rb +39 -4
- data/vendor/gems/{css_parser-1.0.0 → css_parser-1.1.5}/test/test_css_parser_misc.rb +1 -2
- data/vendor/gems/{css_parser-1.0.0 → css_parser-1.1.5}/test/test_css_parser_regexps.rb +1 -1
- data/vendor/gems/css_parser-1.1.5/test/test_helper.rb +6 -0
- data/vendor/gems/{css_parser-1.0.0 → css_parser-1.1.5}/test/test_merging.rb +16 -1
- data/vendor/gems/{css_parser-1.0.0 → css_parser-1.1.5}/test/test_rule_set.rb +16 -1
- data/vendor/gems/{css_parser-1.0.0 → css_parser-1.1.5}/test/test_rule_set_creating_shorthand.rb +1 -1
- data/vendor/gems/{css_parser-1.0.0 → css_parser-1.1.5}/test/test_rule_set_expanding_shorthand.rb +1 -1
- metadata +79 -54
- data/.document +0 -5
- data/.gitignore +0 -6
- data/README.rdoc +0 -85
- data/Rakefile +0 -58
- data/VERSION +0 -1
- data/deadweight.gemspec +0 -84
- data/test/cli_test.rb +0 -21
- data/test/deadweight_test.rb +0 -72
- data/test/fixtures/index.html +0 -16
- data/test/fixtures/index2.html +0 -21
- data/test/fixtures/style.css +0 -24
- data/test/rake_task_test.rb +0 -26
- data/test/test_helper.rb +0 -47
- data/vendor/gems/css_parser-1.0.0/test/test_css_parser_downloading.rb +0 -81
- data/vendor/gems/css_parser-1.0.0/test/test_helper.rb +0 -8
data/test/deadweight_test.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class DeadweightTest < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@dw = Deadweight.new
|
6
|
-
default_settings(@dw)
|
7
|
-
@result = @dw.run
|
8
|
-
end
|
9
|
-
|
10
|
-
context "when initialized with a block" do
|
11
|
-
setup do
|
12
|
-
@dwb = Deadweight.new do |dw|
|
13
|
-
default_settings(dw)
|
14
|
-
end
|
15
|
-
|
16
|
-
@result = @dwb.run
|
17
|
-
end
|
18
|
-
|
19
|
-
should "have the same attributes" do
|
20
|
-
assert_equal(@dw.log_file, @dwb.log_file)
|
21
|
-
assert_equal(@dw.root, @dwb.root)
|
22
|
-
assert_equal(@dw.stylesheets, @dwb.stylesheets)
|
23
|
-
assert_equal(@dw.pages, @dwb.pages)
|
24
|
-
end
|
25
|
-
|
26
|
-
should_correctly_report_selectors
|
27
|
-
end
|
28
|
-
|
29
|
-
should_correctly_report_selectors
|
30
|
-
|
31
|
-
should 'strip pseudo classes from selectors' do
|
32
|
-
# #oof:hover (#oof does not exist)
|
33
|
-
assert @result.include?('#oof:hover'), @result.inspect
|
34
|
-
|
35
|
-
# #foo:hover (#foo does exist)
|
36
|
-
assert !@result.include?('#foo:hover')
|
37
|
-
|
38
|
-
# #rab:hover::selection (#rab does not exist)
|
39
|
-
assert @result.include?('#rab:hover::selection')
|
40
|
-
end
|
41
|
-
|
42
|
-
should "accept Procs as targets" do
|
43
|
-
@dw.mechanize = true
|
44
|
-
|
45
|
-
@dw.pages << proc {
|
46
|
-
fetch('/index.html')
|
47
|
-
agent.page.links.first.click
|
48
|
-
}
|
49
|
-
|
50
|
-
assert @dw.run.empty?
|
51
|
-
end
|
52
|
-
|
53
|
-
should "accept IO objects as targets" do
|
54
|
-
@dw.pages << File.new(File.dirname(__FILE__) + '/fixtures/index2.html')
|
55
|
-
|
56
|
-
assert @dw.run.empty?
|
57
|
-
end
|
58
|
-
|
59
|
-
should "allow individual CSS rules to be appended" do
|
60
|
-
@dw.rules = ".something { display: block; }"
|
61
|
-
|
62
|
-
assert @dw.run.include?(".something")
|
63
|
-
end
|
64
|
-
|
65
|
-
should 'provide the results of its last run with #unused_selectors' do
|
66
|
-
assert_equal @result, @dw.unused_selectors
|
67
|
-
end
|
68
|
-
|
69
|
-
should 'provide the parsed CSS rules with #parsed_rules' do
|
70
|
-
assert_equal 'color: green;', @dw.parsed_rules['#foo']
|
71
|
-
end
|
72
|
-
end
|
data/test/fixtures/index.html
DELETED
data/test/fixtures/index2.html
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
<html>
|
2
|
-
<head>
|
3
|
-
<link rel="stylesheet" type="text/css" href="style.css">
|
4
|
-
</head>
|
5
|
-
|
6
|
-
<body>
|
7
|
-
<div id="foo">
|
8
|
-
<div class="bar">
|
9
|
-
<div class="baz">
|
10
|
-
hello again
|
11
|
-
</div>
|
12
|
-
</div>
|
13
|
-
</div>
|
14
|
-
|
15
|
-
<div id="oof"></div>
|
16
|
-
|
17
|
-
<div id="rab"></div>
|
18
|
-
</body>
|
19
|
-
</html>
|
20
|
-
|
21
|
-
|
data/test/fixtures/style.css
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
#foo {
|
2
|
-
color: green;
|
3
|
-
}
|
4
|
-
|
5
|
-
#foo .bar {
|
6
|
-
color: blue;
|
7
|
-
}
|
8
|
-
|
9
|
-
#foo .bar .baz {
|
10
|
-
color: red;
|
11
|
-
}
|
12
|
-
|
13
|
-
/* pseudo classes */
|
14
|
-
#foo:hover {
|
15
|
-
color: red;
|
16
|
-
}
|
17
|
-
|
18
|
-
#oof:hover {
|
19
|
-
color: white;
|
20
|
-
}
|
21
|
-
|
22
|
-
#rab:hover::selection {
|
23
|
-
color: black;
|
24
|
-
}
|
data/test/rake_task_test.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
class RakeTaskTest < Test::Unit::TestCase
|
5
|
-
context "Deadweight::RakeTask.new" do
|
6
|
-
setup do
|
7
|
-
@io = StringIO.new("", "w")
|
8
|
-
|
9
|
-
Deadweight::RakeTask.new(@io) do |d|
|
10
|
-
default_settings(d)
|
11
|
-
end
|
12
|
-
|
13
|
-
@task_names = Rake::Task.tasks.map { |t| t.name }
|
14
|
-
@task = Rake::Task.tasks.find { |t| t.name == 'deadweight' }
|
15
|
-
end
|
16
|
-
|
17
|
-
should "define a `deadweight` task that automatically runs" do
|
18
|
-
assert @task, "no deadweight task found in: #{@task_names.inspect}"
|
19
|
-
|
20
|
-
@task.execute
|
21
|
-
@io.close
|
22
|
-
|
23
|
-
assert_correct_selectors_in_output(@io.string)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'test/unit'
|
3
|
-
require 'shoulda'
|
4
|
-
|
5
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
|
-
require 'deadweight'
|
8
|
-
|
9
|
-
class Test::Unit::TestCase
|
10
|
-
UNUSED_SELECTORS = ['#foo .bar .baz']
|
11
|
-
USED_SELECTORS = ['#foo', '#foo .bar']
|
12
|
-
|
13
|
-
def self.should_correctly_report_selectors
|
14
|
-
should "report unused selectors" do
|
15
|
-
assert_reports_unused_selectors(@result)
|
16
|
-
end
|
17
|
-
|
18
|
-
should "not report used selectors" do
|
19
|
-
assert_does_not_report_used_selectors(@result)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def assert_correct_selectors_in_output(output)
|
24
|
-
selectors = output.split("\n")
|
25
|
-
assert_reports_unused_selectors(selectors)
|
26
|
-
assert_does_not_report_used_selectors(selectors)
|
27
|
-
end
|
28
|
-
|
29
|
-
def assert_reports_unused_selectors(output)
|
30
|
-
UNUSED_SELECTORS.each do |s|
|
31
|
-
assert output.include?(s), "output is missing #{s.inspect}:\n#{output}"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def assert_does_not_report_used_selectors(output)
|
36
|
-
USED_SELECTORS.each do |s|
|
37
|
-
assert !output.include?(s), "output should not contain #{s.inspect}:\n#{output}"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def default_settings(dw)
|
42
|
-
dw.log_file = 'test.log'
|
43
|
-
dw.root = File.dirname(__FILE__) + '/fixtures'
|
44
|
-
dw.stylesheets << '/style.css'
|
45
|
-
dw.pages << '/index.html'
|
46
|
-
end
|
47
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
# Test cases for the CssParser's downloading functions.
|
4
|
-
class CssParserDownloadingTests < Test::Unit::TestCase
|
5
|
-
include CssParser
|
6
|
-
include WEBrick
|
7
|
-
|
8
|
-
def setup
|
9
|
-
# from http://nullref.se/blog/2006/5/17/testing-with-webrick
|
10
|
-
@cp = Parser.new
|
11
|
-
|
12
|
-
@uri_base = 'http://localhost:12000'
|
13
|
-
|
14
|
-
www_root = File.dirname(__FILE__) + '/fixtures/'
|
15
|
-
|
16
|
-
@server_thread = Thread.new do
|
17
|
-
s = WEBrick::HTTPServer.new(:Port => 12000, :DocumentRoot => www_root, :Logger => Log.new(nil, BasicLog::ERROR), :AccessLog => [])
|
18
|
-
@port = s.config[:Port]
|
19
|
-
begin
|
20
|
-
s.start
|
21
|
-
ensure
|
22
|
-
s.shutdown
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
sleep 1 # ensure the server has time to load
|
27
|
-
end
|
28
|
-
|
29
|
-
def teardown
|
30
|
-
@server_thread.kill
|
31
|
-
@server_thread.join(5)
|
32
|
-
@server_thread = nil
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_loading_a_remote_file
|
36
|
-
@cp.load_uri!("#{@uri_base}/simple.css")
|
37
|
-
assert_equal 'margin: 0px;', @cp.find_by_selector('p').join(' ')
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_following_at_import_rules
|
41
|
-
@cp.load_uri!("#{@uri_base}/import1.css")
|
42
|
-
|
43
|
-
# from '/import1.css'
|
44
|
-
assert_equal 'color: lime;', @cp.find_by_selector('div').join(' ')
|
45
|
-
|
46
|
-
# from '/subdir/import2.css'
|
47
|
-
assert_equal 'text-decoration: none;', @cp.find_by_selector('a').join(' ')
|
48
|
-
|
49
|
-
# from '/subdir/../simple.css'
|
50
|
-
assert_equal 'margin: 0px;', @cp.find_by_selector('p').join(' ')
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_importing_with_media_types
|
54
|
-
@cp.load_uri!("#{@uri_base}/import-with-media-types.css")
|
55
|
-
|
56
|
-
# from simple.css with :screen media type
|
57
|
-
assert_equal 'margin: 0px;', @cp.find_by_selector('p', :screen).join(' ')
|
58
|
-
assert_equal '', @cp.find_by_selector('p', :tty).join(' ')
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_throwing_circular_reference_exception
|
62
|
-
assert_raise CircularReferenceError do
|
63
|
-
@cp.load_uri!("#{@uri_base}/import-circular-reference.css")
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_toggling_not_found_exceptions
|
68
|
-
cp_with_exceptions = Parser.new(:io_exceptions => true)
|
69
|
-
|
70
|
-
assert_raise RemoteFileError do
|
71
|
-
cp_with_exceptions.load_uri!("#{@uri_base}/no-exist.xyz")
|
72
|
-
end
|
73
|
-
|
74
|
-
cp_without_exceptions = Parser.new(:io_exceptions => false)
|
75
|
-
|
76
|
-
assert_nothing_raised RemoteFileError do
|
77
|
-
cp_without_exceptions.load_uri!("#{@uri_base}/no-exist.xyz")
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
@@ -1,8 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__), '../'))
|
2
|
-
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__), '../lib/'))
|
3
|
-
require 'rubygems'
|
4
|
-
require 'test/unit'
|
5
|
-
require 'css_parser'
|
6
|
-
require 'net/http'
|
7
|
-
require 'open-uri'
|
8
|
-
require 'WEBrick'
|