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 +4 -4
- data/README.md +24 -16
- data/lib/ruby_llm/test/test_provider.rb +6 -0
- data/lib/ruby_llm/test/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ef753ca266479d9530fb44f0660cb2292bc916c2c949376c65686488bd41f5d9
|
|
4
|
+
data.tar.gz: f96175266a8866d9038b529b37ae0f099f1b20cdf677f591ab36acc941e566bb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e58becb7a4ae7b1d2248746f8aad685aa5a382307fe8c57887d0b6d2c170e35ffc4e97ae095cc0601ebf17e50de3374cab6060619c6ba57adfed4c85f5be576b
|
|
7
|
+
data.tar.gz: 76456e9ec3ed46ec76eafbae1bdebe6fd9598cce423f527c505028a43520dfa01c538341fd28c71fddfd70f36d7c47410b2cfb2fb8425fa6ba0abe6ccc6aac55
|
data/README.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
[](https://badge.fury.io/rb/ruby_llm-test)
|
|
2
|
+
[](https://github.com/RockSolt/ruby_llm-test/actions/workflows/test.yml)
|
|
3
|
+
[](https://github.com/RockSolt/ruby_llm-test/actions/workflows/rubocop.yml)
|
|
4
|
+
|
|
1
5
|
# RubyLLM::Test
|
|
2
6
|
|
|
3
|
-
|
|
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 `
|
|
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 =
|
|
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
|
|
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('
|
|
56
|
-
|
|
57
|
-
|
|
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('
|
|
60
|
-
expect(response2).to eq('
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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 =
|
|
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)
|
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.
|
|
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-
|
|
10
|
+
date: 2026-09-08 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: ruby_llm
|