nanoc3 3.1.7 → 3.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/.gemtest +0 -0
  2. data/LICENSE +1 -1
  3. data/NEWS.md +9 -0
  4. data/doc/yardoc_templates/default/layout/html/footer.erb +10 -0
  5. data/lib/nanoc3/base/item.rb +1 -1
  6. data/lib/nanoc3/base/item_rep.rb +1 -0
  7. data/lib/nanoc3/base/layout.rb +1 -1
  8. data/lib/nanoc3/cli/base.rb +4 -2
  9. data/lib/nanoc3/cli/commands/view.rb +1 -0
  10. data/lib/nanoc3/data_sources/filesystem.rb +25 -6
  11. data/lib/nanoc3/data_sources/filesystem_unified.rb +5 -5
  12. data/lib/nanoc3/extra/validators/links.rb +1 -1
  13. data/lib/nanoc3/filters/rdiscount.rb +2 -1
  14. data/lib/nanoc3/filters/sass.rb +20 -8
  15. data/lib/nanoc3/filters/sass.rb.orig +75 -0
  16. data/lib/nanoc3.rb +1 -1
  17. data/nanoc3.gemspec +41 -0
  18. data/tasks/clean.rake +11 -0
  19. data/tasks/doc.rake +14 -0
  20. data/tasks/gem.rake +13 -0
  21. data/tasks/test.rake +38 -0
  22. data/test/base/core_ext/array_spec.rb +23 -0
  23. data/test/base/core_ext/hash_spec.rb +41 -0
  24. data/test/base/core_ext/string_spec.rb +27 -0
  25. data/test/base/test_code_snippet.rb +33 -0
  26. data/test/base/test_compiler.rb +410 -0
  27. data/test/base/test_compiler_dsl.rb +121 -0
  28. data/test/base/test_context.rb +33 -0
  29. data/test/base/test_data_source.rb +48 -0
  30. data/test/base/test_dependency_tracker.rb +510 -0
  31. data/test/base/test_directed_graph.rb +91 -0
  32. data/test/base/test_filter.rb +85 -0
  33. data/test/base/test_item.rb +141 -0
  34. data/test/base/test_item_rep.rb +953 -0
  35. data/test/base/test_layout.rb +44 -0
  36. data/test/base/test_notification_center.rb +36 -0
  37. data/test/base/test_plugin.rb +32 -0
  38. data/test/base/test_rule.rb +21 -0
  39. data/test/base/test_rule_context.rb +63 -0
  40. data/test/base/test_site.rb +366 -0
  41. data/test/cli/commands/test_compile.rb +12 -0
  42. data/test/cli/commands/test_create_item.rb +12 -0
  43. data/test/cli/commands/test_create_layout.rb +28 -0
  44. data/test/cli/commands/test_create_site.rb +24 -0
  45. data/test/cli/commands/test_help.rb +12 -0
  46. data/test/cli/commands/test_info.rb +12 -0
  47. data/test/cli/commands/test_update.rb +12 -0
  48. data/test/cli/test_logger.rb +12 -0
  49. data/test/data_sources/test_filesystem.rb +420 -0
  50. data/test/data_sources/test_filesystem_unified.rb +538 -0
  51. data/test/data_sources/test_filesystem_verbose.rb +359 -0
  52. data/test/extra/core_ext/test_enumerable.rb +32 -0
  53. data/test/extra/core_ext/test_time.rb +17 -0
  54. data/test/extra/deployers/test_rsync.rb +234 -0
  55. data/test/extra/test_auto_compiler.rb +482 -0
  56. data/test/extra/test_file_proxy.rb +21 -0
  57. data/test/extra/test_vcs.rb +24 -0
  58. data/test/extra/validators/test_links.rb +53 -0
  59. data/test/extra/validators/test_w3c.rb +49 -0
  60. data/test/filters/test_bluecloth.rb +20 -0
  61. data/test/filters/test_coderay.rb +46 -0
  62. data/test/filters/test_colorize_syntax.rb +56 -0
  63. data/test/filters/test_erb.rb +72 -0
  64. data/test/filters/test_erubis.rb +72 -0
  65. data/test/filters/test_haml.rb +98 -0
  66. data/test/filters/test_kramdown.rb +20 -0
  67. data/test/filters/test_less.rb +59 -0
  68. data/test/filters/test_markaby.rb +26 -0
  69. data/test/filters/test_maruku.rb +20 -0
  70. data/test/filters/test_rainpress.rb +31 -0
  71. data/test/filters/test_rdiscount.rb +33 -0
  72. data/test/filters/test_rdoc.rb +18 -0
  73. data/test/filters/test_redcloth.rb +20 -0
  74. data/test/filters/test_relativize_paths.rb +231 -0
  75. data/test/filters/test_rubypants.rb +20 -0
  76. data/test/filters/test_sass.rb +170 -0
  77. data/test/filters/test_sass.rb.orig +103 -0
  78. data/test/gem_loader.rb +11 -0
  79. data/test/helper.rb +99 -0
  80. data/test/helpers/test_blogging.rb +808 -0
  81. data/test/helpers/test_breadcrumbs.rb +83 -0
  82. data/test/helpers/test_capturing.rb +42 -0
  83. data/test/helpers/test_filtering.rb +108 -0
  84. data/test/helpers/test_html_escape.rb +18 -0
  85. data/test/helpers/test_link_to.rb +251 -0
  86. data/test/helpers/test_rendering.rb +109 -0
  87. data/test/helpers/test_tagging.rb +89 -0
  88. data/test/helpers/test_text.rb +26 -0
  89. data/test/helpers/test_xml_sitemap.rb +69 -0
  90. data/test/tasks/test_clean.rb +71 -0
  91. metadata +83 -8
data/.gemtest ADDED
File without changes
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2007-2010 Denis Defreyne and contributors
1
+ Copyright (c) 2007-2011 Denis Defreyne and contributors
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/NEWS.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # nanoc news
2
2
 
3
+ ## 3.1.8 (2001-06-25)
4
+
5
+ * Made link validator accept https: URLs
6
+ * Fixed erronous handling of layouts with names ending in index
7
+ * Fixed dependency generation between Sass partials
8
+ * Fixed errors related to thread requires
9
+ * Fixed crash while handling load errors
10
+ * Improved encoding handling while reading files
11
+
3
12
  ## 3.1.7 (2011-05-03)
4
13
 
5
14
  * Restored compatibility with Sass 3.1
@@ -0,0 +1,10 @@
1
+ <%= superb %>
2
+ <script type="text/javascript">
3
+ var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
4
+ document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
5
+ </script>
6
+ <script type="text/javascript">
7
+ try {
8
+ var pageTracker = _gat._getTracker("UA-15639968-1");
9
+ pageTracker._trackPageview();
10
+ } catch(err) {}</script>
@@ -96,7 +96,7 @@ module Nanoc3
96
96
 
97
97
  # Get rest of params
98
98
  @attributes = attributes.symbolize_keys
99
- @identifier = identifier.cleaned_identifier
99
+ @identifier = identifier.cleaned_identifier.freeze
100
100
 
101
101
  @parent = nil
102
102
  @children = []
@@ -459,6 +459,7 @@ module Nanoc3
459
459
  if @old_content.nil? || self.raw_path.nil? || !@item.site.config[:enable_output_diff]
460
460
  @diff = nil
461
461
  else
462
+ require 'thread'
462
463
  @diff_thread = Thread.new do
463
464
  @diff = diff_strings(@old_content, @content[:last])
464
465
  sleep 2
@@ -48,7 +48,7 @@ module Nanoc3
48
48
 
49
49
  @raw_content = raw_content
50
50
  @attributes = attributes.symbolize_keys
51
- @identifier = identifier.cleaned_identifier
51
+ @identifier = identifier.cleaned_identifier.freeze
52
52
  end
53
53
 
54
54
  # Requests the attribute with the given key.
@@ -164,7 +164,9 @@ module Nanoc3::CLI
164
164
  case error
165
165
  when LoadError
166
166
  # Get gem name
167
- lib_name = error.message.match(/no such file to load -- ([^\s]+)/)[1]
167
+ matches = error.message.match(/no such file to load -- ([^\s]+)/)
168
+ return nil if matches.empty?
169
+ lib_name = matches[1]
168
170
  gem_name = gem_names[$1]
169
171
 
170
172
  # Build message
@@ -238,7 +240,7 @@ module Nanoc3::CLI
238
240
  gem_info = defined?(Gem) ? "with RubyGems #{Gem::VERSION}" : "without RubyGems"
239
241
  engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"
240
242
 
241
- puts "nanoc #{Nanoc3::VERSION} (c) 2007-2010 Denis Defreyne."
243
+ puts "nanoc #{Nanoc3::VERSION} (c) 2007-2011 Denis Defreyne."
242
244
  puts "Running #{engine} #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) on #{RUBY_PLATFORM} #{gem_info}"
243
245
  exit 0
244
246
  when :verbose
@@ -72,6 +72,7 @@ module Nanoc3::CLI::Commands
72
72
  use Rack::CommonLogger
73
73
  use Rack::ShowExceptions
74
74
  use Rack::Lint
75
+ use Rack::Head
75
76
  use Adsf::Rack::IndexFileFinder, :root => site.config[:output_dir]
76
77
  run Rack::File.new(site.config[:output_dir])
77
78
  end.to_app
@@ -264,13 +264,32 @@ module Nanoc3::DataSources
264
264
  # the default external encoding, but this can be overridden by the
265
265
  # “encoding” configuration attribute in the data source configuration.
266
266
  def read(filename)
267
- data = File.read(filename)
268
- if data.respond_to?(:encode)
269
- data.force_encoding(@config[:encoding]) if @config && @config[:encoding]
270
- data.encode('UTF-8')
271
- else
272
- data
267
+ # Read
268
+ begin
269
+ data = File.read(filename)
270
+ rescue => e
271
+ raise RuntimeError.new("Could not read #{filename}: #{e.inspect}")
273
272
  end
273
+
274
+ # Fix
275
+ if data.respond_to?(:encode!)
276
+ if @config && @config[:encoding]
277
+ original_encoding = Encoding.find(@config[:encoding])
278
+ data.force_encoding(@config[:encoding])
279
+ else
280
+ original_encoding = data.encoding
281
+ end
282
+
283
+ data.encode!('UTF-8') rescue raise_encoding_error(filename, original_encoding)
284
+ raise_encoding_error(filename, original_encoding) if !data.valid_encoding?
285
+ end
286
+
287
+ data
288
+ end
289
+
290
+ # Raises an invalid encoding error for the given filename and encoding.
291
+ def raise_encoding_error(filename, encoding)
292
+ raise RuntimeError.new("Could not read #{filename} because the file is not valid #{encoding}.")
274
293
  end
275
294
 
276
295
  end
@@ -40,8 +40,8 @@ module Nanoc3::DataSources
40
40
  # (`allow_periods_in_identifiers` set to false)
41
41
  # foo.html.erb → /foo/
42
42
  #
43
- # Note that it is possible for two different, separate files to have the
44
- # same identifier. It is recommended to avoid such situations.
43
+ # Note that each item must have an unique identifier. nanoc will display an
44
+ # error if two items with the same identifier are found.
45
45
  #
46
46
  # Some more examples:
47
47
  #
@@ -103,10 +103,10 @@ module Nanoc3::DataSources
103
103
  # Returns the identifier derived from the given filename, first stripping
104
104
  # the given directory name off the filename.
105
105
  def identifier_for_filename(filename)
106
- if filename =~ /index\.[^\/]+$/
107
- regex = ((@config && @config[:allow_periods_in_identifiers]) ? /index\.[^\/\.]+$/ : /index\.[^\/]+$/)
106
+ if filename =~ /(^|\/)index\.[^\/]+$/
107
+ regex = ((@config && @config[:allow_periods_in_identifiers]) ? /\/?index\.[^\/\.]+$/ : /\/?index\.[^\/]+$/)
108
108
  else
109
- regex = ((@config && @config[:allow_periods_in_identifiers]) ? /\.[^\/\.]+$/ : /\.[^\/]+$/)
109
+ regex = ((@config && @config[:allow_periods_in_identifiers]) ? /\.[^\/\.]+$/ : /\.[^\/]+$/)
110
110
  end
111
111
  filename.sub(regex, '').cleaned_identifier
112
112
  end
@@ -166,7 +166,7 @@ module Nanoc3::Extra::Validators
166
166
  end
167
167
 
168
168
  # Skip non-HTTP URLs
169
- return true if uri.scheme != 'http'
169
+ return true if uri.scheme !~ /^https?$/
170
170
 
171
171
  # Get status
172
172
  status = fetch_http_status_for(uri)
@@ -4,7 +4,8 @@ module Nanoc3::Filters
4
4
  class RDiscount < Nanoc3::Filter
5
5
 
6
6
  # Runs the content through [RDiscount](http://github.com/rtomayko/rdiscount).
7
- # This method takes no options.
7
+ #
8
+ # @option params [Array] symbol ([]) A list of RDiscount extensions
8
9
  #
9
10
  # @param [String] content The content to filter
10
11
  #
@@ -50,20 +50,32 @@ module Nanoc3::Filters
50
50
 
51
51
  # Convert to items
52
52
  imported_items = imported_filenames.map do |filename|
53
- pathname = Pathname.new(filename)
54
- next unless pathname.file?
55
- normalized_filename = pathname.realpath
56
- @items.find { |i| i[:content_filename] && Pathname.new(i[:content_filename]).realpath == normalized_filename }
53
+ # Find directory for this item
54
+ current_dir_pathname = Pathname.new(@item[:content_filename]).dirname.realpath
55
+
56
+ # Find absolute pathname for imported item
57
+ imported_pathname = Pathname.new(filename)
58
+ if imported_pathname.relative?
59
+ imported_pathname = current_dir_pathname + imported_pathname
60
+ end
61
+ next if !imported_pathname.exist?
62
+ imported_filename = imported_pathname.realpath
63
+
64
+ # Find matching item
65
+ @items.find do |i|
66
+ next if i[:content_filename].nil?
67
+ Pathname.new(i[:content_filename]).realpath == imported_filename
68
+ end
57
69
  end.compact
58
70
 
59
71
  # Require compilation of each item
60
- imported_items.each do |item|
72
+ imported_items.each do |i|
61
73
  # Notify
62
- Nanoc3::NotificationCenter.post(:visit_started, item)
63
- Nanoc3::NotificationCenter.post(:visit_ended, item)
74
+ Nanoc3::NotificationCenter.post(:visit_started, i)
75
+ Nanoc3::NotificationCenter.post(:visit_ended, i)
64
76
 
65
77
  # Raise unmet dependency error if item is not yet compiled
66
- any_uncompiled_rep = item.reps.find { |r| !r.compiled? }
78
+ any_uncompiled_rep = i.reps.find { |r| !r.compiled? }
67
79
  raise Nanoc3::Errors::UnmetDependency.new(any_uncompiled_rep) if any_uncompiled_rep
68
80
  end
69
81
 
@@ -0,0 +1,75 @@
1
+ # encoding: utf-8
2
+
3
+ module Nanoc3::Filters
4
+ class Sass < Nanoc3::Filter
5
+
6
+ # Runs the content through [Sass](http://sass-lang.com/).
7
+ # Parameters passed to this filter will be passed on to Sass.
8
+ #
9
+ # @param [String] content The content to filter
10
+ #
11
+ # @return [String] The filtered content
12
+ def run(content, params={})
13
+ require 'sass'
14
+
15
+ # Add imported_filename read accessor to ImportNode
16
+ # … but… but… nex3 said I could monkey patch it! :(
17
+ methods = ::Sass::Tree::ImportNode.instance_methods
18
+ if !methods.include?(:import_filename) && !methods.include?('import_filename')
19
+ ::Sass::Tree::ImportNode.send(:attr_reader, :imported_filename)
20
+ end
21
+
22
+ # Get options
23
+ options = params.dup
24
+ sass_filename = options[:filename] || (@item && @item[:content_filename])
25
+ options[:filename] ||= sass_filename
26
+
27
+ # Build engine
28
+ engine = ::Sass::Engine.new(content, options)
29
+
30
+ # Get import nodes
31
+ require 'set'
32
+ imported_nodes = []
33
+ unprocessed_nodes = Set.new([ engine.to_tree ])
34
+ until unprocessed_nodes.empty?
35
+ # Get an unprocessed node
36
+ node = unprocessed_nodes.each { |n| break n }
37
+ unprocessed_nodes.delete(node)
38
+
39
+ # Add to list of import nodes if necessary
40
+ imported_nodes << node if node.is_a?(::Sass::Tree::ImportNode)
41
+
42
+ # Mark children of this node for processing
43
+ node.children.each { |c| unprocessed_nodes << c }
44
+ end
45
+
46
+ # Get import paths
47
+ import_paths = (options[:load_paths] || []).dup
48
+ import_paths.unshift(File.dirname(sass_filename)) if sass_filename
49
+ imported_filenames = imported_nodes.map { |node| node.imported_filename }
50
+
51
+ # Convert to items
52
+ imported_items = imported_filenames.map do |filename|
53
+ pathname = Pathname.new(filename)
54
+ next unless pathname.file?
55
+ normalized_filename = pathname.realpath
56
+ @items.find { |i| i[:content_filename] && Pathname.new(i[:content_filename]).realpath == normalized_filename }
57
+ end.compact
58
+
59
+ # Require compilation of each item
60
+ imported_items.each do |item|
61
+ # Notify
62
+ Nanoc3::NotificationCenter.post(:visit_started, item)
63
+ Nanoc3::NotificationCenter.post(:visit_ended, item)
64
+
65
+ # Raise unmet dependency error if item is not yet compiled
66
+ any_uncompiled_rep = item.reps.find { |r| !r.compiled? }
67
+ raise Nanoc3::Errors::UnmetDependency.new(any_uncompiled_rep) if any_uncompiled_rep
68
+ end
69
+
70
+ # Done
71
+ engine.render
72
+ end
73
+
74
+ end
75
+ end
data/lib/nanoc3.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Nanoc3
4
4
 
5
5
  # The current nanoc version.
6
- VERSION = '3.1.7'
6
+ VERSION = '3.1.8'
7
7
 
8
8
  end
9
9
 
data/nanoc3.gemspec ADDED
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH.unshift(File.expand_path('../lib/', __FILE__))
4
+ require 'nanoc3'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'nanoc3'
8
+ s.version = Nanoc3::VERSION
9
+ s.summary = 'a web publishing system written in Ruby for building small to medium-sized websites.'
10
+ s.homepage = 'http://nanoc.stoneship.org/'
11
+
12
+ s.authors = 'Denis Defreyne'
13
+ s.email = 'denis.defreyne@stoneship.org'
14
+
15
+ s.files = Dir['[A-Z]*'] +
16
+ Dir['doc/yardoc_templates/**/*'] +
17
+ Dir['{bin,lib,tasks,test}/**/*'] +
18
+ [ 'nanoc3.gemspec', '.gemtest' ]
19
+ s.executables = [ 'nanoc3' ]
20
+ s.require_paths = [ 'lib' ]
21
+
22
+ s.rdoc_options = [ '--main', 'README.md' ]
23
+ s.extra_rdoc_files = [ 'ChangeLog', 'LICENSE', 'README.md', 'NEWS.md' ]
24
+
25
+ s.add_runtime_dependency('cri', '~> 1.0')
26
+
27
+ s.post_install_message = %q{------------------------------------------------------------------------------
28
+ Thanks for installing nanoc 3.1! Here are some resources to help you get
29
+ started:
30
+
31
+ * The tutorial at <http://nanoc.stoneship.org/tutorial/>
32
+ * The manual at <http://nanoc.stoneship.org/manual/>
33
+ * The discussion group at <http://groups.google.com/group/nanoc>
34
+
35
+ Because nanoc 3.1 has quite a few new features, be sure to check out the nanoc
36
+ blog at <http://nanoc.stoneship.org/blog/> for details about this release.
37
+
38
+ Enjoy!
39
+ ------------------------------------------------------------------------------
40
+ }
41
+ end
data/tasks/clean.rake ADDED
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rake/clean'
4
+
5
+ CLEAN.include([
6
+ 'coverage',
7
+ 'doc',
8
+ 'tmp'
9
+ ])
10
+
11
+ CLOBBER.include([ 'pkg' ])
data/tasks/doc.rake ADDED
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+
3
+ require 'yard'
4
+
5
+ YARD::Rake::YardocTask.new(:doc) do |yard|
6
+ yard.files = Dir['lib/**/*.rb']
7
+ yard.options = [
8
+ '--markup', 'markdown',
9
+ '--readme', 'README.md',
10
+ '--files', 'NEWS.md,LICENSE',
11
+ '--output-dir', 'doc/yardoc',
12
+ '--template-path', 'doc/yardoc_templates'
13
+ ]
14
+ end
data/tasks/gem.rake ADDED
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems/package_task'
4
+
5
+ namespace :pkg do
6
+
7
+ spec = eval(File.read('nanoc3.gemspec'))
8
+ Gem::PackageTask.new(spec) do |pkg|
9
+ pkg.need_zip = true
10
+ pkg.need_tar = true
11
+ end
12
+
13
+ end
data/tasks/test.rake ADDED
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+
3
+ require 'minitest/unit'
4
+
5
+ test = namespace :test do
6
+
7
+ # test:all
8
+ desc 'Run all tests'
9
+ task :all do
10
+ ENV['QUIET'] ||= 'true'
11
+
12
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/..'))
13
+
14
+ MiniTest::Unit.autorun
15
+
16
+ test_files = Dir['test/**/*_spec.rb'] + Dir['test/**/test_*.rb']
17
+ test_files.each { |f| require f }
18
+ end
19
+
20
+ # test:...
21
+ %w( base cli data_sources extra filters helpers tasks ).each do |dir|
22
+ desc "Run all #{dir} tests"
23
+ task dir.to_sym do |task|
24
+ ENV['QUIET'] ||= 'true'
25
+
26
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/..'))
27
+
28
+ MiniTest::Unit.autorun
29
+
30
+ test_files = Dir["test/#{dir}/**/*_spec.rb"] + Dir["test/#{dir}/**/test_*.rb"]
31
+ test_files.each { |f| require f }
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ desc 'Alias for test:all'
38
+ task :test => [ :'test:all' ]
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ describe 'Array#symbolize_keys' do
6
+
7
+ it 'should convert keys to symbols' do
8
+ array_old = [ :abc, 'xyz', { 'foo' => 'bar', :baz => :qux } ]
9
+ array_new = [ :abc, 'xyz', { :foo => 'bar', :baz => :qux } ]
10
+ array_old.symbolize_keys.must_equal array_new
11
+ end
12
+
13
+ end
14
+
15
+ describe 'Array#stringify_keys' do
16
+
17
+ it 'should convert keys to strings' do
18
+ array_old = [ :abc, 'xyz', { :foo => 'bar', 'baz' => :qux } ]
19
+ array_new = [ :abc, 'xyz', { 'foo' => 'bar', 'baz' => :qux } ]
20
+ array_old.stringify_keys.must_equal array_new
21
+ end
22
+
23
+ end
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ describe 'Hash#symbolize_keys' do
6
+
7
+ it 'should convert keys to symbols' do
8
+ hash_old = { 'foo' => 'bar' }
9
+ hash_new = { :foo => 'bar' }
10
+ hash_old.symbolize_keys.must_equal hash_new
11
+ end
12
+
13
+ end
14
+
15
+ describe 'Hash#stringify_keys' do
16
+
17
+ it 'should leave strings as strings' do
18
+ hash_old = { 'foo' => 'bar' }
19
+ hash_new = { 'foo' => 'bar' }
20
+ hash_old.stringify_keys.must_equal hash_new
21
+ end
22
+
23
+ it 'should convert symbols to strings' do
24
+ hash_old = { :foo => 'bar' }
25
+ hash_new = { 'foo' => 'bar' }
26
+ hash_old.stringify_keys.must_equal hash_new
27
+ end
28
+
29
+ it 'should convert integers to strings' do
30
+ hash_old = { 123 => 'bar' }
31
+ hash_new = { '123' => 'bar' }
32
+ hash_old.stringify_keys.must_equal hash_new
33
+ end
34
+
35
+ it 'should convert nil to an empty string' do
36
+ hash_old = { nil => 'bar' }
37
+ hash_new = { '' => 'bar' }
38
+ hash_old.stringify_keys.must_equal hash_new
39
+ end
40
+
41
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ describe 'String#cleaned_identifier' do
6
+
7
+ it 'should not convert already clean paths' do
8
+ '/foo/bar/'.cleaned_identifier.must_equal '/foo/bar/'
9
+ end
10
+
11
+ it 'should prepend slash if necessary' do
12
+ 'foo/bar/'.cleaned_identifier.must_equal '/foo/bar/'
13
+ end
14
+
15
+ it 'should append slash if necessary' do
16
+ '/foo/bar'.cleaned_identifier.must_equal '/foo/bar/'
17
+ end
18
+
19
+ it 'should remove double slashes at start' do
20
+ '//foo/bar/'.cleaned_identifier.must_equal '/foo/bar/'
21
+ end
22
+
23
+ it 'should remove double slashes at end' do
24
+ '/foo/bar//'.cleaned_identifier.must_equal '/foo/bar/'
25
+ end
26
+
27
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::CodeSnippetTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_load
10
+ # Initialize
11
+ $complete_insane_parrot = 'meow'
12
+
13
+ # Create code and load it
14
+ code_snippet = Nanoc3::CodeSnippet.new("$complete_insane_parrot = 'woof'", 'parrot.rb')
15
+ code_snippet.load
16
+
17
+ # Ensure code is loaded
18
+ assert_equal('woof', $complete_insane_parrot)
19
+ end
20
+
21
+ def test_load_with_toplevel_binding
22
+ # Initialize
23
+ @foo = 'meow'
24
+
25
+ # Create code and load it
26
+ code_snippet = Nanoc3::CodeSnippet.new("@foo = 'woof'", 'dog.rb')
27
+ code_snippet.load
28
+
29
+ # Ensure binding is correct
30
+ assert_equal('meow', @foo)
31
+ end
32
+
33
+ end