nanoc 3.6.9 → 3.6.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +15 -8
- data/Gemfile.lock +27 -14
- data/NEWS.md +14 -0
- data/lib/nanoc/base.rb +2 -0
- data/lib/nanoc/base/checksummer.rb +82 -0
- data/lib/nanoc/base/compilation/compiler.rb +4 -3
- data/lib/nanoc/base/compilation/filter.rb +3 -10
- data/lib/nanoc/base/compilation/rules_collection.rb +6 -1
- data/lib/nanoc/base/core_ext/array.rb +1 -1
- data/lib/nanoc/base/core_ext/hash.rb +1 -2
- data/lib/nanoc/base/core_ext/pathname.rb +1 -2
- data/lib/nanoc/base/core_ext/string.rb +1 -3
- data/lib/nanoc/base/errors.rb +9 -0
- data/lib/nanoc/base/result_data/item_rep.rb +2 -7
- data/lib/nanoc/base/source_data/code_snippet.rb +1 -1
- data/lib/nanoc/base/source_data/item.rb +1 -16
- data/lib/nanoc/base/source_data/layout.rb +1 -3
- data/lib/nanoc/base/source_data/site.rb +14 -0
- data/lib/nanoc/base/temp_filename_factory.rb +53 -0
- data/lib/nanoc/cli/commands/compile.rb +6 -2
- data/lib/nanoc/cli/commands/create-site.rb +3 -0
- data/lib/nanoc/cli/error_handler.rb +9 -5
- data/lib/nanoc/extra.rb +9 -8
- data/lib/nanoc/extra/jruby_nokogiri_warner.rb +48 -0
- data/lib/nanoc/extra/link_collector.rb +2 -0
- data/lib/nanoc/extra/piper.rb +1 -1
- data/lib/nanoc/filters/colorize_syntax.rb +2 -0
- data/lib/nanoc/filters/pandoc.rb +2 -2
- data/lib/nanoc/filters/relativize_paths.rb +2 -0
- data/lib/nanoc/filters/xsl.rb +2 -0
- data/lib/nanoc/version.rb +1 -1
- data/tasks/rubocop.rake +7 -3
- data/test/base/checksummer_spec.rb +274 -0
- data/test/base/core_ext/array_spec.rb +2 -2
- data/test/base/core_ext/hash_spec.rb +7 -4
- data/test/base/core_ext/pathname_spec.rb +6 -6
- data/test/base/core_ext/string_spec.rb +2 -2
- data/test/base/temp_filename_factory_spec.rb +72 -0
- data/test/base/test_site.rb +26 -0
- data/test/cli/commands/test_prune.rb +4 -0
- data/test/extra/checking/checks/test_css.rb +28 -24
- data/test/extra/checking/checks/test_html.rb +28 -24
- data/test/extra/test_piper.rb +12 -0
- data/test/filters/test_colorize_syntax.rb +6 -6
- data/test/filters/test_erb.rb +4 -0
- data/test/filters/test_pandoc.rb +15 -0
- data/test/filters/test_relativize_paths.rb +27 -65
- data/test/filters/test_xsl.rb +7 -35
- data/test/fixtures/vcr_cassettes/css_run_error.yml +65 -0
- data/test/fixtures/vcr_cassettes/css_run_ok.yml +55 -0
- data/test/fixtures/vcr_cassettes/html_run_error.yml +94 -0
- data/test/fixtures/vcr_cassettes/html_run_ok.yml +56 -0
- data/test/helper.rb +19 -9
- metadata +11 -2
@@ -247,22 +247,7 @@ module Nanoc
|
|
247
247
|
# @return [String] The checksum for this object. If its contents change,
|
248
248
|
# the checksum will change as well.
|
249
249
|
def checksum
|
250
|
-
|
251
|
-
if binary?
|
252
|
-
if File.exist?(raw_filename)
|
253
|
-
Pathname.new(raw_filename).checksum
|
254
|
-
else
|
255
|
-
''.checksum
|
256
|
-
end
|
257
|
-
else
|
258
|
-
@raw_content.checksum
|
259
|
-
end
|
260
|
-
|
261
|
-
attributes = @attributes.dup
|
262
|
-
attributes.delete(:file)
|
263
|
-
attributes_checksum = attributes.checksum
|
264
|
-
|
265
|
-
content_checksum + ',' + attributes_checksum
|
250
|
+
Nanoc::Checksummer.calc(self)
|
266
251
|
end
|
267
252
|
memoize :checksum
|
268
253
|
|
@@ -88,9 +88,7 @@ module Nanoc
|
|
88
88
|
# @return [String] The checksum for this object. If its contents change,
|
89
89
|
# the checksum will change as well.
|
90
90
|
def checksum
|
91
|
-
|
92
|
-
attributes.delete(:file)
|
93
|
-
@raw_content.checksum + ',' + attributes.checksum
|
91
|
+
Nanoc::Checksummer.calc(self)
|
94
92
|
end
|
95
93
|
memoize :checksum
|
96
94
|
|
@@ -245,6 +245,10 @@ module Nanoc
|
|
245
245
|
data_sources.each { |ds| ds.unuse }
|
246
246
|
setup_child_parent_links
|
247
247
|
|
248
|
+
# Ensure unique
|
249
|
+
ensure_identifier_uniqueness(@items, 'item')
|
250
|
+
ensure_identifier_uniqueness(@layouts, 'layout')
|
251
|
+
|
248
252
|
# Load compiler too
|
249
253
|
# FIXME this should not be necessary
|
250
254
|
compiler.load
|
@@ -346,6 +350,16 @@ module Nanoc
|
|
346
350
|
end
|
347
351
|
end
|
348
352
|
|
353
|
+
def ensure_identifier_uniqueness(objects, type)
|
354
|
+
seen = Set.new
|
355
|
+
objects.each do |obj|
|
356
|
+
if seen.include?(obj.identifier)
|
357
|
+
raise Nanoc::Errors::DuplicateIdentifier.new(obj.identifier, type)
|
358
|
+
end
|
359
|
+
seen << obj.identifier
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
349
363
|
# Builds the configuration hash based on the given argument. Also see
|
350
364
|
# {#initialize} for details.
|
351
365
|
def build_config(dir_or_config_hash)
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'tmpdir'
|
4
|
+
|
5
|
+
module Nanoc
|
6
|
+
|
7
|
+
class TempFilenameFactory
|
8
|
+
|
9
|
+
# @return [String] The root directory for all temporary filenames
|
10
|
+
attr_reader :root_dir
|
11
|
+
|
12
|
+
# @return [Nanoc::TempFilenameFactory] A common instance
|
13
|
+
def self.instance
|
14
|
+
@instance ||= new
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@counts = {}
|
19
|
+
@root_dir = Dir.mktmpdir('nanoc')
|
20
|
+
end
|
21
|
+
|
22
|
+
# @param [String] prefix A string prefix to include in the temporary
|
23
|
+
# filename, often the type of filename being provided.
|
24
|
+
#
|
25
|
+
# @return [String] A new unused filename
|
26
|
+
def create(prefix)
|
27
|
+
count = @counts.fetch(prefix, 0)
|
28
|
+
@counts[prefix] = count + 1
|
29
|
+
|
30
|
+
dirname = File.join(@root_dir, prefix)
|
31
|
+
filename = File.join(@root_dir, prefix, count.to_s)
|
32
|
+
|
33
|
+
FileUtils.mkdir_p(dirname)
|
34
|
+
|
35
|
+
filename
|
36
|
+
end
|
37
|
+
|
38
|
+
# @param [String] prefix A string prefix that indicates which temporary
|
39
|
+
# filenames should be deleted.
|
40
|
+
#
|
41
|
+
# @return [void]
|
42
|
+
def cleanup(prefix)
|
43
|
+
path = File.join(@root_dir, prefix)
|
44
|
+
if File.exist?(path)
|
45
|
+
FileUtils.remove_entry_secure(path)
|
46
|
+
end
|
47
|
+
|
48
|
+
@counts.delete(prefix)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -233,21 +233,25 @@ module Nanoc::CLI::Commands
|
|
233
233
|
|
234
234
|
def durations_per_filter
|
235
235
|
@_durations_per_filter ||= begin
|
236
|
-
|
236
|
+
result = {}
|
237
|
+
@times.keys.each do |filter_name|
|
237
238
|
durations = durations_for_filter(filter_name)
|
238
239
|
if durations
|
239
240
|
result[filter_name] = durations
|
240
241
|
end
|
241
242
|
end
|
243
|
+
result
|
242
244
|
end
|
243
245
|
end
|
244
246
|
|
245
247
|
def durations_for_filter(filter_name)
|
246
|
-
|
248
|
+
result = []
|
249
|
+
@times[filter_name].each do |sample|
|
247
250
|
if sample[:start] && sample[:stop]
|
248
251
|
result << sample[:stop] - sample[:start]
|
249
252
|
end
|
250
253
|
end
|
254
|
+
result
|
251
255
|
end
|
252
256
|
|
253
257
|
end
|
@@ -84,6 +84,9 @@ data_sources:
|
|
84
84
|
# will have the identifier “/about/” when turned off, but when turned on
|
85
85
|
# it will become “/about.html/” instead.
|
86
86
|
allow_periods_in_identifiers: false
|
87
|
+
|
88
|
+
# The default encoding for all files in `content/` and `layouts/`.
|
89
|
+
encoding: utf-8
|
87
90
|
EOS
|
88
91
|
|
89
92
|
DEFAULT_RULES = <<EOS unless defined? DEFAULT_RULES
|
@@ -58,12 +58,16 @@ module Nanoc::CLI
|
|
58
58
|
exit!(0)
|
59
59
|
end
|
60
60
|
end
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
|
62
|
+
# Set stack trace dump handler
|
63
|
+
if !defined?(RUBY_ENGINE) || RUBY_ENGINE != 'jruby'
|
64
|
+
begin
|
65
|
+
Signal.trap('USR1') do
|
66
|
+
puts 'Caught USR1; dumping a stack trace'
|
67
|
+
puts caller.map { |i| " #{i}" }.join("\n")
|
68
|
+
end
|
69
|
+
rescue ArgumentError
|
65
70
|
end
|
66
|
-
rescue ArgumentError
|
67
71
|
end
|
68
72
|
|
69
73
|
# Run
|
data/lib/nanoc/extra.rb
CHANGED
@@ -2,14 +2,15 @@
|
|
2
2
|
|
3
3
|
module Nanoc::Extra
|
4
4
|
|
5
|
-
autoload 'AutoCompiler',
|
6
|
-
autoload 'Checking',
|
7
|
-
autoload 'CHiCk',
|
8
|
-
autoload 'FilesystemTools',
|
9
|
-
autoload 'LinkCollector',
|
10
|
-
autoload 'Pruner',
|
11
|
-
autoload 'Validators',
|
12
|
-
autoload 'Piper',
|
5
|
+
autoload 'AutoCompiler', 'nanoc/extra/auto_compiler'
|
6
|
+
autoload 'Checking', 'nanoc/extra/checking'
|
7
|
+
autoload 'CHiCk', 'nanoc/extra/chick'
|
8
|
+
autoload 'FilesystemTools', 'nanoc/extra/filesystem_tools'
|
9
|
+
autoload 'LinkCollector', 'nanoc/extra/link_collector.rb'
|
10
|
+
autoload 'Pruner', 'nanoc/extra/pruner'
|
11
|
+
autoload 'Validators', 'nanoc/extra/validators'
|
12
|
+
autoload 'Piper', 'nanoc/extra/piper'
|
13
|
+
autoload 'JRubyNokogiriWarner', 'nanoc/extra/jruby_nokogiri_warner'
|
13
14
|
|
14
15
|
# Deprecated; use {Nanoc::Context} instead
|
15
16
|
# TODO [in nanoc 4.0] remove me
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'singleton'
|
4
|
+
|
5
|
+
module Nanoc::Extra
|
6
|
+
|
7
|
+
class JRubyNokogiriWarner
|
8
|
+
|
9
|
+
include Singleton
|
10
|
+
|
11
|
+
TEXT = <<EOS
|
12
|
+
--------------------------------------------------------------------------------
|
13
|
+
Note:
|
14
|
+
|
15
|
+
The behavior of Pure Java Nokogiri differs from the Nokogiri used on the
|
16
|
+
standard Ruby interpreter (MRI) due to differences in underlying libraries.
|
17
|
+
|
18
|
+
These sometimes problematic behavioral differences can cause nanoc filters not
|
19
|
+
to function properly, if at all. If you need reliable (X)HTML and XML handling
|
20
|
+
functionality, consider not using Nokogiri on JRuby for the time being.
|
21
|
+
|
22
|
+
These issues are being worked on both from the Nokogiri and the nanoc side. Keep
|
23
|
+
your Nokogiri and nanoc versions up to date!
|
24
|
+
|
25
|
+
For details, see https://github.com/nanoc/nanoc/pull/422.
|
26
|
+
--------------------------------------------------------------------------------
|
27
|
+
EOS
|
28
|
+
|
29
|
+
def self.check_and_warn
|
30
|
+
instance.check_and_warn
|
31
|
+
end
|
32
|
+
|
33
|
+
def initialize
|
34
|
+
@warned = false
|
35
|
+
end
|
36
|
+
|
37
|
+
def check_and_warn
|
38
|
+
return if !defined?(RUBY_ENGINE)
|
39
|
+
return if RUBY_ENGINE != 'jruby'
|
40
|
+
return if @warned
|
41
|
+
|
42
|
+
$stderr.puts TEXT
|
43
|
+
@warned = true
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
data/lib/nanoc/extra/piper.rb
CHANGED
@@ -83,6 +83,8 @@ module Nanoc::Filters
|
|
83
83
|
#
|
84
84
|
# @return [String] The filtered content
|
85
85
|
def run(content, params = {})
|
86
|
+
Nanoc::Extra::JRubyNokogiriWarner.check_and_warn
|
87
|
+
|
86
88
|
# Take colorizers from parameters
|
87
89
|
@colorizers = Hash.new(params[:default_colorizer] || DEFAULT_COLORIZER)
|
88
90
|
(params[:colorizers] || {}).each_pair do |language, colorizer|
|
data/lib/nanoc/filters/pandoc.rb
CHANGED
@@ -12,8 +12,8 @@ module Nanoc::Filters
|
|
12
12
|
# @param [String] content The content to filter
|
13
13
|
#
|
14
14
|
# @return [String] The filtered content
|
15
|
-
def run(content, params
|
16
|
-
PandocRuby.convert(content, params)
|
15
|
+
def run(content, *params)
|
16
|
+
PandocRuby.convert(content, *params)
|
17
17
|
end
|
18
18
|
|
19
19
|
end
|
@@ -29,6 +29,8 @@ module Nanoc::Filters
|
|
29
29
|
#
|
30
30
|
# @return [String] The filtered content
|
31
31
|
def run(content, params = {})
|
32
|
+
Nanoc::Extra::JRubyNokogiriWarner.check_and_warn
|
33
|
+
|
32
34
|
# Set assigns so helper function can be used
|
33
35
|
@item_rep = assigns[:item_rep] if @item_rep.nil?
|
34
36
|
|
data/lib/nanoc/filters/xsl.rb
CHANGED
data/lib/nanoc/version.rb
CHANGED
data/tasks/rubocop.rake
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
-
|
1
|
+
begin
|
2
|
+
require 'rubocop/rake_task'
|
2
3
|
|
3
|
-
Rubocop::RakeTask.new(:rubocop) do |task|
|
4
|
-
|
4
|
+
Rubocop::RakeTask.new(:rubocop) do |task|
|
5
|
+
task.patterns = ['lib/**/*.rb']
|
6
|
+
end
|
7
|
+
rescue LoadError
|
8
|
+
warn "Could not load Rubocop. Rubocop rake tasks will be unavailable."
|
5
9
|
end
|
@@ -0,0 +1,274 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
describe Nanoc::Checksummer do
|
6
|
+
|
7
|
+
subject { Nanoc::Checksummer }
|
8
|
+
|
9
|
+
CHECKSUM_REGEX = /\A[0-9a-zA-Z\/+]+=*\Z/
|
10
|
+
|
11
|
+
describe 'for String' do
|
12
|
+
|
13
|
+
it 'should checksum strings' do
|
14
|
+
subject.calc('foo').must_equal('+5k/BWvkYc6T1qhGaSyf3861CyE=')
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'for Array' do
|
20
|
+
|
21
|
+
it 'should checksum arrays' do
|
22
|
+
subject.calc([1, 'a', :a]).must_equal 'YtWOEFUAMQritkY38KXHFZM/n2E='
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should take order into account when checksumming arrays' do
|
26
|
+
subject.calc([:a, 'a', 1]).wont_equal(subject.calc([1, 'a', :a]))
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should checksum non-serializable arrays' do
|
30
|
+
subject.calc([-> {}]).must_match(CHECKSUM_REGEX)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'for Hash' do
|
36
|
+
|
37
|
+
it 'should checksum hashes' do
|
38
|
+
subject.calc({ a: 1, b: 2 }).must_equal 'qY8fW6gWK7F1XQ9MLrx3Gru/RTY='
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should take order into account when checksumming hashes' do
|
42
|
+
subject.calc({ a: 1, b: 2 }).wont_equal(subject.calc({ b: 2, a: 1 }))
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should checksum non-serializable hashes' do
|
46
|
+
subject.calc({ a: ->{} }).must_match(CHECKSUM_REGEX)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'for Pathname' do
|
52
|
+
|
53
|
+
let(:file) { Tempfile.new('foo') }
|
54
|
+
let(:filename) { file.path }
|
55
|
+
let(:pathname) { Pathname.new(filename) }
|
56
|
+
let(:atime) { 1234567890 }
|
57
|
+
let(:mtime) { 1234567890 }
|
58
|
+
let(:data) { 'stuffs' }
|
59
|
+
let(:normal_checksum) { 'THy7Y28oroov/KvPxT6wcMnXr/s=' }
|
60
|
+
|
61
|
+
before do
|
62
|
+
file.write(data)
|
63
|
+
file.close
|
64
|
+
File.utime(atime, mtime, filename)
|
65
|
+
end
|
66
|
+
|
67
|
+
after do
|
68
|
+
file.unlink
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'does not exist' do
|
72
|
+
|
73
|
+
let(:non_existing_filename) { 'askldjfklaslasdfkjsajdf' }
|
74
|
+
let(:pathname) { Pathname.new(filename) }
|
75
|
+
|
76
|
+
it 'should still checksum' do
|
77
|
+
subject.calc(pathname).must_equal(normal_checksum)
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should get the mtime right' do
|
83
|
+
stat = File.stat(filename)
|
84
|
+
stat.mtime.to_i.must_equal(mtime)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should get the file size right' do
|
88
|
+
stat = File.stat(filename)
|
89
|
+
stat.size.must_equal(6)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should checksum binary content' do
|
93
|
+
subject.calc(pathname).must_equal(normal_checksum)
|
94
|
+
end
|
95
|
+
|
96
|
+
describe 'if the mtime changes' do
|
97
|
+
|
98
|
+
let(:mtime) { 1333333333 }
|
99
|
+
|
100
|
+
it 'should have a different checksum' do
|
101
|
+
subject.calc(pathname).must_match(CHECKSUM_REGEX)
|
102
|
+
subject.calc(pathname).wont_equal(normal_checksum)
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
describe 'if the content changes, but not the file size' do
|
108
|
+
|
109
|
+
let(:data) { 'STUFF!' }
|
110
|
+
|
111
|
+
it 'should have the same checksum' do
|
112
|
+
subject.calc(pathname).must_equal(normal_checksum)
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
describe 'if the file size changes' do
|
118
|
+
|
119
|
+
let(:data) { 'stuff and stuff and stuff!!!' }
|
120
|
+
|
121
|
+
it 'should have a different checksum' do
|
122
|
+
subject.calc(pathname).must_match(CHECKSUM_REGEX)
|
123
|
+
subject.calc(pathname).wont_equal(normal_checksum)
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'should not have the same checksum for same content but different class'
|
131
|
+
|
132
|
+
describe 'for Nanoc::RulesCollection' do
|
133
|
+
|
134
|
+
let(:data) { 'STUFF!' }
|
135
|
+
let(:normal_checksum) { 'r4SwDpCp5saBPeZk2gQOJcipTZU=' }
|
136
|
+
|
137
|
+
let(:rules_collection) do
|
138
|
+
coll = Nanoc::RulesCollection.new(nil)
|
139
|
+
coll.data = data
|
140
|
+
coll
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should calculate' do
|
144
|
+
subject.calc(rules_collection).must_equal(normal_checksum)
|
145
|
+
end
|
146
|
+
|
147
|
+
describe 'if the content changes' do
|
148
|
+
|
149
|
+
let(:data) { 'Other stuff!' }
|
150
|
+
|
151
|
+
it 'should have a different checksum' do
|
152
|
+
subject.calc(rules_collection).must_match(CHECKSUM_REGEX)
|
153
|
+
subject.calc(rules_collection).wont_equal(normal_checksum)
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
describe 'for Nanoc::CodeSnippet' do
|
161
|
+
|
162
|
+
let(:data) { 'asdf' }
|
163
|
+
let(:filename) { File.expand_path('bob.txt') }
|
164
|
+
let(:code_snippet) { Nanoc::CodeSnippet.new(data, filename) }
|
165
|
+
let(:normal_checksum) { 'ZSo56CFoBcNgiDsWOfLLquH2sF0=' }
|
166
|
+
|
167
|
+
it 'should checksum the data' do
|
168
|
+
subject.calc(code_snippet).must_equal(normal_checksum)
|
169
|
+
end
|
170
|
+
|
171
|
+
describe 'if the filename changes' do
|
172
|
+
|
173
|
+
let(:filename) { File.expand_path('george.txt') }
|
174
|
+
|
175
|
+
it 'should have the same checksum' do
|
176
|
+
subject.calc(code_snippet).must_equal(normal_checksum)
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
describe 'if the content changes' do
|
182
|
+
|
183
|
+
let(:data) { 'Other stuff!' }
|
184
|
+
|
185
|
+
it 'should have a different checksum' do
|
186
|
+
subject.calc(code_snippet).must_match(CHECKSUM_REGEX)
|
187
|
+
subject.calc(code_snippet).wont_equal(normal_checksum)
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
describe 'for Nanoc::Configuration' do
|
195
|
+
|
196
|
+
let(:wrapped) { { a: 1, b: 2 } }
|
197
|
+
let(:configuration) { Nanoc::Configuration.new(wrapped) }
|
198
|
+
let(:normal_checksum) { 'eYYQ74x29njbtXMtuKZX/ogD8JA=' }
|
199
|
+
|
200
|
+
it 'should checksum the hash' do
|
201
|
+
subject.calc(configuration).must_equal('eYYQ74x29njbtXMtuKZX/ogD8JA=')
|
202
|
+
end
|
203
|
+
|
204
|
+
describe 'if the content changes' do
|
205
|
+
|
206
|
+
let(:wrapped) { { a: 666, b: 2 } }
|
207
|
+
|
208
|
+
it 'should have a different checksum' do
|
209
|
+
subject.calc(configuration).must_match(CHECKSUM_REGEX)
|
210
|
+
subject.calc(configuration).wont_equal(normal_checksum)
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
describe 'for Nanoc::Item' do
|
218
|
+
|
219
|
+
let(:content) { 'asdf' }
|
220
|
+
let(:filename) { File.expand_path('bob.txt') }
|
221
|
+
let(:attributes) { { a: 1, b: 2 } }
|
222
|
+
let(:identifier) { '/foo/' }
|
223
|
+
let(:item) { Nanoc::Item.new(content, attributes, identifier) }
|
224
|
+
let(:normal_checksum) { 'eTPdmaG7UAuPzH210HM1JvJaWDo=' }
|
225
|
+
|
226
|
+
it 'should checksum item' do
|
227
|
+
subject.calc(item).must_equal(normal_checksum)
|
228
|
+
end
|
229
|
+
|
230
|
+
describe 'with changed attributes' do
|
231
|
+
|
232
|
+
let(:attributes) { { x: 4, y: 5 } }
|
233
|
+
|
234
|
+
it 'should have a different checksum' do
|
235
|
+
subject.calc(item).must_match(CHECKSUM_REGEX)
|
236
|
+
subject.calc(item).wont_equal(normal_checksum)
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
describe 'with changed content' do
|
242
|
+
|
243
|
+
let(:content) { 'something drastically different' }
|
244
|
+
|
245
|
+
it 'should have a different checksum' do
|
246
|
+
subject.calc(item).must_match(CHECKSUM_REGEX)
|
247
|
+
subject.calc(item).wont_equal(normal_checksum)
|
248
|
+
end
|
249
|
+
|
250
|
+
end
|
251
|
+
|
252
|
+
end
|
253
|
+
|
254
|
+
describe 'for other marshal-able classes' do
|
255
|
+
|
256
|
+
let(:obj) { :foobar }
|
257
|
+
|
258
|
+
it 'should checksum' do
|
259
|
+
subject.calc(obj).must_match(CHECKSUM_REGEX)
|
260
|
+
end
|
261
|
+
|
262
|
+
end
|
263
|
+
|
264
|
+
describe 'for other non-marshal-able classes' do
|
265
|
+
|
266
|
+
let(:obj) { proc {} }
|
267
|
+
|
268
|
+
it 'should checksum' do
|
269
|
+
subject.calc(obj).must_match(CHECKSUM_REGEX)
|
270
|
+
end
|
271
|
+
|
272
|
+
end
|
273
|
+
|
274
|
+
end
|