mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-06 13:18:14 +08:00
28 lines
845 B
Ruby
28 lines
845 B
Ruby
# frozen_string_literal: true
|
|
|
|
module DiscourseAi
|
|
module Evals
|
|
module RunnerSpecHelper
|
|
def stub_runner_bot(
|
|
agent: instance_double(DiscourseAi::Agents::Agent, response_format: nil),
|
|
response: "ok",
|
|
&custom_block
|
|
)
|
|
bot_double = instance_double(DiscourseAi::Agents::Bot, agent: agent)
|
|
|
|
allow(AiAgent).to receive(:find_by_id_from_cache).and_return(nil)
|
|
allow(DiscourseAi::Agents::Bot).to receive(:as).and_return(bot_double)
|
|
|
|
if block_given?
|
|
allow(bot_double).to receive(:reply) { |*_, &blk| custom_block.call(blk) }
|
|
else
|
|
allow(bot_double).to receive(:reply) { |_ctx, &blk| blk.call(response, nil, nil) }
|
|
end
|
|
|
|
bot_double
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
RSpec.configure { |config| config.include DiscourseAi::Evals::RunnerSpecHelper }
|