nanoc 3.6.9 → 3.6.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +15 -8
  3. data/Gemfile.lock +27 -14
  4. data/NEWS.md +14 -0
  5. data/lib/nanoc/base.rb +2 -0
  6. data/lib/nanoc/base/checksummer.rb +82 -0
  7. data/lib/nanoc/base/compilation/compiler.rb +4 -3
  8. data/lib/nanoc/base/compilation/filter.rb +3 -10
  9. data/lib/nanoc/base/compilation/rules_collection.rb +6 -1
  10. data/lib/nanoc/base/core_ext/array.rb +1 -1
  11. data/lib/nanoc/base/core_ext/hash.rb +1 -2
  12. data/lib/nanoc/base/core_ext/pathname.rb +1 -2
  13. data/lib/nanoc/base/core_ext/string.rb +1 -3
  14. data/lib/nanoc/base/errors.rb +9 -0
  15. data/lib/nanoc/base/result_data/item_rep.rb +2 -7
  16. data/lib/nanoc/base/source_data/code_snippet.rb +1 -1
  17. data/lib/nanoc/base/source_data/item.rb +1 -16
  18. data/lib/nanoc/base/source_data/layout.rb +1 -3
  19. data/lib/nanoc/base/source_data/site.rb +14 -0
  20. data/lib/nanoc/base/temp_filename_factory.rb +53 -0
  21. data/lib/nanoc/cli/commands/compile.rb +6 -2
  22. data/lib/nanoc/cli/commands/create-site.rb +3 -0
  23. data/lib/nanoc/cli/error_handler.rb +9 -5
  24. data/lib/nanoc/extra.rb +9 -8
  25. data/lib/nanoc/extra/jruby_nokogiri_warner.rb +48 -0
  26. data/lib/nanoc/extra/link_collector.rb +2 -0
  27. data/lib/nanoc/extra/piper.rb +1 -1
  28. data/lib/nanoc/filters/colorize_syntax.rb +2 -0
  29. data/lib/nanoc/filters/pandoc.rb +2 -2
  30. data/lib/nanoc/filters/relativize_paths.rb +2 -0
  31. data/lib/nanoc/filters/xsl.rb +2 -0
  32. data/lib/nanoc/version.rb +1 -1
  33. data/tasks/rubocop.rake +7 -3
  34. data/test/base/checksummer_spec.rb +274 -0
  35. data/test/base/core_ext/array_spec.rb +2 -2
  36. data/test/base/core_ext/hash_spec.rb +7 -4
  37. data/test/base/core_ext/pathname_spec.rb +6 -6
  38. data/test/base/core_ext/string_spec.rb +2 -2
  39. data/test/base/temp_filename_factory_spec.rb +72 -0
  40. data/test/base/test_site.rb +26 -0
  41. data/test/cli/commands/test_prune.rb +4 -0
  42. data/test/extra/checking/checks/test_css.rb +28 -24
  43. data/test/extra/checking/checks/test_html.rb +28 -24
  44. data/test/extra/test_piper.rb +12 -0
  45. data/test/filters/test_colorize_syntax.rb +6 -6
  46. data/test/filters/test_erb.rb +4 -0
  47. data/test/filters/test_pandoc.rb +15 -0
  48. data/test/filters/test_relativize_paths.rb +27 -65
  49. data/test/filters/test_xsl.rb +7 -35
  50. data/test/fixtures/vcr_cassettes/css_run_error.yml +65 -0
  51. data/test/fixtures/vcr_cassettes/css_run_ok.yml +55 -0
  52. data/test/fixtures/vcr_cassettes/html_run_error.yml +94 -0
  53. data/test/fixtures/vcr_cassettes/html_run_ok.yml +56 -0
  54. data/test/helper.rb +19 -9
  55. metadata +11 -2
@@ -58,8 +58,8 @@ end
58
58
  describe 'Array#checksum' do
59
59
 
60
60
  it 'should work' do
61
- expectation = '78468f950645150238a26f5b8f2dde39a75a7028'
62
- [ [ :foo, 123 ]].checksum.must_equal expectation
61
+ expectation = 'CEUlNvu/3DUmlbtpFRiLHU8oHA0='
62
+ [ [ :foo, 123 ] ].checksum.must_equal expectation
63
63
  end
64
64
 
65
65
  end
@@ -82,15 +82,18 @@ end
82
82
  describe 'Hash#checksum' do
83
83
 
84
84
  it 'should work' do
85
- expectation = '78468f950645150238a26f5b8f2dde39a75a7028'
85
+ expectation = 'wy7gHokc700tqJ/BmJ+EK6/F0bc='
86
86
  { :foo => 123 }.checksum.must_equal expectation
87
- [ [ :foo, 123 ]].checksum.must_equal expectation
88
87
  end
89
88
 
90
- it 'should sort keys' do
89
+ it 'should not sort keys' do
90
+ if RUBY_VERSION =~ /\A1\.8./
91
+ skip "Ruby 1.8.x does not have ordered hashes"
92
+ end
93
+
91
94
  a = { :a => 1, :c => 2, :b => 3 }.checksum
92
95
  b = { :a => 1, :b => 3, :c => 2 }.checksum
93
- a.must_equal b
96
+ a.wont_equal b
94
97
  end
95
98
 
96
99
  end
@@ -7,12 +7,12 @@ describe 'Pathname#checksum' do
7
7
  # Create file
8
8
  FileUtils.mkdir_p('tmp')
9
9
  File.open('tmp/myfile', 'w') { |io| io.write('') }
10
- now = Time.now
11
- File.utime(now, now, 'tmp/myfile')
10
+ timestamp = Time.at(1234569)
11
+ File.utime(timestamp, timestamp, 'tmp/myfile')
12
12
 
13
13
  # Create checksum
14
14
  pathname = Pathname.new('tmp/myfile')
15
- pathname.checksum.must_equal '0-' + now.to_s
15
+ pathname.checksum.must_equal 'oU+0fYgGm4EDTl+uErBv8rB9YhU='
16
16
  ensure
17
17
  FileUtils.rm_rf('tmp')
18
18
  end
@@ -23,12 +23,12 @@ describe 'Pathname#checksum' do
23
23
  # Create file
24
24
  FileUtils.mkdir_p('tmp')
25
25
  File.open('tmp/myfile', 'w') { |io| io.write('abc') }
26
- now = Time.now
27
- File.utime(now, now, 'tmp/myfile')
26
+ timestamp = Time.at(1234569)
27
+ File.utime(timestamp, timestamp, 'tmp/myfile')
28
28
 
29
29
  # Create checksum
30
30
  pathname = Pathname.new('tmp/myfile')
31
- pathname.checksum.must_equal '3-' + now.to_s
31
+ pathname.checksum.must_equal 'IAoqYXvcDheQjaYmZ8waPtEO8zU='
32
32
  ensure
33
33
  FileUtils.rm_rf('tmp')
34
34
  end
@@ -27,11 +27,11 @@ end
27
27
  describe 'String#checksum' do
28
28
 
29
29
  it 'should work on empty strings' do
30
- ''.checksum.must_equal 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
30
+ ''.checksum.must_equal 'PfY7essFItpoXa1f6EuB/deyUmQ='
31
31
  end
32
32
 
33
33
  it 'should work on all strings' do
34
- 'abc'.checksum.must_equal 'a9993e364706816aba3e25717850c26c9cd0d89d'
34
+ 'abc'.checksum.must_equal 'NkkYRO+25f6psNSeCYykXKCg3C0='
35
35
  end
36
36
 
37
37
  end
@@ -0,0 +1,72 @@
1
+ # encoding: utf-8
2
+
3
+ describe Nanoc::TempFilenameFactory do
4
+
5
+ subject do
6
+ Nanoc::TempFilenameFactory.instance
7
+ end
8
+
9
+ let(:prefix) { 'foo' }
10
+
11
+ before do
12
+ subject.cleanup(prefix)
13
+ end
14
+
15
+ describe '#create' do
16
+
17
+ it 'should create unique paths' do
18
+ path_a = subject.create(prefix)
19
+ path_b = subject.create(prefix)
20
+ path_a.wont_equal(path_b)
21
+ end
22
+
23
+ it 'should return absolute paths' do
24
+ path = subject.create(prefix)
25
+ path.must_match(/\A\//)
26
+ end
27
+
28
+ it 'should create the containing directory' do
29
+ Dir[subject.root_dir + '/**/*'].must_equal([])
30
+ path = subject.create(prefix)
31
+ File.directory?(File.dirname(path)).must_equal(true)
32
+ end
33
+
34
+ it 'should reuse the same path after cleanup' do
35
+ path_a = subject.create(prefix)
36
+ subject.cleanup(prefix)
37
+ path_b = subject.create(prefix)
38
+ path_a.must_equal(path_b)
39
+ end
40
+
41
+ end
42
+
43
+ describe '#cleanup' do
44
+
45
+ it 'should remove generated files' do
46
+ path_a = subject.create(prefix)
47
+ File.file?(path_a).wont_equal(true) # not yet used
48
+
49
+ File.open(path_a, 'w') { |io| io << 'hi!' }
50
+ File.file?(path_a).must_equal(true)
51
+
52
+ subject.cleanup(prefix)
53
+ File.file?(path_a).wont_equal(true)
54
+ end
55
+
56
+ end
57
+
58
+ describe 'other instance' do
59
+
60
+ let(:other_instance) do
61
+ Nanoc::TempFilenameFactory.new
62
+ end
63
+
64
+ it 'should create unique paths across instances' do
65
+ path_a = subject.create(prefix)
66
+ path_b = other_instance.create(prefix)
67
+ path_a.wont_equal(path_b)
68
+ end
69
+
70
+ end
71
+
72
+ end
@@ -113,6 +113,32 @@ EOF
113
113
  end
114
114
  end
115
115
 
116
+ def test_multiple_items_with_same_identifier
117
+ with_site do
118
+ File.open('content/sam.html', 'w') { |io| io.write('I am Sam!') }
119
+ FileUtils.mkdir_p('content/sam')
120
+ File.open('content/sam/index.html', 'w') { |io| io.write('I am Sam, too!') }
121
+
122
+ assert_raises(Nanoc::Errors::DuplicateIdentifier) do
123
+ site = Nanoc::Site.new('.')
124
+ site.load
125
+ end
126
+ end
127
+ end
128
+
129
+ def test_multiple_layouts_with_same_identifier
130
+ with_site do
131
+ File.open('layouts/sam.html', 'w') { |io| io.write('I am Sam!') }
132
+ FileUtils.mkdir_p('layouts/sam')
133
+ File.open('layouts/sam/index.html', 'w') { |io| io.write('I am Sam, too!') }
134
+
135
+ assert_raises(Nanoc::Errors::DuplicateIdentifier) do
136
+ site = Nanoc::Site.new('.')
137
+ site.load
138
+ end
139
+ end
140
+ end
141
+
116
142
  end
117
143
 
118
144
  describe 'Nanoc::Site#initialize' do
@@ -94,6 +94,10 @@ class Nanoc::CLI::Commands::PruneTest < Nanoc::TestCase
94
94
 
95
95
  def test_run_with_symlink_to_output_dir
96
96
  skip_unless_have_symlink
97
+ if defined?(JRUBY_VERSION) && JRUBY_VERSION == '1.7.11'
98
+ skip "JRuby 1.7.11 has buggy File.find behavior (see https://github.com/jruby/jruby/issues/1647)"
99
+ end
100
+
97
101
  with_site do |site|
98
102
  # Set output dir
99
103
  FileUtils.rm_rf('output')
@@ -3,34 +3,38 @@
3
3
  class Nanoc::Extra::Checking::Checks::CSSTest < Nanoc::TestCase
4
4
 
5
5
  def test_run_ok
6
- with_site do |site|
7
- # Create files
8
- FileUtils.mkdir_p('output')
9
- File.open('output/blah.html', 'w') { |io| io.write('<h1>Hi!</h1>') }
10
- File.open('output/style.css', 'w') { |io| io.write('h1 { color: red; }') }
11
-
12
- # Run check
13
- check = Nanoc::Extra::Checking::Checks::CSS.new(site)
14
- check.run
15
-
16
- # Check
17
- assert check.issues.empty?
6
+ VCR.use_cassette('css_run_ok') do
7
+ with_site do |site|
8
+ # Create files
9
+ FileUtils.mkdir_p('output')
10
+ File.open('output/blah.html', 'w') { |io| io.write('<h1>Hi!</h1>') }
11
+ File.open('output/style.css', 'w') { |io| io.write('h1 { color: red; }') }
12
+
13
+ # Run check
14
+ check = Nanoc::Extra::Checking::Checks::CSS.new(site)
15
+ check.run
16
+
17
+ # Check
18
+ assert check.issues.empty?
19
+ end
18
20
  end
19
21
  end
20
22
 
21
23
  def test_run_error
22
- with_site do |site|
23
- # Create files
24
- FileUtils.mkdir_p('output')
25
- File.open('output/blah.html', 'w') { |io| io.write('<h1>Hi!</h1>') }
26
- File.open('output/style.css', 'w') { |io| io.write('h1 { coxlor: rxed; }') }
27
-
28
- # Run check
29
- check = Nanoc::Extra::Checking::Checks::CSS.new(site)
30
- check.run
31
-
32
- # Check
33
- refute check.issues.empty?
24
+ VCR.use_cassette('css_run_error') do
25
+ with_site do |site|
26
+ # Create files
27
+ FileUtils.mkdir_p('output')
28
+ File.open('output/blah.html', 'w') { |io| io.write('<h1>Hi!</h1>') }
29
+ File.open('output/style.css', 'w') { |io| io.write('h1 { coxlor: rxed; }') }
30
+
31
+ # Run check
32
+ check = Nanoc::Extra::Checking::Checks::CSS.new(site)
33
+ check.run
34
+
35
+ # Check
36
+ refute check.issues.empty?
37
+ end
34
38
  end
35
39
  end
36
40
 
@@ -3,34 +3,38 @@
3
3
  class Nanoc::Extra::Checking::Checks::HTMLTest < Nanoc::TestCase
4
4
 
5
5
  def test_run_ok
6
- with_site do |site|
7
- # Create files
8
- FileUtils.mkdir_p('output')
9
- File.open('output/blah.html', 'w') { |io| io.write('<!DOCTYPE html><html><head><meta charset="utf-8"><title>Hello</title></head><body><h1>Hi!</h1></body>') }
10
- File.open('output/style.css', 'w') { |io| io.write('h1 { coxlor: rxed; }') }
11
-
12
- # Run check
13
- check = Nanoc::Extra::Checking::Checks::HTML.new(site)
14
- check.run
15
-
16
- # Check
17
- assert check.issues.empty?
6
+ VCR.use_cassette('html_run_ok') do
7
+ with_site do |site|
8
+ # Create files
9
+ FileUtils.mkdir_p('output')
10
+ File.open('output/blah.html', 'w') { |io| io.write('<!DOCTYPE html><html><head><meta charset="utf-8"><title>Hello</title></head><body><h1>Hi!</h1></body>') }
11
+ File.open('output/style.css', 'w') { |io| io.write('h1 { coxlor: rxed; }') }
12
+
13
+ # Run check
14
+ check = Nanoc::Extra::Checking::Checks::HTML.new(site)
15
+ check.run
16
+
17
+ # Check
18
+ assert check.issues.empty?
19
+ end
18
20
  end
19
21
  end
20
22
 
21
23
  def test_run_error
22
- with_site do |site|
23
- # Create files
24
- FileUtils.mkdir_p('output')
25
- File.open('output/blah.html', 'w') { |io| io.write('<h2>Hi!</h1>') }
26
- File.open('output/style.css', 'w') { |io| io.write('h1 { coxlor: rxed; }') }
27
-
28
- # Run check
29
- check = Nanoc::Extra::Checking::Checks::HTML.new(site)
30
- check.run
31
-
32
- # Check
33
- refute check.issues.empty?
24
+ VCR.use_cassette('html_run_error') do
25
+ with_site do |site|
26
+ # Create files
27
+ FileUtils.mkdir_p('output')
28
+ File.open('output/blah.html', 'w') { |io| io.write('<h2>Hi!</h1>') }
29
+ File.open('output/style.css', 'w') { |io| io.write('h1 { coxlor: rxed; }') }
30
+
31
+ # Run check
32
+ check = Nanoc::Extra::Checking::Checks::HTML.new(site)
33
+ check.run
34
+
35
+ # Check
36
+ refute check.issues.empty?
37
+ end
34
38
  end
35
39
  end
36
40
 
@@ -33,4 +33,16 @@ class Nanoc::Extra::PiperTest < Nanoc::TestCase
33
33
  assert_equal('', stderr.string)
34
34
  end
35
35
 
36
+ def test_no_such_command
37
+ stdout = StringIO.new
38
+ stderr = StringIO.new
39
+
40
+ cmd = %w( cat kafhawilgoiwaejagoualjdsfilofiewaguihaifeowuiga )
41
+
42
+ piper = Nanoc::Extra::Piper.new(:stdout => stdout, :stderr => stderr)
43
+ assert_raises(Nanoc::Extra::Piper::Error) do
44
+ piper.run(cmd, nil)
45
+ end
46
+ end
47
+
36
48
  end
@@ -282,7 +282,7 @@ puts 'hi!'
282
282
  </code></pre>
283
283
  after
284
284
  EOS
285
- expected_output = <<EOS
285
+ expected_output = <<EOS.sub(/\s*\Z/m, '')
286
286
  before
287
287
  <pre><code>
288
288
  #!/usr/bin/env ruby
@@ -292,7 +292,7 @@ after
292
292
  EOS
293
293
 
294
294
  # Run filter
295
- actual_output = filter.setup_and_run(input)
295
+ actual_output = filter.setup_and_run(input).sub(/\s*\Z/m, '')
296
296
  assert_equal(expected_output, actual_output)
297
297
  end
298
298
  end
@@ -312,7 +312,7 @@ puts 'hi!'
312
312
  </code></pre>
313
313
  after
314
314
  EOS
315
- expected_output = <<EOS
315
+ expected_output = <<EOS.sub(/\s*\Z/m, '')
316
316
  before
317
317
  #{CODERAY_PRE}<pre><code class=\"language-ruby\"><span class=\"doctype\">#!/usr/bin/env ruby</span>
318
318
  puts <span class=\"string\"><span class=\"delimiter\">'</span><span class=\"content\">hi!</span><span class=\"delimiter\">'</span></span></code></pre>#{CODERAY_POST}
@@ -320,7 +320,7 @@ after
320
320
  EOS
321
321
 
322
322
  # Run filter
323
- actual_output = filter.setup_and_run(input)
323
+ actual_output = filter.setup_and_run(input).sub(/\s*\Z/m, '')
324
324
  assert_equal(expected_output, actual_output)
325
325
  end
326
326
  end
@@ -372,7 +372,7 @@ before
372
372
  </code></pre>
373
373
  after
374
374
  EOS
375
- expected_output = <<EOS
375
+ expected_output = <<EOS.sub(/\s*\Z/m, '')
376
376
  before
377
377
  #{CODERAY_PRE}<pre><code class="language-ruby"> <span class=\"keyword\">def</span> <span class=\"function\">foo</span>
378
378
  <span class=\"keyword\">end</span></code></pre>#{CODERAY_POST}
@@ -380,7 +380,7 @@ after
380
380
  EOS
381
381
 
382
382
  # Run filter
383
- actual_output = filter.setup_and_run(input)
383
+ actual_output = filter.setup_and_run(input).sub(/\s*\Z/m, '')
384
384
  assert_equal(expected_output, actual_output)
385
385
  end
386
386
  end
@@ -66,6 +66,10 @@ class Nanoc::Filters::ERBTest < Nanoc::TestCase
66
66
  end
67
67
 
68
68
  def test_safe_level
69
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
70
+ skip 'JRuby does not implement safe levels'
71
+ end
72
+
69
73
  # Set up
70
74
  filter = ::Nanoc::Filters::ERB.new
71
75
  File.open('moo', 'w') { |io| io.write("one miiillion dollars") }
@@ -15,4 +15,19 @@ class Nanoc::Filters::PandocTest < Nanoc::TestCase
15
15
  end
16
16
  end
17
17
 
18
+ def test_params
19
+ if_have 'pandoc-ruby' do
20
+ skip_unless_have_command "pandoc"
21
+
22
+ # Create filter
23
+ filter = ::Nanoc::Filters::Pandoc.new
24
+
25
+ # Run filter
26
+ opts = [ :s, {:f => :markdown, :to => :html}, 'no-wrap', :toc ]
27
+ result = filter.setup_and_run("# Heading\n", *opts)
28
+ assert_match '<div id="TOC">', result
29
+ assert_match(%r{<h1 id=\"heading\">Heading</h1>\s*}, result)
30
+ end
31
+ end
32
+
18
33
  end
@@ -103,7 +103,7 @@ class Nanoc::Filters::RelativizePathsTest < Nanoc::TestCase
103
103
  </html>
104
104
  EOS
105
105
  expected_match_0 = %r{<a href="\.\./\.\.">foo</a>}
106
- expected_match_1 = %r{^<!DOCTYPE html>\s*<html>\s*<head>(.|\s)*<title>Hello</title>\s*</head>\s*<body>\s*<a href="../..">foo</a>\s*</body>\s*</html>\s*$}
106
+ expected_match_1 = %r{\A\s*<!DOCTYPE html\s*>\s*<html>\s*<head>(.|\s)*<title>Hello</title>\s*</head>\s*<body>\s*<a href="../..">foo</a>\s*</body>\s*</html>\s*\Z}m
107
107
 
108
108
  # Test
109
109
  actual_content = filter.setup_and_run(raw_content, :type => :html)
@@ -303,7 +303,6 @@ EOS
303
303
  assert_equal(expected_content, actual_content)
304
304
  end
305
305
 
306
-
307
306
  def test_filter_html_object_with_relative_path
308
307
  # Create filter with mock item
309
308
  filter = Nanoc::Filters::RelativizePaths.new
@@ -319,13 +318,11 @@ EOS
319
318
  @item_rep.path = '/woof/meow/'
320
319
  end
321
320
 
322
- # Set content
323
- raw_content = %[<object data="/example"><param name="movie" content="/example"></object>]
324
- expected_content = %[<object data="../../example"><param name="movie" content="../../example"></object>]
325
-
326
- # Test
321
+ raw_content = %[<object data="/example"><param name="movie" content="/example"></object>]
327
322
  actual_content = filter.setup_and_run(raw_content, :type => :html)
328
- assert_equal(expected_content, actual_content)
323
+
324
+ assert_match(/<object data="..\/..\/example">/, actual_content)
325
+ assert_match(/<param (name="movie" )?content="..\/..\/example"/, actual_content)
329
326
  end
330
327
 
331
328
 
@@ -503,6 +500,7 @@ EOS
503
500
  end
504
501
 
505
502
  # Set content
503
+ expected = /<bar boo="\.\.\/\.\.">baz<\/bar>/
506
504
  raw_content = <<-XML
507
505
  <?xml version="1.0" encoding="utf-8"?>
508
506
  <foo>
@@ -510,16 +508,9 @@ EOS
510
508
  </foo>
511
509
  XML
512
510
 
513
- expected_content = <<-XML
514
- <?xml version="1.0" encoding="utf-8"?>
515
- <foo>
516
- <bar boo="../..">baz</bar>
517
- </foo>
518
- XML
519
-
520
- # Test
521
511
  actual_content = filter.setup_and_run(raw_content, :type => :xml, :select => ['*/@boo'])
522
- assert_equal(expected_content, actual_content)
512
+
513
+ assert_match(expected, actual_content)
523
514
  end
524
515
  end
525
516
 
@@ -546,15 +537,10 @@ XML
546
537
  </foo>
547
538
  XML
548
539
 
549
- expected_content = <<-XML
550
- <foo>
551
- <bar><far href="../..">baz</far></bar>
552
- </foo>
553
- XML
554
-
555
- # Test
556
540
  actual_content = filter.setup_and_run(raw_content, :type => :xml, :select => ['far/@href'])
557
- assert_equal(expected_content, actual_content)
541
+
542
+ assert_match(/<foo>/, actual_content)
543
+ assert_match(/<bar><far href="..\/..">baz<\/far><\/bar>/, actual_content)
558
544
  end
559
545
  end
560
546
 
@@ -581,19 +567,14 @@ XML
581
567
  </foo>
582
568
  XML
583
569
 
584
- expected_content = <<-XML
585
- <foo xmlns="http://example.org">
586
- <bar><a href="../..">baz</a></bar>
587
- </foo>
588
- XML
589
-
590
- # Test
591
570
  actual_content = filter.setup_and_run(raw_content, {
592
- :type => :xml,
593
- :namespaces => {:ex => 'http://example.org'},
571
+ :type => :xml,
572
+ :namespaces => {:ex => 'http://example.org'},
594
573
  :select => ['ex:a/@href']
595
574
  })
596
- assert_equal(expected_content, actual_content)
575
+
576
+ assert_match(/<foo xmlns="http:\/\/example.org">/, actual_content)
577
+ assert_match(/<bar><a href="..\/..">baz<\/a><\/bar>/, actual_content)
597
578
  end
598
579
  end
599
580
 
@@ -628,21 +609,12 @@ XML
628
609
  </html>
629
610
  XML
630
611
 
631
- expected_match = %r{^<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
632
- <html xmlns="http://www.w3.org/1999/xhtml">
633
- <head>.*<meta.*charset.*>
634
- <link rel="stylesheet" href="../../../css" />
635
- <script src="../../../js"></script>
636
- </head>
637
- <body>
638
- <a href="../..">bar</a>
639
- <img src="../../../img" />
640
- </body>
641
- </html>}
642
-
643
- # Test
644
612
  actual_content = filter.setup_and_run(raw_content, :type => :xhtml)
645
- assert_match expected_match, actual_content
613
+
614
+ assert_match(/<link[^>]*href="..\/..\/..\/css"[^>]*\/>/, actual_content)
615
+ assert_match(/<script src="..\/..\/..\/js">/, actual_content)
616
+ assert_match(/<img src="..\/..\/..\/img"[^>]*\/>/, actual_content)
617
+ assert_match(/<a href="..\/..">bar<\/a>/, actual_content)
646
618
  end
647
619
  end
648
620
 
@@ -670,16 +642,12 @@ XML
670
642
  </p>
671
643
  XML
672
644
 
673
- expected_content = <<-XML
674
- <a href="../..">bar</a>
675
- <p>
676
- <img src="../../../img" />
677
- </p>
678
- XML
645
+ expected_content =
646
+ %r{\A\s*<a href="../..">bar</a>\s*<p>\s*<img src="../../../img" />\s*</p>\s*\Z}m
679
647
 
680
648
  # Test
681
649
  actual_content = filter.setup_and_run(raw_content.freeze, :type => :xhtml)
682
- assert_equal(expected_content, actual_content)
650
+ assert_match(expected_content, actual_content)
683
651
  end
684
652
  end
685
653
 
@@ -707,16 +675,10 @@ XML
707
675
  <![endif]-->
708
676
  ]
709
677
 
710
- expected_content = %[
711
- <link rel="stylesheet" href="../../foo.css" />
712
- <!--[if lt IE 9]>
713
- <script src="../../js/lib/html5shiv.js"></script>
714
- <![endif]-->
715
- ]
716
-
717
- # Test
718
678
  actual_content = filter.setup_and_run(raw_content.freeze, :type => :xhtml)
719
- assert_equal(expected_content, actual_content)
679
+
680
+ assert_match(/<link (rel="stylesheet" )?href="..\/..\/foo.css" /, actual_content)
681
+ assert_match(/<script src="..\/..\/js\/lib\/html5shiv.js"><\/script>/, actual_content)
720
682
  end
721
683
  end
722
684