Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/fbe/conclude.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,18 @@ def on(query)
# @raise [Fbe::Error] If +what+ or +details+ is in the list, since +draw+ sets them
def follow(props)
raise(Fbe::Error, 'Follow is already set') unless @follows.nil?
list = props.strip.split.compact
list =
case props
when String
props.strip.split
when Array
unless props.all? { |prop| prop.is_a?(String) }
raise(Fbe::Error, 'Follow expects an Array of Strings')
end
props.map(&:strip).reject(&:empty?)
else
raise(Fbe::Error, 'Follow expects a String or an Array of Strings')
end
bad = list & %w[what details]
raise(Fbe::Error, "Can't follow #{bad.join(' and ')}, the judge sets it in the new fact") unless bad.empty?
@follows = list
Expand Down
15 changes: 14 additions & 1 deletion test/fbe/test_conclude.rb
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def test_follow_multivalued
Fbe.conclude(judge: 'judge-follow') do
quota_unaware
on('(exists foo)')
follow('tags')
follow(%w[tags])
draw do |n, _prev|
n.processed = 'yes'
'Some long description that satisfies the twenty five chars minimum.'
Expand Down Expand Up @@ -426,6 +426,19 @@ def test_follow_raises_on_second_call
end
end

def test_follow_rejects_non_string_properties
fb = Factbase.new
error =
assert_raises(Fbe::Error) do
Fbe.conclude(fb:, judge: 'judge-follow', options: Judges::Options.new, global: {}, loog: Loog::NULL) do
quota_unaware
on('(exists foo)')
follow(['tags', 42])
end
end
assert_includes(error.message, 'Array of Strings')
end

def test_follow_refuses_properties_set_by_judge
%w[what details].each do |prop|
fb = Factbase.new
Expand Down
Loading