ruby_llm-test 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a0eae1a8d1ab14addc132333aa7f6baef9695e8a13c0160ee7ff85b5114c2a9
4
- data.tar.gz: a45059e4ae9b0f182f791b43df7905b25a11d38d7a3d87878d2e6f0ad8a4421f
3
+ metadata.gz: ef753ca266479d9530fb44f0660cb2292bc916c2c949376c65686488bd41f5d9
4
+ data.tar.gz: f96175266a8866d9038b529b37ae0f099f1b20cdf677f591ab36acc941e566bb
5
5
  SHA512:
6
- metadata.gz: 4504b45b39bfea4799804b39f14f54560650646269eded1b0f3a50f019cf803f09a9bc04a82c7b4a66ddf88e345843c8be4bd4396655c4e7d11051bcafda200b
7
- data.tar.gz: 7583a4bc1e8b89d0c2d358eb3d90956205ca3d622d06907045e2e48827c3cd7b9444433876e84af94b81d60ea1e416c872f2d81e2c7aaef063ce1d61d57f1af5
6
+ metadata.gz: e58becb7a4ae7b1d2248746f8aad685aa5a382307fe8c57887d0b6d2c170e35ffc4e97ae095cc0601ebf17e50de3374cab6060619c6ba57adfed4c85f5be576b
7
+ data.tar.gz: 76456e9ec3ed46ec76eafbae1bdebe6fd9598cce423f527c505028a43520dfa01c538341fd28c71fddfd70f36d7c47410b2cfb2fb8425fa6ba0abe6ccc6aac55
data/README.md CHANGED
@@ -1,6 +1,14 @@
1
+ [![Gem Version](https://badge.fury.io/rb/ruby_llm-test.svg)](https://badge.fury.io/rb/ruby_llm-test)
2
+ [![Tests](https://github.com/RockSolt/ruby_llm-test/actions/workflows/test.yml/badge.svg)](https://github.com/RockSolt/ruby_llm-test/actions/workflows/test.yml)
3
+ [![RuboCop](https://github.com/RockSolt/ruby_llm-test/actions/workflows/rubocop.yml/badge.svg)](https://github.com/RockSolt/ruby_llm-test/actions/workflows/rubocop.yml)
4
+
1
5
  # RubyLLM::Test
2
6
 
3
- This gem provides testing utilities for RubyLLM, a Ruby library for working with large language models (LLMs). It enables calls to LLMs to be stubbed so that the surrounding application logic can be tested without making actual calls to the LLM. This is particularly useful for testing code that interacts with LLMs, as it allows developers to simulate responses from the LLM without incurring the cost, latency, or randomness of real API calls.
7
+ How do you test your business logic when it interacts with large language models (LLMs)? From a testing point of view, an LLM is just an external system. To keep tests fast and consistent, pick a boundary then stub or mock the external system.
8
+
9
+ Part of the appeal of the RubyLLM library is that code using it does not need to know the specifics of provider APIs. The RubyLLM::Test gem brings the same benefit to your tests. No API or provider-specific knowledge is required to stub calls.
10
+
11
+ Simple stubs make for simple tests. Keep your tests fast, consistent, and thorough with RubyLLM::Test!
4
12
 
5
13
  ```ruby
6
14
  RubyLLM::Test.stub_response("Outlook good")
@@ -29,7 +37,7 @@ Or install it yourself as:
29
37
 
30
38
  ## Usage
31
39
 
32
- Add the following lines to your `spec/spec_helper.rb` or `test/test_helper.rb`:
40
+ Add the following lines to your `spec_helper.rb` or `test_helper.rb`:
33
41
 
34
42
  ```ruby
35
43
  require 'ruby_llm/test'
@@ -43,21 +51,22 @@ Then, in your tests, you can use the `stub_response` method to stub responses fr
43
51
  it 'returns a stubbed response' do
44
52
  RubyLLM::Test.stub_response('Hello, world!')
45
53
 
46
- response = MyLLMClient.call('Hello?')
47
- expect(response).to eq('Hello, world!')
54
+ response = RubyLLM.chat.ask 'Hello?'
55
+ expect(response.content).to eq('Hello, world!')
48
56
  end
49
57
  ```
50
58
 
51
- If you make multiple calls to the LLM, you can call `stub_response` more than once or use method `stub_responses` to stub multiple responses at once. For example:
59
+ If you make multiple calls to the LLM, you can call `stub_response` more than once or use the `stub_responses` method to stub multiple responses at once. For example:
52
60
 
53
61
  ```ruby
54
62
  it 'returns multiple stubbed responses' do
55
- RubyLLM::Test.stub_responses('Hello, world!', 'How are you?')
56
- response1 = MyLLMClient.call('Hello?')
57
- response2 = MyLLMClient.call('How are you?')
63
+ RubyLLM::Test.stub_responses('Blue.', 'No, yellow.')
64
+ chat = RubyLLM.chat
65
+ response1 = chat.ask 'What is your favorite color?'
66
+ response2 = chat.ask 'Are you sure?'
58
67
 
59
- expect(response1).to eq('Hello, world!')
60
- expect(response2).to eq('How are you?')
68
+ expect(response1.content).to eq('Blue.')
69
+ expect(response2.content).to eq('No, yellow.')
61
70
  end
62
71
  ```
63
72
 
@@ -70,7 +79,7 @@ it 'returns a stubbed message' do
70
79
  message = RubyLLM::Message.new(role: :assistant, content: 'Hello, world!')
71
80
  RubyLLM::Test.stub_response(message)
72
81
 
73
- response = MyLLMClient.call('Hello?')
82
+ response = RubyLLM.chat.ask 'Hello?'
74
83
  expect(response).to eq(message)
75
84
  end
76
85
  ```
@@ -84,14 +93,14 @@ it 'returns a stubbed JSON message' do
84
93
  hash = { key: 'value' }
85
94
  RubyLLM::Test.stub_response(hash)
86
95
 
87
- response = MyLLMClient.call('Hello?')
96
+ response = RubyLLM.chat.ask 'Hello?'
88
97
  expect(response.content).to eq(hash.to_json)
89
98
  end
90
99
  ```
91
100
 
92
101
  ### Resetting Stubs
93
102
 
94
- Make sure to reset stubs after each test to avoid interference before or between tests.
103
+ Reset stubs before each test to ensure a clean slate.
95
104
 
96
105
  ```ruby
97
106
  RubyLLM::Test.reset
@@ -102,10 +111,9 @@ RubyLLM::Test.reset
102
111
  You can also stub responses in a block, which handles the setup and teardown of stubs automatically. For example:
103
112
 
104
113
  ```ruby
105
-
106
114
  RubyLLM::Test.with_responses('Hello, world!') do
107
- response = MyLLMClient.call('Hello?')
108
- expect(response).to eq('Hello, world!')
115
+ response = RubyLLM.chat.ask 'Hello?'
116
+ expect(response.content).to eq('Hello, world!')
109
117
  end
110
118
  ```
111
119
 
@@ -11,6 +11,12 @@ module RubyLLM
11
11
  @test_harness = test_harness
12
12
  end
13
13
 
14
+ # There are a number of cases that access `provider.class.display_name`, which avoids the delegation. Adding
15
+ # dummy stub for this. TBD if this needs to be more sophisticated in the future.
16
+ def self.display_name
17
+ "TestProvider"
18
+ end
19
+
14
20
  def complete(...)
15
21
  parameters = CompleteParameters.capture_from(__getobj__, ...)
16
22
  @test_harness.record_request(parameters)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RubyLLM
4
4
  module Test
5
- VERSION = "0.2.0"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_llm-test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Kummer
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-04-25 00:00:00.000000000 Z
10
+ date: 2026-09-08 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: ruby_llm