-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdescription_from_code_generator_spec.rb
104 lines (80 loc) · 3.18 KB
/
description_from_code_generator_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
require "spec_helper"
require "generators/examples/description_from_code_generator"
RSpec.describe DescriptionFromCodeGenerator do
def generate(code)
described_class.new(code: code).generate
end
context "Claude" do
before do
Sublayer.configuration.ai_provider = Sublayer::Providers::Claude
Sublayer.configuration.ai_model = "claude-3-haiku-20240307"
end
it "generates description from hello world code" do
VCR.use_cassette("claude/generators/description_from_code_generator/hello_world") do
code = %q(#!/usr/bin/env ruby
require 'optparse'
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: hello.rb [options]"
opts.on("-w", "--who PERSON", "Name of the person to greet") do |person|
options[:who] = person
end
end.parse!
who = options[:who] || "world"
puts "Hello, #{who}!")
description = generate(code)
expect(description).to be_a(String)
expect(description.length).to be > 0
end
end
end
context "OpenAI" do
before do
Sublayer.configuration.ai_provider = Sublayer::Providers::OpenAI
Sublayer.configuration.ai_model = "gpt-4-turbo"
end
it "generates description from hello world code" do
VCR.use_cassette("openai/generators/description_from_code_generator/hello_world") do
code = %q(#!/usr/bin/env ruby
require 'optparse'
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: hello.rb [options]"
opts.on("-w", "--who PERSON", "Name of the person to greet") do |person|
options[:who] = person
end
end.parse!
who = options[:who] || "world"
puts "Hello, #{who}!")
description = generate(code)
expect(description.strip).to eq <<~DESCRIPTION.strip
The provided Ruby script is a simple command-line application that greets a user. It starts by including the option parser library, then sets up command-line options allowing the user to specify a name with the '-w' or '--who' switch. In absence of this switch, it defaults to greeting 'world'. Finally, it outputs a greeting message to the terminal, addressing either the specified name or 'world' if no name was given.
DESCRIPTION
end
end
end
context "Gemini" do
before do
Sublayer.configuration.ai_provider = Sublayer::Providers::Gemini
Sublayer.configuration.ai_model = "gemini-1.5-pro-latest"
end
it "generates description from hello world code" do
VCR.use_cassette("gemini/generators/description_from_code_generator/hello_world") do
code = %q(#!/usr/bin/env ruby
require 'optparse'
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: hello.rb [options]"
opts.on("-w", "--who PERSON", "Name of the person to greet") do |person|
options[:who] = person
end
end.parse!
who = options[:who] || "world"
puts "Hello, #{who}!")
description = generate(code)
expect(description).to be_a(String)
expect(description.length).to be > 0
end
end
end
end