nanoc3 3.1.7 → 3.1.8
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/.gemtest +0 -0
- data/LICENSE +1 -1
- data/NEWS.md +9 -0
- data/doc/yardoc_templates/default/layout/html/footer.erb +10 -0
- data/lib/nanoc3/base/item.rb +1 -1
- data/lib/nanoc3/base/item_rep.rb +1 -0
- data/lib/nanoc3/base/layout.rb +1 -1
- data/lib/nanoc3/cli/base.rb +4 -2
- data/lib/nanoc3/cli/commands/view.rb +1 -0
- data/lib/nanoc3/data_sources/filesystem.rb +25 -6
- data/lib/nanoc3/data_sources/filesystem_unified.rb +5 -5
- data/lib/nanoc3/extra/validators/links.rb +1 -1
- data/lib/nanoc3/filters/rdiscount.rb +2 -1
- data/lib/nanoc3/filters/sass.rb +20 -8
- data/lib/nanoc3/filters/sass.rb.orig +75 -0
- data/lib/nanoc3.rb +1 -1
- data/nanoc3.gemspec +41 -0
- data/tasks/clean.rake +11 -0
- data/tasks/doc.rake +14 -0
- data/tasks/gem.rake +13 -0
- data/tasks/test.rake +38 -0
- data/test/base/core_ext/array_spec.rb +23 -0
- data/test/base/core_ext/hash_spec.rb +41 -0
- data/test/base/core_ext/string_spec.rb +27 -0
- data/test/base/test_code_snippet.rb +33 -0
- data/test/base/test_compiler.rb +410 -0
- data/test/base/test_compiler_dsl.rb +121 -0
- data/test/base/test_context.rb +33 -0
- data/test/base/test_data_source.rb +48 -0
- data/test/base/test_dependency_tracker.rb +510 -0
- data/test/base/test_directed_graph.rb +91 -0
- data/test/base/test_filter.rb +85 -0
- data/test/base/test_item.rb +141 -0
- data/test/base/test_item_rep.rb +953 -0
- data/test/base/test_layout.rb +44 -0
- data/test/base/test_notification_center.rb +36 -0
- data/test/base/test_plugin.rb +32 -0
- data/test/base/test_rule.rb +21 -0
- data/test/base/test_rule_context.rb +63 -0
- data/test/base/test_site.rb +366 -0
- data/test/cli/commands/test_compile.rb +12 -0
- data/test/cli/commands/test_create_item.rb +12 -0
- data/test/cli/commands/test_create_layout.rb +28 -0
- data/test/cli/commands/test_create_site.rb +24 -0
- data/test/cli/commands/test_help.rb +12 -0
- data/test/cli/commands/test_info.rb +12 -0
- data/test/cli/commands/test_update.rb +12 -0
- data/test/cli/test_logger.rb +12 -0
- data/test/data_sources/test_filesystem.rb +420 -0
- data/test/data_sources/test_filesystem_unified.rb +538 -0
- data/test/data_sources/test_filesystem_verbose.rb +359 -0
- data/test/extra/core_ext/test_enumerable.rb +32 -0
- data/test/extra/core_ext/test_time.rb +17 -0
- data/test/extra/deployers/test_rsync.rb +234 -0
- data/test/extra/test_auto_compiler.rb +482 -0
- data/test/extra/test_file_proxy.rb +21 -0
- data/test/extra/test_vcs.rb +24 -0
- data/test/extra/validators/test_links.rb +53 -0
- data/test/extra/validators/test_w3c.rb +49 -0
- data/test/filters/test_bluecloth.rb +20 -0
- data/test/filters/test_coderay.rb +46 -0
- data/test/filters/test_colorize_syntax.rb +56 -0
- data/test/filters/test_erb.rb +72 -0
- data/test/filters/test_erubis.rb +72 -0
- data/test/filters/test_haml.rb +98 -0
- data/test/filters/test_kramdown.rb +20 -0
- data/test/filters/test_less.rb +59 -0
- data/test/filters/test_markaby.rb +26 -0
- data/test/filters/test_maruku.rb +20 -0
- data/test/filters/test_rainpress.rb +31 -0
- data/test/filters/test_rdiscount.rb +33 -0
- data/test/filters/test_rdoc.rb +18 -0
- data/test/filters/test_redcloth.rb +20 -0
- data/test/filters/test_relativize_paths.rb +231 -0
- data/test/filters/test_rubypants.rb +20 -0
- data/test/filters/test_sass.rb +170 -0
- data/test/filters/test_sass.rb.orig +103 -0
- data/test/gem_loader.rb +11 -0
- data/test/helper.rb +99 -0
- data/test/helpers/test_blogging.rb +808 -0
- data/test/helpers/test_breadcrumbs.rb +83 -0
- data/test/helpers/test_capturing.rb +42 -0
- data/test/helpers/test_filtering.rb +108 -0
- data/test/helpers/test_html_escape.rb +18 -0
- data/test/helpers/test_link_to.rb +251 -0
- data/test/helpers/test_rendering.rb +109 -0
- data/test/helpers/test_tagging.rb +89 -0
- data/test/helpers/test_text.rb +26 -0
- data/test/helpers/test_xml_sitemap.rb +69 -0
- data/test/tasks/test_clean.rb +71 -0
- metadata +83 -8
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/helper'
|
4
|
+
|
5
|
+
class Nanoc3::LayoutTest < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
include Nanoc3::TestHelpers
|
8
|
+
|
9
|
+
def test_initialize
|
10
|
+
# Make sure attributes are cleaned
|
11
|
+
layout = Nanoc3::Layout.new("content", { 'foo' => 'bar' }, '/foo/')
|
12
|
+
assert_equal({ :foo => 'bar' }, layout.attributes)
|
13
|
+
|
14
|
+
# Make sure identifier is cleaned
|
15
|
+
layout = Nanoc3::Layout.new("content", { 'foo' => 'bar' }, 'foo')
|
16
|
+
assert_equal('/foo/', layout.identifier)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_frozen_identifier
|
20
|
+
layout = Nanoc3::Layout.new("foo", {}, '/foo')
|
21
|
+
|
22
|
+
error = assert_raises(RuntimeError) do
|
23
|
+
layout.identifier.chop!
|
24
|
+
end
|
25
|
+
assert_equal "can't modify frozen string", error.message
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_lookup_with_known_attribute
|
29
|
+
# Create layout
|
30
|
+
layout = Nanoc3::Layout.new("content", { 'foo' => 'bar' }, '/foo/')
|
31
|
+
|
32
|
+
# Check attributes
|
33
|
+
assert_equal('bar', layout[:foo])
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_lookup_with_unknown_attribute
|
37
|
+
# Create layout
|
38
|
+
layout = Nanoc3::Layout.new("content", { 'foo' => 'bar' }, '/foo/')
|
39
|
+
|
40
|
+
# Check attributes
|
41
|
+
assert_equal(nil, layout[:filter])
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/helper'
|
4
|
+
|
5
|
+
class Nanoc3::NotificationCenterTest < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
include Nanoc3::TestHelpers
|
8
|
+
|
9
|
+
def test_post
|
10
|
+
# Set up notification
|
11
|
+
Nanoc3::NotificationCenter.on :ping_received, :test do
|
12
|
+
@ping_received = true
|
13
|
+
end
|
14
|
+
|
15
|
+
# Post
|
16
|
+
@ping_received = false
|
17
|
+
Nanoc3::NotificationCenter.post :ping_received
|
18
|
+
assert(@ping_received)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_remove
|
22
|
+
# Set up notification
|
23
|
+
Nanoc3::NotificationCenter.on :ping_received, :test do
|
24
|
+
@ping_received = true
|
25
|
+
end
|
26
|
+
|
27
|
+
# Remove observer
|
28
|
+
Nanoc3::NotificationCenter.remove :ping_received, :test
|
29
|
+
|
30
|
+
# Post
|
31
|
+
@ping_received = false
|
32
|
+
Nanoc3::NotificationCenter.post :ping_received
|
33
|
+
assert(!@ping_received)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/helper'
|
4
|
+
|
5
|
+
class Nanoc3::PluginTest < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
include Nanoc3::TestHelpers
|
8
|
+
|
9
|
+
class SampleFilter < Nanoc3::Filter
|
10
|
+
identifier :_plugin_test_sample_filter
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_named
|
14
|
+
# Find existant filter
|
15
|
+
filter = Nanoc3::Filter.named(:erb)
|
16
|
+
assert(!filter.nil?)
|
17
|
+
|
18
|
+
# Find non-existant filter
|
19
|
+
filter = Nanoc3::Filter.named(:lksdaffhdlkashlgkskahf)
|
20
|
+
assert(filter.nil?)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_register
|
24
|
+
SampleFilter.send(:identifier, :_plugin_test_sample_filter)
|
25
|
+
|
26
|
+
registry = Nanoc3::PluginRegistry.instance
|
27
|
+
filter = registry.find(Nanoc3::Filter, :_plugin_test_sample_filter)
|
28
|
+
|
29
|
+
refute_nil filter
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/helper'
|
4
|
+
|
5
|
+
class Nanoc3::RuleTest < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
include Nanoc3::TestHelpers
|
8
|
+
|
9
|
+
def test_initialize
|
10
|
+
# TODO implement
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_applicable_to
|
14
|
+
# TODO implement
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_apply_to
|
18
|
+
# TODO implement
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/helper'
|
4
|
+
|
5
|
+
class Nanoc3::RuleContextTest < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
include Nanoc3::TestHelpers
|
8
|
+
|
9
|
+
def test_objects
|
10
|
+
# Mock everything
|
11
|
+
config = mock
|
12
|
+
items = mock
|
13
|
+
layouts = mock
|
14
|
+
site = mock
|
15
|
+
site.stubs(:config).returns(config)
|
16
|
+
site.stubs(:items).returns(items)
|
17
|
+
site.stubs(:layouts).returns(layouts)
|
18
|
+
item = mock
|
19
|
+
item.stubs(:site).returns(site)
|
20
|
+
rep = mock
|
21
|
+
rep.stubs(:item).returns(item)
|
22
|
+
|
23
|
+
# Create context
|
24
|
+
@rule_context = Nanoc3::RuleContext.new(rep)
|
25
|
+
|
26
|
+
# Check
|
27
|
+
assert_equal rep, @rule_context.rep
|
28
|
+
assert_equal item, @rule_context.item
|
29
|
+
assert_equal site, @rule_context.site
|
30
|
+
assert_equal config, @rule_context.config
|
31
|
+
assert_equal layouts, @rule_context.layouts
|
32
|
+
assert_equal items, @rule_context.items
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_actions
|
36
|
+
# Mock everything
|
37
|
+
config = mock
|
38
|
+
items = mock
|
39
|
+
layouts = mock
|
40
|
+
site = mock
|
41
|
+
site.stubs(:config).returns(config)
|
42
|
+
site.stubs(:items).returns(items)
|
43
|
+
site.stubs(:layouts).returns(layouts)
|
44
|
+
item = mock
|
45
|
+
item.stubs(:site).returns(site)
|
46
|
+
|
47
|
+
# Mock rep
|
48
|
+
rep = mock
|
49
|
+
rep.stubs(:item).returns(item)
|
50
|
+
rep.expects(:filter).with(:foo, { :bar => 'baz' })
|
51
|
+
rep.expects(:layout).with('foo')
|
52
|
+
rep.expects(:snapshot).with('awesome')
|
53
|
+
|
54
|
+
# Create context
|
55
|
+
@rule_context = Nanoc3::RuleContext.new(rep)
|
56
|
+
|
57
|
+
# Check
|
58
|
+
rep.filter :foo, :bar => 'baz'
|
59
|
+
rep.layout 'foo'
|
60
|
+
rep.snapshot 'awesome'
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,366 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/helper'
|
4
|
+
|
5
|
+
class Nanoc3::SiteTest < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
include Nanoc3::TestHelpers
|
8
|
+
|
9
|
+
def test_initialize_with_dir_without_config_yaml
|
10
|
+
assert_raises(Errno::ENOENT) do
|
11
|
+
site = Nanoc3::Site.new('.')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_initialize_with_dir_with_config_yaml
|
16
|
+
File.open('config.yaml', 'w') { |io| io.write('output_dir: public_html') }
|
17
|
+
site = Nanoc3::Site.new('.')
|
18
|
+
assert_equal 'public_html', site.config[:output_dir]
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_initialize_with_config_hash
|
22
|
+
site = Nanoc3::Site.new(:foo => 'bar')
|
23
|
+
assert_equal 'bar', site.config[:foo]
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_initialize_with_incomplete_data_source_config
|
27
|
+
site = Nanoc3::Site.new(:data_sources => [ { :type => 'foo', :items_root => '/bar/' } ])
|
28
|
+
assert_equal('foo', site.config[:data_sources][0][:type])
|
29
|
+
assert_equal('/bar/', site.config[:data_sources][0][:items_root])
|
30
|
+
assert_equal('/', site.config[:data_sources][0][:layouts_root])
|
31
|
+
assert_equal({}, site.config[:data_sources][0][:config])
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_load_rules_with_existing_rules_file
|
35
|
+
# Mock DSL
|
36
|
+
dsl = mock
|
37
|
+
dsl.expects(:compile).with('*')
|
38
|
+
|
39
|
+
# Create site
|
40
|
+
site = Nanoc3::Site.new({})
|
41
|
+
site.expects(:dsl).returns(dsl)
|
42
|
+
|
43
|
+
# Create rules file
|
44
|
+
File.open('Rules', 'w') do |io|
|
45
|
+
io.write <<-EOF
|
46
|
+
compile '*' do
|
47
|
+
# ... do nothing ...
|
48
|
+
end
|
49
|
+
EOF
|
50
|
+
end
|
51
|
+
|
52
|
+
# Load rules
|
53
|
+
site.send :load_rules
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_load_rules_with_broken_rules_file
|
57
|
+
# Mock DSL
|
58
|
+
dsl = mock
|
59
|
+
dsl.expects(:some_function_that_doesn_really_exist)
|
60
|
+
dsl.expects(:weird_param_number_one)
|
61
|
+
dsl.expects(:mysterious_param_number_two)
|
62
|
+
|
63
|
+
# Create site
|
64
|
+
site = Nanoc3::Site.new({})
|
65
|
+
site.expects(:dsl).returns(dsl)
|
66
|
+
|
67
|
+
# Create rules file
|
68
|
+
File.open('Rules', 'w') do |io|
|
69
|
+
io.write <<-EOF
|
70
|
+
some_function_that_doesn_really_exist(
|
71
|
+
weird_param_number_one,
|
72
|
+
mysterious_param_number_two
|
73
|
+
)
|
74
|
+
EOF
|
75
|
+
end
|
76
|
+
|
77
|
+
# Load rules
|
78
|
+
site.send :load_rules
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_load_data_sources_first
|
82
|
+
# Create site
|
83
|
+
Nanoc3::CLI::Base.new.run([ 'create_site', 'bar' ])
|
84
|
+
|
85
|
+
FileUtils.cd('bar') do
|
86
|
+
# Create data source code
|
87
|
+
File.open('lib/some_data_source.rb', 'w') do |io|
|
88
|
+
io.write "class FooDataSource < Nanoc3::DataSource\n"
|
89
|
+
io.write " identifier :site_test_foo\n"
|
90
|
+
io.write " def items ; [ Nanoc3::Item.new('content', {}, '/foo/') ] ; end\n"
|
91
|
+
io.write "end\n"
|
92
|
+
end
|
93
|
+
|
94
|
+
# Update configuration
|
95
|
+
File.open('config.yaml', 'w') do |io|
|
96
|
+
io.write "data_sources:\n"
|
97
|
+
io.write " - type: site_test_foo"
|
98
|
+
end
|
99
|
+
|
100
|
+
# Create site
|
101
|
+
site = Nanoc3::Site.new('.')
|
102
|
+
site.load_data
|
103
|
+
|
104
|
+
# Check
|
105
|
+
assert_equal 1, site.data_sources.size
|
106
|
+
assert_equal '/foo/', site.items[0].identifier
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_disallow_routes_not_starting_with_slash
|
111
|
+
# Create site
|
112
|
+
Nanoc3::CLI::Base.new.run([ 'create_site', 'bar' ])
|
113
|
+
|
114
|
+
FileUtils.cd('bar') do
|
115
|
+
# Create routes
|
116
|
+
File.open('Rules', 'w') do |io|
|
117
|
+
io.write "compile '*' do\n"
|
118
|
+
io.write " layout 'default'\n"
|
119
|
+
io.write "end\n"
|
120
|
+
io.write "\n"
|
121
|
+
io.write "route '*' do\n"
|
122
|
+
io.write " 'index.html'\n"
|
123
|
+
io.write "end\n"
|
124
|
+
io.write "\n"
|
125
|
+
io.write "layout '*', :erb\n"
|
126
|
+
end
|
127
|
+
|
128
|
+
# Create site
|
129
|
+
site = Nanoc3::Site.new('.')
|
130
|
+
error = assert_raises(RuntimeError) do
|
131
|
+
site.load_data
|
132
|
+
end
|
133
|
+
assert_match /^The path returned for the.*does not start with a slash. Please ensure that all routing rules return a path that starts with a slash./, error.message
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
describe 'Nanoc3::Site#initialize' do
|
140
|
+
|
141
|
+
include Nanoc3::TestHelpers
|
142
|
+
|
143
|
+
it 'should merge default config' do
|
144
|
+
site = Nanoc3::Site.new(:foo => 'bar')
|
145
|
+
site.config[:foo].must_equal 'bar'
|
146
|
+
site.config[:output_dir].must_equal 'output'
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'should not raise under normal circumstances' do
|
150
|
+
Nanoc3::Site.new({})
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'should not raise for non-existant output directory' do
|
154
|
+
Nanoc3::Site.new(:output_dir => 'fklsdhailfdjalghlkasdflhagjskajdf')
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'should not raise for unknown data sources' do
|
158
|
+
proc do
|
159
|
+
Nanoc3::Site.new(:data_source => 'fklsdhailfdjalghlkasdflhagjskajdf')
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
describe 'Nanoc3::Site#load_data' do
|
166
|
+
|
167
|
+
include Nanoc3::TestHelpers
|
168
|
+
|
169
|
+
it 'should load the data source' do
|
170
|
+
site = Nanoc3::Site.new({})
|
171
|
+
|
172
|
+
# Mock data sources
|
173
|
+
data_sources = [ mock, mock, mock ]
|
174
|
+
data_sources.each { |ds| ds.expects(:use) }
|
175
|
+
data_sources.each { |ds| ds.expects(:unuse) }
|
176
|
+
site.stubs(:data_sources).returns(data_sources)
|
177
|
+
|
178
|
+
# Mock load_* methods
|
179
|
+
site.stubs(:load_code_snippets).with(false)
|
180
|
+
site.stubs(:load_rules)
|
181
|
+
site.stubs(:load_items)
|
182
|
+
site.stubs(:load_layouts)
|
183
|
+
site.expects(:link_everything_to_site)
|
184
|
+
site.expects(:setup_child_parent_links).times(2)
|
185
|
+
site.expects(:build_reps)
|
186
|
+
site.expects(:route_reps)
|
187
|
+
|
188
|
+
# Load data
|
189
|
+
site.load_data
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'should call the preprocessor' do
|
193
|
+
site = Nanoc3::Site.new({})
|
194
|
+
site.instance_eval do
|
195
|
+
@items_loaded = true
|
196
|
+
@layouts_loaded = true
|
197
|
+
end
|
198
|
+
|
199
|
+
# Mock data sources
|
200
|
+
data_sources = [ mock, mock, mock ]
|
201
|
+
data_sources.each { |ds| ds.expects(:use) }
|
202
|
+
data_sources.each { |ds| ds.expects(:unuse) }
|
203
|
+
site.stubs(:data_sources).returns(data_sources)
|
204
|
+
|
205
|
+
# Mock load_* methods
|
206
|
+
site.expects(:load_code_snippets).with(false)
|
207
|
+
site.expects(:load_rules)
|
208
|
+
site.expects(:load_items)
|
209
|
+
site.expects(:load_layouts)
|
210
|
+
site.expects(:link_everything_to_site)
|
211
|
+
site.expects(:setup_child_parent_links).times(2)
|
212
|
+
site.expects(:build_reps)
|
213
|
+
site.expects(:route_reps)
|
214
|
+
|
215
|
+
# Mock preprocessor
|
216
|
+
preprocessor = lambda { |*x| }
|
217
|
+
site.expects(:preprocessor).times(2).returns(preprocessor)
|
218
|
+
|
219
|
+
# Load data
|
220
|
+
site.load_data
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'should call load_* methods' do
|
224
|
+
site = Nanoc3::Site.new({})
|
225
|
+
|
226
|
+
# Mock data sources
|
227
|
+
data_sources = [ mock, mock, mock ]
|
228
|
+
data_sources.each { |ds| ds.expects(:use) }
|
229
|
+
data_sources.each { |ds| ds.expects(:unuse) }
|
230
|
+
site.stubs(:data_sources).returns(data_sources)
|
231
|
+
|
232
|
+
# Mock load_* methods
|
233
|
+
site.expects(:load_code_snippets).with(false)
|
234
|
+
site.expects(:load_rules)
|
235
|
+
site.expects(:load_items)
|
236
|
+
site.expects(:load_layouts)
|
237
|
+
site.expects(:link_everything_to_site)
|
238
|
+
site.expects(:setup_child_parent_links).times(2)
|
239
|
+
site.expects(:build_reps)
|
240
|
+
site.expects(:route_reps)
|
241
|
+
|
242
|
+
# Load data
|
243
|
+
site.load_data
|
244
|
+
end
|
245
|
+
|
246
|
+
it 'should not load data twice if not forced' do
|
247
|
+
site = Nanoc3::Site.new({})
|
248
|
+
|
249
|
+
# Mock data sources
|
250
|
+
data_sources = [ mock, mock, mock ]
|
251
|
+
data_sources.each { |ds| ds.expects(:use) }
|
252
|
+
data_sources.each { |ds| ds.expects(:unuse) }
|
253
|
+
site.stubs(:data_sources).returns(data_sources)
|
254
|
+
|
255
|
+
# Mock load_* methods
|
256
|
+
site.expects(:load_code_snippets).with(false).once
|
257
|
+
site.expects(:load_rules)
|
258
|
+
site.expects(:load_items).once
|
259
|
+
site.expects(:load_layouts).once
|
260
|
+
site.expects(:link_everything_to_site)
|
261
|
+
site.expects(:setup_child_parent_links).times(2)
|
262
|
+
site.expects(:build_reps).once
|
263
|
+
site.expects(:route_reps).once
|
264
|
+
|
265
|
+
# Load data twice
|
266
|
+
site.load_data
|
267
|
+
site.load_data
|
268
|
+
end
|
269
|
+
|
270
|
+
it 'should load data twice if forced' do
|
271
|
+
site = Nanoc3::Site.new({})
|
272
|
+
|
273
|
+
# Mock data sources
|
274
|
+
data_sources = [ mock, mock, mock ]
|
275
|
+
data_sources.each { |ds| ds.expects(:use).times(2) }
|
276
|
+
data_sources.each { |ds| ds.expects(:unuse).times(2) }
|
277
|
+
site.stubs(:data_sources).returns(data_sources)
|
278
|
+
|
279
|
+
# Mock load_* methods
|
280
|
+
site.expects(:load_code_snippets).with(true).times(2)
|
281
|
+
site.expects(:load_rules).times(2)
|
282
|
+
site.expects(:load_items).times(2)
|
283
|
+
site.expects(:load_layouts).times(2)
|
284
|
+
site.expects(:link_everything_to_site).times(2)
|
285
|
+
site.expects(:setup_child_parent_links).times(2*2)
|
286
|
+
site.expects(:build_reps).times(2)
|
287
|
+
site.expects(:route_reps).times(2)
|
288
|
+
|
289
|
+
# Load data twice
|
290
|
+
site.load_data(true)
|
291
|
+
site.load_data(true)
|
292
|
+
end
|
293
|
+
|
294
|
+
end
|
295
|
+
|
296
|
+
describe 'Nanoc3::Site#code_snippets' do
|
297
|
+
|
298
|
+
include Nanoc3::TestHelpers
|
299
|
+
|
300
|
+
it 'should raise when data is not loaded yet' do
|
301
|
+
site = Nanoc3::Site.new({})
|
302
|
+
proc do
|
303
|
+
site.code_snippets
|
304
|
+
end.must_raise Nanoc3::Errors::DataNotYetAvailable
|
305
|
+
end
|
306
|
+
|
307
|
+
end
|
308
|
+
|
309
|
+
describe 'Nanoc3::Site#items' do
|
310
|
+
|
311
|
+
include Nanoc3::TestHelpers
|
312
|
+
|
313
|
+
it 'should raise when data is not loaded yet' do
|
314
|
+
site = Nanoc3::Site.new({})
|
315
|
+
proc do
|
316
|
+
site.items
|
317
|
+
end.must_raise Nanoc3::Errors::DataNotYetAvailable
|
318
|
+
end
|
319
|
+
|
320
|
+
end
|
321
|
+
|
322
|
+
describe 'Nanoc3::Site#layouts' do
|
323
|
+
|
324
|
+
include Nanoc3::TestHelpers
|
325
|
+
|
326
|
+
it 'should raise when data is not loaded yet' do
|
327
|
+
site = Nanoc3::Site.new({})
|
328
|
+
proc do
|
329
|
+
site.layouts
|
330
|
+
end.must_raise Nanoc3::Errors::DataNotYetAvailable
|
331
|
+
end
|
332
|
+
|
333
|
+
end
|
334
|
+
|
335
|
+
describe 'Nanoc3::Site#compiler' do
|
336
|
+
|
337
|
+
include Nanoc3::TestHelpers
|
338
|
+
|
339
|
+
it 'should not raise under normal circumstances' do
|
340
|
+
site = Nanoc3::Site.new({})
|
341
|
+
site.compiler
|
342
|
+
end
|
343
|
+
|
344
|
+
end
|
345
|
+
|
346
|
+
describe 'Nanoc3::Site#data_sources' do
|
347
|
+
|
348
|
+
include Nanoc3::TestHelpers
|
349
|
+
|
350
|
+
it 'should not raise for known data sources' do
|
351
|
+
site = Nanoc3::Site.new({})
|
352
|
+
site.data_sources
|
353
|
+
end
|
354
|
+
|
355
|
+
it 'should raise for unknown data sources' do
|
356
|
+
proc do
|
357
|
+
site = Nanoc3::Site.new(
|
358
|
+
:data_sources => [
|
359
|
+
{ :type => 'fklsdhailfdjalghlkasdflhagjskajdf' }
|
360
|
+
]
|
361
|
+
)
|
362
|
+
site.data_sources
|
363
|
+
end.must_raise Nanoc3::Errors::UnknownDataSource
|
364
|
+
end
|
365
|
+
|
366
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/helper'
|
4
|
+
|
5
|
+
class Nanoc3::CLI::Commands::CreateLayoutTest < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
include Nanoc3::TestHelpers
|
8
|
+
|
9
|
+
def test_can_compile_new_layout
|
10
|
+
Nanoc3::CLI::Base.new.run([ 'create_site', 'foo' ])
|
11
|
+
|
12
|
+
FileUtils.cd('foo') do
|
13
|
+
# Create new layout
|
14
|
+
Nanoc3::CLI::Base.new.run([ 'create_layout', 'moo' ])
|
15
|
+
|
16
|
+
# Makes rules use new layout
|
17
|
+
rules_raw = File.read('Rules')
|
18
|
+
File.open('Rules', 'w') do |io|
|
19
|
+
io.write rules_raw.sub("layout 'default'", "layout 'moo'")
|
20
|
+
end
|
21
|
+
|
22
|
+
site = Nanoc3::Site.new('.')
|
23
|
+
site.load_data
|
24
|
+
site.compiler.run
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/helper'
|
4
|
+
|
5
|
+
class Nanoc3::CLI::Commands::CreateSiteTest < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
include Nanoc3::TestHelpers
|
8
|
+
|
9
|
+
def test_create_site_with_existing_name
|
10
|
+
Nanoc3::CLI::Base.new.run([ 'create_site', 'foo' ])
|
11
|
+
assert_raises(SystemExit) { Nanoc3::CLI::Base.new.run([ 'create_site', 'foo' ]) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_can_compile_new_site
|
15
|
+
Nanoc3::CLI::Base.new.run([ 'create_site', 'foo' ])
|
16
|
+
|
17
|
+
FileUtils.cd('foo') do
|
18
|
+
site = Nanoc3::Site.new('.')
|
19
|
+
site.load_data
|
20
|
+
site.compiler.run
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|