|
96 | 96 |
|
97 | 97 | it "outputs the answer as JSON to stdout" do |
98 | 98 | answer = build(:answer) |
| 99 | + question = "What is the current VAT rate?" |
| 100 | + answer_strategy = "claude_structured_answer" |
99 | 101 |
|
100 | 102 | allow(AnswerComposition::Composer) |
101 | 103 | .to receive(:call) |
102 | 104 | .with(an_instance_of(Question)) |
103 | 105 | .and_return(answer) |
104 | 106 |
|
105 | | - ClimateControl.modify(QUESTION: "What is the current VAT rate?") do |
| 107 | + ClimateControl.modify(QUESTION: question) do |
106 | 108 | answer_json = { message: answer.message }.to_json |
107 | | - expect { Rake::Task[task_name].invoke } |
| 109 | + expect { Rake::Task[task_name].invoke(answer_strategy) } |
108 | 110 | .to output("#{answer_json}\n").to_stdout |
109 | 111 | end |
| 112 | + |
| 113 | + expect(AnswerComposition::Composer) |
| 114 | + .to have_received(:call) |
| 115 | + .with(an_object_having_attributes(message: question, |
| 116 | + conversation: an_instance_of(Conversation), |
| 117 | + answer_strategy: answer_strategy)) |
| 118 | + end |
| 119 | + |
| 120 | + it "warns when an answer_strategy argument isn't given" do |
| 121 | + answer = build(:answer) |
| 122 | + question = "What is the current VAT rate?" |
| 123 | + default_answer_strategy = Rails.configuration.answer_strategy |
| 124 | + |
| 125 | + allow(AnswerComposition::Composer) |
| 126 | + .to receive(:call) |
| 127 | + .with(an_instance_of(Question)) |
| 128 | + .and_return(answer) |
| 129 | + |
| 130 | + ClimateControl.modify(QUESTION: question) do |
| 131 | + expect { Rake::Task[task_name].invoke } |
| 132 | + .to output.to_stdout |
| 133 | + .and output("No answer strategy argument provided, using #{default_answer_strategy}\n").to_stderr |
| 134 | + end |
| 135 | + |
| 136 | + expect(AnswerComposition::Composer) |
| 137 | + .to have_received(:call) |
| 138 | + .with(an_object_having_attributes(message: question, |
| 139 | + conversation: an_instance_of(Conversation), |
| 140 | + answer_strategy: default_answer_strategy)) |
110 | 141 | end |
111 | 142 | end |
112 | 143 |
|
|
0 commit comments