Skip to content

Commit

Permalink
Raise proper error when no layout rule memory exists
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdefreyne committed Jul 24, 2016
1 parent 9881c6b commit 5b2e9a6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 11 additions & 1 deletion lib/nanoc/rule_dsl/rule_memory_calculator.rb
Expand Up @@ -12,6 +12,12 @@ def initialize(obj)
end
end

class NoRuleMemoryForLayoutException < ::Nanoc::Error
def initialize(layout)
super("There is no layout rule specified for #{layout.inspect}")
end
end

# @api private
attr_accessor :rules_collection

Expand Down Expand Up @@ -83,7 +89,11 @@ def new_rule_memory_for_rep(rep)
# @return [Nanoc::Int::RuleMemory]
def new_rule_memory_for_layout(layout)
res = @rules_collection.filter_for_layout(layout)
# FIXME: what if res is nil?

unless res
raise NoRuleMemoryForLayoutException.new(layout)
end

Nanoc::Int::RuleMemory.new(layout).tap do |rm|
rm.add_filter(res[0], res[1])
end
Expand Down
5 changes: 4 additions & 1 deletion spec/nanoc/rule_dsl/rule_memory_calculator_spec.rb
Expand Up @@ -80,7 +80,10 @@
let(:obj) { Nanoc::Int::Layout.new('content', {}, '/default.erb') }

context 'no rules exist' do
# FIXME: This case is broken
it 'raises error' do
expect { subject }.to raise_error(
Nanoc::RuleDSL::RuleMemoryCalculator::NoRuleMemoryForLayoutException)
end
end

context 'rule exists' do
Expand Down

0 comments on commit 5b2e9a6

Please sign in to comment.