Module: RubyLLM::Contract::RSpec::Helpers
- Defined in:
- lib/ruby_llm/contract/rspec/helpers.rb
Instance Method Summary collapse
-
#stub_all_steps(response: nil, responses: nil) ⇒ Object
Set a global test adapter for ALL steps.
-
#stub_step(step_class, response: nil, responses: nil) ⇒ Object
Stub a step to return a canned response without API calls.
Instance Method Details
#stub_all_steps(response: nil, responses: nil) ⇒ Object
Set a global test adapter for ALL steps.
stub_all_steps(response: { default: true })
27 28 29 30 |
# File 'lib/ruby_llm/contract/rspec/helpers.rb', line 27 def stub_all_steps(response: nil, responses: nil) adapter = build_test_adapter(response: response, responses: responses) RubyLLM::Contract.configure { |c| c.default_adapter = adapter } end |
#stub_step(step_class, response: nil, responses: nil) ⇒ Object
Stub a step to return a canned response without API calls.
stub_step(ClassifyTicket, response: { priority: "high" })
result = ClassifyTicket.run("test")
result.parsed_output # => {priority: "high"}
Only affects the specified step — other steps are not affected.
15 16 17 18 19 20 21 |
# File 'lib/ruby_llm/contract/rspec/helpers.rb', line 15 def stub_step(step_class, response: nil, responses: nil) adapter = build_test_adapter(response: response, responses: responses) allow(step_class).to receive(:run).and_wrap_original do |original, input, **kwargs| context = (kwargs[:context] || {}).merge(adapter: adapter) original.call(input, context: context) end end |