ruby_raider 0.8.6 → 0.8.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/integration.yml +0 -2
- data/.github/workflows/push_gem.yml +37 -0
- data/.github/workflows/system.yml +0 -2
- data/.gitignore +1 -2
- data/.rubocop.yml +1 -1
- data/README.md +26 -22
- data/lib/commands/scaffolding_commands.rb +34 -36
- data/lib/generators/automation/templates/partials/initialize_selector.tt +7 -0
- data/lib/generators/automation/templates/partials/selenium_login.tt +1 -0
- data/lib/generators/generator.rb +6 -1
- data/lib/generators/invoke_generators.rb +4 -2
- data/lib/generators/menu_generator.rb +21 -6
- data/lib/generators/rspec/rspec_generator.rb +6 -0
- data/lib/generators/rspec/templates/spec.tt +29 -0
- data/lib/generators/templates/common/gemfile.tt +4 -0
- data/lib/generators/templates/common/rakefile.tt +4 -8
- data/lib/generators/templates/common/read_me.tt +44 -49
- data/lib/generators/templates/helpers/driver_helper.tt +8 -1
- data/lib/generators/templates/helpers/partials/driver_and_options.tt +8 -2
- data/lib/generators/templates/helpers/spec_helper.tt +3 -0
- data/lib/ruby_raider.rb +3 -9
- data/lib/scaffolding/scaffolding.rb +14 -6
- data/lib/scaffolding/templates/feature.tt +1 -1
- data/lib/scaffolding/templates/page_object.tt +2 -2
- data/lib/scaffolding/templates/spec.tt +2 -3
- data/lib/scaffolding/templates/steps.tt +12 -0
- data/lib/version +1 -0
- data/ruby_raider.gemspec +1 -2
- data/spec/integration/commands/scaffolding_commands_spec.rb +14 -4
- data/spec/spec_helper.rb +1 -1
- metadata +6 -20
- data/lib/commands/open_ai_commands.rb +0 -85
- data/lib/open_ai/open_ai.rb +0 -67
- data/spec/integration/commands/open_ai_commands_spec.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3fe29e41e6594c06a03da48fdd3481af4706a6cf4e5c344bb3f78db1e48cec8
|
4
|
+
data.tar.gz: 3b53ca1421e02300c0edb463cd4ca7c373992afdb41caa70318fc9df213fec90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b684e1ebcca1611a9593f3b77039bfd66e21656e6746f6e31a5240f9fdb032527e29f63d5aab3caf770c472c4c8810f50c587a61375568d6db4d93258454c49
|
7
|
+
data.tar.gz: da691e9de5d1128eb1aa0d99fbbde682afb70d0be3bf3d29a75b88bbc2af7c771b19a1aa29295fa4c1f5bd8d56082f7659284aff7484c6f284d6891ae21ff9c9
|
@@ -0,0 +1,37 @@
|
|
1
|
+
name: Push Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
workflow_dispatch:
|
5
|
+
|
6
|
+
permissions:
|
7
|
+
contents: read
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
push:
|
11
|
+
if: github.repository == 'RubyRaider/ruby_raider'
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
|
14
|
+
environment:
|
15
|
+
name: rubygems.org
|
16
|
+
url: https://rubygems.org/gems/ruby_raider
|
17
|
+
|
18
|
+
permissions:
|
19
|
+
contents: write
|
20
|
+
id-token: write
|
21
|
+
|
22
|
+
steps:
|
23
|
+
# Set up
|
24
|
+
- name: Harden Runner
|
25
|
+
uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1
|
26
|
+
with:
|
27
|
+
egress-policy: audit
|
28
|
+
|
29
|
+
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
|
30
|
+
- name: Set up Ruby
|
31
|
+
uses: ruby/setup-ruby@cacc9f1c0b3f4eb8a16a6bb0ed10897b43b9de49 # v1.176.0
|
32
|
+
with:
|
33
|
+
bundler-cache: true
|
34
|
+
ruby-version: ruby
|
35
|
+
|
36
|
+
# Release
|
37
|
+
- uses: rubygems/release-gem@612653d273a73bdae1df8453e090060bb4db5f31 # v1
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -88,10 +88,9 @@ Select the ones you will like to work with.
|
|
88
88
|
|
89
89
|
```ruby
|
90
90
|
Commands:
|
91
|
-
raider generate # Provides access to all the
|
91
|
+
raider generate # Provides access to all the scaffolding commands
|
92
92
|
raider help [COMMAND] # Describe available commands or one specific command
|
93
93
|
raider new [PROJECT_NAME] # Creates a new framework based on settings picked
|
94
|
-
raider open_ai # Provides access to all the open ai commands
|
95
94
|
raider utility # Provides access to all the utility commands
|
96
95
|
raider version # It shows the version of Ruby Raider you are currently using
|
97
96
|
```
|
@@ -100,33 +99,38 @@ All the basic commands have their corresponding shortcut:
|
|
100
99
|
|
101
100
|
* g for generate
|
102
101
|
* n for new
|
103
|
-
* o for open_ai
|
104
102
|
* u for utility
|
105
103
|
* v for version
|
106
104
|
|
105
|
+
### Scaffolding Commands
|
106
|
+
Ruby Raider also supports scaffolding:
|
107
|
+
|
108
|
+
* To create a new page object you do: ```raider g page [PAGE_NAME]```
|
109
|
+
* To create a new spec you do: ```raider g spec [SPEC_NAME]```
|
110
|
+
* To create a new feature you do: ```raider g feature [FEATURE_NAME]```
|
111
|
+
* To create a new steps definition you do: ```raider g steps [STEPS_NAME]```
|
112
|
+
* To create both a page/spec or a page/feature/steps you do: ```raider g scaffold [SCAFFOLD_NAME]```
|
113
|
+
|
114
|
+
It's possible to add the option --path or -p if you want to specify where to create your features, pages, helpers and
|
115
|
+
specs.
|
116
|
+
|
117
|
+
If you want to set the default path for the creation of your features, helpers and specs:
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
raider u path [PATH_NAME] - -feature or -f
|
121
|
+
raider u path [PATH_NAME] - -spec or -s
|
122
|
+
raider u path [PATH_NAME] - -helper or -h
|
123
|
+
```
|
124
|
+
|
125
|
+
If you don't specify an option, path will assume you want to change the default path for pages.
|
126
|
+
|
127
|
+
|
107
128
|
### Appium Server Command
|
108
129
|
To initialise Appium server run this command:
|
109
130
|
```ruby
|
110
131
|
raider u start_appium
|
111
132
|
```
|
112
133
|
|
113
|
-
###
|
134
|
+
### Sponsors
|
114
135
|
|
115
|
-
|
116
|
-
# Will print the result of the request on the terminal
|
117
|
-
raider o make [REQUEST]
|
118
|
-
# Will create a file with the result of your request as content
|
119
|
-
raider o make [REQUEST] - -path or -p [PATH]
|
120
|
-
# Will input the content of the chosen file into open ai and will edit it based on the result
|
121
|
-
raider o make [PATH_NAME] - -edit or -e [FILE_PATH]
|
122
|
-
# Creates a cucumber file and uses it to input into open ai and create a steps file
|
123
|
-
# The prompt is required
|
124
|
-
raider o cucumber [NAME] - -prompt or -p [PROMPT]
|
125
|
-
# Creates a cucumber step definitions file based on an scenario file
|
126
|
-
raider open_ai steps [NAME]
|
127
|
-
Options :
|
128
|
-
-p, [--path = PATH] # The path where your steps will be created
|
129
|
-
-pr, [--prompt = PROMPT] # This will create the selected steps based on your prompt using open ai
|
130
|
-
-i, [--input = INPUT] # It uses a file as input to create the steps
|
131
|
-
|
132
|
-
```
|
136
|
+
This project is tested with BrowserStack.
|
@@ -7,6 +7,7 @@ require_relative '../commands/utility_commands'
|
|
7
7
|
|
8
8
|
# :reek:FeatureEnvy { enabled: false }
|
9
9
|
# :reek:UtilityFunction { enabled: false }
|
10
|
+
# :reek:RepeatedConditional { enabled: false }
|
10
11
|
class ScaffoldingCommands < Thor
|
11
12
|
desc 'page [PAGE_NAME]', 'Creates a new page object'
|
12
13
|
option :path,
|
@@ -15,7 +16,9 @@ class ScaffoldingCommands < Thor
|
|
15
16
|
type: :boolean, required: false, desc: 'This will delete the selected page', aliases: '-d'
|
16
17
|
|
17
18
|
def page(name)
|
18
|
-
|
19
|
+
return delete_scaffolding(name, 'page') if options[:delete]
|
20
|
+
|
21
|
+
generate_scaffolding(name, 'page', options[:path])
|
19
22
|
end
|
20
23
|
|
21
24
|
desc 'feature [NAME]', 'Creates a new feature'
|
@@ -27,7 +30,9 @@ class ScaffoldingCommands < Thor
|
|
27
30
|
required: false, desc: 'This will delete the selected feature', aliases: '-d'
|
28
31
|
|
29
32
|
def feature(name)
|
30
|
-
|
33
|
+
return delete_scaffolding(name, 'feature') if options[:delete]
|
34
|
+
|
35
|
+
generate_scaffolding(name, 'feature', options[:path])
|
31
36
|
end
|
32
37
|
|
33
38
|
desc 'spec [SPEC_NAME]', 'Creates a new spec'
|
@@ -37,7 +42,9 @@ class ScaffoldingCommands < Thor
|
|
37
42
|
type: :boolean, required: false, desc: 'This will delete the selected spec', aliases: '-d'
|
38
43
|
|
39
44
|
def spec(name)
|
40
|
-
|
45
|
+
return delete_scaffolding(name, 'spec') if options[:delete]
|
46
|
+
|
47
|
+
generate_scaffolding(name, 'spec', options[:path])
|
41
48
|
end
|
42
49
|
|
43
50
|
desc 'helper [HELPER_NAME]', 'Creates a new helper'
|
@@ -47,7 +54,21 @@ class ScaffoldingCommands < Thor
|
|
47
54
|
type: :boolean, required: false, desc: 'This will delete the selected helper', aliases: '-d'
|
48
55
|
|
49
56
|
def helper(name)
|
50
|
-
|
57
|
+
return delete_scaffolding(name, 'helper') if options[:delete]
|
58
|
+
|
59
|
+
generate_scaffolding(name, 'helper', options[:path])
|
60
|
+
end
|
61
|
+
|
62
|
+
desc 'steps [STEPS_NAME]', 'Creates a new steps definition'
|
63
|
+
option :path,
|
64
|
+
type: :string, required: false, desc: 'The path where your steps will be created', aliases: '-p'
|
65
|
+
option :delete,
|
66
|
+
type: :boolean, required: false, desc: 'This will delete the selected steps', aliases: '-d'
|
67
|
+
|
68
|
+
def steps(name)
|
69
|
+
return delete_scaffolding(name, 'steps') if options[:delete]
|
70
|
+
|
71
|
+
generate_scaffolding(name, 'steps', options[:path])
|
51
72
|
end
|
52
73
|
|
53
74
|
desc 'scaffold [SCAFFOLD_NAME]', 'It generates everything needed to start automating'
|
@@ -57,46 +78,23 @@ class ScaffoldingCommands < Thor
|
|
57
78
|
Scaffolding.new([name, load_config_path('spec')]).generate_spec
|
58
79
|
else
|
59
80
|
Scaffolding.new([name, load_config_path('feature')]).generate_feature
|
81
|
+
Scaffolding.new([name, load_config_path('steps')]).generate_steps
|
60
82
|
end
|
61
|
-
Scaffolding.new([name, load_config_path('page')]).
|
83
|
+
Scaffolding.new([name, load_config_path('page')]).generate_page
|
62
84
|
end
|
63
85
|
|
64
|
-
desc 'config', 'Creates configuration file'
|
65
|
-
option :delete,
|
66
|
-
type: :boolean, required: false, desc: 'This will delete the config file', aliases: '-d'
|
67
|
-
|
68
86
|
no_commands do
|
69
87
|
def load_config_path(type)
|
70
88
|
YAML.load_file('config/config.yml')["#{type}_path"] if Pathname.new('config/config.yml').exist?
|
71
89
|
end
|
72
90
|
|
73
|
-
def
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
scaffolding.delete_class
|
81
|
-
when 'feature'
|
82
|
-
scaffolding.delete_feature
|
83
|
-
when 'spec'
|
84
|
-
scaffolding.delete_spec
|
85
|
-
when 'helper'
|
86
|
-
scaffolding.delete_helper
|
87
|
-
end
|
88
|
-
else
|
89
|
-
case type
|
90
|
-
when 'page'
|
91
|
-
scaffolding.generate_class
|
92
|
-
when 'feature'
|
93
|
-
scaffolding.generate_feature
|
94
|
-
when 'spec'
|
95
|
-
scaffolding.generate_spec
|
96
|
-
when 'helper'
|
97
|
-
scaffolding.generate_helper
|
98
|
-
end
|
99
|
-
end
|
91
|
+
def delete_scaffolding(name, type)
|
92
|
+
Scaffolding.new([name]).send("delete_#{type}")
|
93
|
+
end
|
94
|
+
|
95
|
+
def generate_scaffolding(name, type, path)
|
96
|
+
path ||= load_config_path(type)
|
97
|
+
Scaffolding.new([name, path]).send("generate_#{type}")
|
100
98
|
end
|
101
99
|
end
|
102
100
|
end
|
data/lib/generators/generator.rb
CHANGED
@@ -9,6 +9,7 @@ class Generator < Thor::Group
|
|
9
9
|
argument :framework
|
10
10
|
argument :name
|
11
11
|
argument :visual_automation, optional: true
|
12
|
+
argument :axe_support, optional: true
|
12
13
|
|
13
14
|
def self.source_paths
|
14
15
|
base_path = File.dirname(__FILE__)
|
@@ -46,7 +47,7 @@ class Generator < Thor::Group
|
|
46
47
|
end
|
47
48
|
|
48
49
|
def visual?
|
49
|
-
|
50
|
+
args[3]
|
50
51
|
end
|
51
52
|
|
52
53
|
def watir?
|
@@ -57,6 +58,10 @@ class Generator < Thor::Group
|
|
57
58
|
(args & (%w[selenium watir])).count.positive?
|
58
59
|
end
|
59
60
|
|
61
|
+
def axe?
|
62
|
+
args.last
|
63
|
+
end
|
64
|
+
|
60
65
|
private
|
61
66
|
|
62
67
|
def _initializer
|
@@ -18,7 +18,8 @@ module InvokeGenerators
|
|
18
18
|
framework: framework,
|
19
19
|
generator: generator,
|
20
20
|
name: structure[:name],
|
21
|
-
visual: structure[:visual]
|
21
|
+
visual: structure[:visual],
|
22
|
+
axe_support: structure[:axe_support]
|
22
23
|
})
|
23
24
|
end
|
24
25
|
end
|
@@ -32,6 +33,7 @@ module InvokeGenerators
|
|
32
33
|
.new([structure[:automation],
|
33
34
|
structure[:framework],
|
34
35
|
structure[:name],
|
35
|
-
structure[:visual]
|
36
|
+
structure[:visual],
|
37
|
+
structure[:axe_support]]).invoke_all
|
36
38
|
end
|
37
39
|
end
|
@@ -22,7 +22,11 @@ class MenuGenerator
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def choose_visual_automation
|
25
|
-
prompt.select('Do you want to add visual automation with
|
25
|
+
prompt.select('Do you want to add visual automation with Applitools?', yes_no_menu_choices)
|
26
|
+
end
|
27
|
+
|
28
|
+
def choose_axe_support
|
29
|
+
prompt.select('Do you want to add Axe accessibility testing tool?', yes_no_menu_choices)
|
26
30
|
end
|
27
31
|
|
28
32
|
def choose_test_framework(automation)
|
@@ -37,7 +41,8 @@ class MenuGenerator
|
|
37
41
|
automation: options[:automation],
|
38
42
|
framework: options[:framework],
|
39
43
|
name: @name,
|
40
|
-
visual: options[:visual_automation]
|
44
|
+
visual: options[:visual_automation],
|
45
|
+
axe_support: options[:axe_support]
|
41
46
|
}
|
42
47
|
generate_framework(structure)
|
43
48
|
system "cd #{name} && gem install bundler && bundle install"
|
@@ -69,22 +74,32 @@ class MenuGenerator
|
|
69
74
|
end
|
70
75
|
end
|
71
76
|
|
72
|
-
FrameworkOptions = Struct.new(:automation, :framework, :visual_automation)
|
77
|
+
FrameworkOptions = Struct.new(:automation, :framework, :visual_automation, :axe_support)
|
73
78
|
|
74
79
|
def create_framework_options(params)
|
75
|
-
FrameworkOptions.new(params[:automation], params[:framework], params[:visual_automation])
|
80
|
+
FrameworkOptions.new(params[:automation], params[:framework], params[:visual_automation], params[:axe_support])
|
76
81
|
end
|
77
82
|
|
78
83
|
def create_framework(framework, automation_type)
|
79
84
|
visual_automation = choose_visual_automation if %w[selenium].include?(automation_type)
|
85
|
+
axe = choose_axe_support if automation_type == 'selenium' && framework == 'Rspec' && visual_automation == false
|
80
86
|
options = create_framework_options(automation: automation_type,
|
81
87
|
framework: framework.downcase,
|
82
|
-
visual_automation: visual_automation
|
88
|
+
visual_automation: visual_automation,
|
89
|
+
axe_support: axe)
|
90
|
+
|
91
|
+
# Print the chosen options
|
92
|
+
puts 'Chosen Options:'
|
93
|
+
puts " Automation Type: #{options[:automation]}"
|
94
|
+
puts " Framework: #{options[:framework]}"
|
95
|
+
puts " Visual Automation: #{options[:visual_automation]}"
|
96
|
+
puts " Axe Support: #{options[:axe_support]}"
|
97
|
+
|
83
98
|
set_up_framework(options)
|
84
99
|
prompt.say("You have chosen to use #{framework} with #{automation_type}")
|
85
100
|
end
|
86
101
|
|
87
|
-
def
|
102
|
+
def yes_no_menu_choices
|
88
103
|
{
|
89
104
|
Yes: -> { true },
|
90
105
|
No: -> { false },
|
@@ -6,6 +6,34 @@ require_relative '../models/model_factory'
|
|
6
6
|
require_relative '../page_objects/pages/account'
|
7
7
|
require_relative '../page_objects/pages/login'
|
8
8
|
|
9
|
+
<%- if axe? %>
|
10
|
+
describe 'Login' do
|
11
|
+
let(:login) { Login.new(driver) }
|
12
|
+
let(:account) { Account.new(driver) }
|
13
|
+
let(:user) { ModelFactory.for('users')['registered user'] }
|
14
|
+
|
15
|
+
before do
|
16
|
+
login.visit
|
17
|
+
login.log_as(user['username'], user['password'])
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with a login user on the account page' do
|
21
|
+
it 'no accessibility errors are present on the page' do
|
22
|
+
expect(account.page).to be_axe_clean
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'no accessibility errors are present on the transaction history' do
|
26
|
+
transaction_history = '.dash-tile.dash-tile-balloon.clearfix'
|
27
|
+
expect(account.page).to be_axe_clean.within transaction_history
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'no accessibility errors are present on the heading' do
|
31
|
+
heading = '.maintext'
|
32
|
+
expect(account.page).to be_axe_clean.within heading
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
<%- elsif %w[selenium watir].include? automation -%>
|
9
37
|
describe 'Login' do
|
10
38
|
subject(:header) { account_page.header.customer_name }
|
11
39
|
|
@@ -42,6 +70,7 @@ describe 'Login' do
|
|
42
70
|
end
|
43
71
|
end
|
44
72
|
end
|
73
|
+
<%- end -%>
|
45
74
|
<%- elsif automation == 'sparkling_ios' -%>
|
46
75
|
require_relative '../helpers/spec_helper'
|
47
76
|
require_relative '../page_objects/pages/home'
|
@@ -7,6 +7,10 @@ gem 'allure-cucumber'
|
|
7
7
|
gem 'allure-rspec'
|
8
8
|
gem 'allure-ruby-commons'
|
9
9
|
<% end -%>
|
10
|
+
<% if axe? -%>
|
11
|
+
gem 'axe-core-rspec'
|
12
|
+
gem 'axe-core-selenium'
|
13
|
+
<% end -%>
|
10
14
|
<% if visual_automation -%>
|
11
15
|
gem 'eyes_selenium', '~> 4.6', '>= 4.6.1'
|
12
16
|
gem 'eyes_universal', '~> 3.3', '>= 3.3.1'
|
@@ -1,8 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
config = YAML.load_file('config/config.yml')
|
6
|
-
config['browser'] = args.browser
|
7
|
-
File.write('config/config.yml', config.to_yaml)
|
8
|
-
end
|
1
|
+
desc 'Print Ruby Raider version'
|
2
|
+
task :raider do
|
3
|
+
system 'raider version'
|
4
|
+
end
|
@@ -1,29 +1,25 @@
|
|
1
1
|
# Ruby Raider
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/ruby_raider.svg)](https://badge.fury.io/rb/ruby_raider)
|
4
|
-
[![Rubocop](https://github.com/RubyRaider/ruby_raider/actions/workflows/rspec.yml/badge.svg)](https://github.com/RubyRaider/ruby_raider/actions/workflows/rspec.yml)
|
5
|
-
[![Gitter](https://badges.gitter.im/RubyRaider/community.svg)](https://gitter.im/RubyRaider/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
6
|
-
|
7
3
|
<!-- PROJECT LOGO -->
|
8
4
|
<br />
|
9
5
|
<div align="center">
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
6
|
+
<a href="https://github.com/RubyRaider/ruby_raider">
|
7
|
+
<img src="https://rubyraiderdotcom.files.wordpress.com/2022/05/logo_transparent_background-1.png" alt="Logo">
|
8
|
+
</a>
|
9
|
+
<h1 align="center">Ruby Raider</h1>
|
10
|
+
<p align="center">
|
11
|
+
This is a gem to make setup and start of UI automation projects easier.
|
12
|
+
<br />
|
13
|
+
<a href="https://github.com/RubyRaider/ruby_raider#getting-started"><strong>Explore the docs »</strong></a>
|
14
|
+
<br />
|
15
|
+
<br />
|
16
|
+
<a href="https://rubygems.org/gems/ruby_raider">Rubygems</a>
|
17
|
+
·
|
18
|
+
<a href="https://github.com/RubyRaider/ruby_raider/issues">Report Bug</a>
|
19
|
+
·
|
20
|
+
<a href="https://github.com/RubyRaider/ruby_raider/issues">Request Feature</a>
|
21
|
+
</p>
|
22
|
+
<p align="center"> For more information and updates on releases, see <a href="https://ruby-raider.com">https://ruby-raider.com</a></p>
|
27
23
|
</div>
|
28
24
|
|
29
25
|
## What is Ruby Raider?
|
@@ -39,7 +35,7 @@ Ruby Raider is a generator and scaffolding gem to make UI test automation easier
|
|
39
35
|
| Rspec and Watir | | Rspec and Appium for Android |
|
40
36
|
| | | Cucumber and Appium Cross-platform |
|
41
37
|
| | | Rspec and Appium Cross-platform |
|
42
|
-
| | |
|
38
|
+
| | | Cucumber and Sparkling Watir for IOS |
|
43
39
|
| | | Rspec and Sparkling Watir for IOS |
|
44
40
|
|
45
41
|
|
@@ -86,46 +82,45 @@ Select the ones you will like to work with.
|
|
86
82
|
|
87
83
|
```ruby
|
88
84
|
Commands:
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
raider version # It shows the version of Ruby Raider you are currently using
|
85
|
+
raider generate # Provides access to all the scaffolding commands
|
86
|
+
raider help [COMMAND] # Describe available commands or one specific command
|
87
|
+
raider new [PROJECT_NAME] # Creates a new framework based on settings picked
|
88
|
+
raider utility # Provides access to all the utility commands
|
89
|
+
raider version # It shows the version of Ruby Raider you are currently using
|
95
90
|
```
|
96
91
|
|
97
92
|
All the basic commands have their corresponding shortcut:
|
98
93
|
|
99
94
|
* g for generate
|
100
95
|
* n for new
|
101
|
-
* o for open_ai
|
102
96
|
* u for utility
|
103
97
|
* v for version
|
104
98
|
|
99
|
+
### Scaffolding Commands
|
100
|
+
Ruby Raider also supports scaffolding:
|
101
|
+
|
102
|
+
* To create a new page object you do: ```raider g page [PAGE_NAME]```
|
103
|
+
* To create a new spec you do: ```raider g spec [SPEC_NAME]```
|
104
|
+
* To create a new feature you do: ```raider g feature [FEATURE_NAME]```
|
105
|
+
* To create a new steps definition you do: ```raider g steps [STEPS_NAME]```
|
106
|
+
* To create both a page/spec or a page/feature/steps you do: ```raider g scaffold [SCAFFOLD_NAME]```
|
107
|
+
|
108
|
+
It's possible to add the option --path or -p if you want to specify where to create your features, pages, helpers and
|
109
|
+
specs.
|
110
|
+
|
111
|
+
If you want to set the default path for the creation of your features, helpers and specs:
|
105
112
|
|
106
|
-
### Appium Server Command
|
107
|
-
To initialise Appium server run this command:
|
108
113
|
```ruby
|
109
|
-
raider u
|
114
|
+
raider u path [PATH_NAME] - -feature or -f
|
115
|
+
raider u path [PATH_NAME] - -spec or -s
|
116
|
+
raider u path [PATH_NAME] - -helper or -h
|
110
117
|
```
|
111
118
|
|
112
|
-
|
119
|
+
If you don't specify an option, path will assume you want to change the default path for pages.
|
113
120
|
|
114
|
-
```ruby
|
115
|
-
# Will print the result of the request on the terminal
|
116
|
-
raider o make [REQUEST]
|
117
|
-
# Will create a file with the result of your request as content
|
118
|
-
raider o make [REQUEST] - -path or -p [PATH]
|
119
|
-
# Will input the content of the chosen file into open ai and will edit it based on the result
|
120
|
-
raider o make [PATH_NAME] - -edit or -e [FILE_PATH]
|
121
|
-
# Creates a cucumber file and uses it to input into open ai and create a steps file
|
122
|
-
# The prompt is required
|
123
|
-
raider o cucumber [NAME] - -prompt or -p [PROMPT]
|
124
|
-
# Creates a cucumber step definitions file based on an scenario file
|
125
|
-
raider open_ai steps [NAME]
|
126
|
-
Options :
|
127
|
-
-p, [--path = PATH] # The path where your steps will be created
|
128
|
-
-pr, [--prompt = PROMPT] # This will create the selected steps based on your prompt using open ai
|
129
|
-
-i, [--input = INPUT] # It uses a file as input to create the steps
|
130
121
|
|
122
|
+
### Appium Server Command
|
123
|
+
To initialise Appium server run this command:
|
124
|
+
```ruby
|
125
|
+
raider u start_appium
|
131
126
|
```
|
@@ -21,6 +21,9 @@ module DriverHelper
|
|
21
21
|
end
|
22
22
|
<%- else -%>
|
23
23
|
# frozen_string_literal: true
|
24
|
+
<% if axe? -%>
|
25
|
+
require 'axe-selenium'
|
26
|
+
<% end -%>
|
24
27
|
require 'yaml'
|
25
28
|
<% if automation == 'selenium' -%>
|
26
29
|
require 'active_support/inflector'
|
@@ -30,10 +33,14 @@ require 'appium_lib'
|
|
30
33
|
<% end -%>
|
31
34
|
|
32
35
|
module DriverHelper
|
33
|
-
<% if automation == 'selenium' -%>
|
36
|
+
<% if automation == 'selenium' && axe? == false -%>
|
34
37
|
def driver(*opts)
|
35
38
|
@driver ||= create_driver(*opts)
|
36
39
|
end
|
40
|
+
<% elsif axe? == true -%>
|
41
|
+
def driver(browser = :chrome, js_path = nil, skip_iframes = nil)
|
42
|
+
@driver ||= create_driver(browser, js_path, skip_iframes)
|
43
|
+
end
|
37
44
|
<% else -%>
|
38
45
|
def driver
|
39
46
|
@driver ||= create_driver
|
@@ -1,4 +1,11 @@
|
|
1
|
-
<% if automation == 'selenium' -%>
|
1
|
+
<% if automation == 'selenium' && axe? == true -%>
|
2
|
+
def create_driver(browser, js_path, skip_iframes)
|
3
|
+
AxeSelenium.configure(browser) do |config|
|
4
|
+
config.jslib_path = js_path if js_path
|
5
|
+
config.skip_iframes = skip_iframes if skip_iframes
|
6
|
+
end.page
|
7
|
+
end
|
8
|
+
<% elsif automation == 'selenium' -%>
|
2
9
|
def create_driver(*opts)
|
3
10
|
@config = YAML.load_file('config/config.yml')
|
4
11
|
browser = @config['browser'].to_sym
|
@@ -22,7 +29,6 @@
|
|
22
29
|
driver_options.each { |opt| options.add_option(opt.first, opt.last) }
|
23
30
|
options
|
24
31
|
end
|
25
|
-
|
26
32
|
<% elsif automation == 'cross_platform' -%>
|
27
33
|
def create_driver
|
28
34
|
platform = config['platform'].to_s
|
data/lib/ruby_raider.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '../lib/commands/open_ai_commands'
|
4
3
|
require_relative '../lib/commands/scaffolding_commands'
|
5
4
|
require_relative '../lib/commands/utility_commands'
|
6
5
|
|
@@ -19,26 +18,21 @@ module RubyRaider
|
|
19
18
|
desc 'version', 'It shows the version of Ruby Raider you are currently using'
|
20
19
|
|
21
20
|
def version
|
22
|
-
puts "The version is #{
|
21
|
+
puts "The version is #{current_version}, happy testing!"
|
23
22
|
end
|
24
23
|
|
25
24
|
map 'v' => 'version'
|
26
25
|
|
27
|
-
desc 'generate', 'Provides access to all the
|
26
|
+
desc 'generate', 'Provides access to all the scaffolding commands'
|
28
27
|
subcommand 'generate', ScaffoldingCommands
|
29
28
|
map 'g' => 'generate'
|
30
29
|
|
31
|
-
desc 'open_ai', 'Provides access to all the open ai commands'
|
32
|
-
subcommand 'open_ai', OpenAiCommands
|
33
|
-
map 'o' => 'open_ai'
|
34
|
-
|
35
30
|
desc 'utility', 'Provides access to all the utility commands'
|
36
31
|
subcommand 'utility', UtilityCommands
|
37
32
|
map 'u' => 'utility'
|
38
33
|
|
39
34
|
no_commands do
|
40
|
-
def
|
41
|
-
def parsed_version = Gem::Version.new(gemspec.version)
|
35
|
+
def current_version = File.read(File.expand_path('version', __dir__)).strip
|
42
36
|
end
|
43
37
|
end
|
44
38
|
end
|
@@ -12,8 +12,8 @@ class Scaffolding < Thor::Group
|
|
12
12
|
"#{File.dirname(__FILE__)}/templates"
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
template('page_object.tt', default_path("page_objects/pages/#{name}
|
15
|
+
def generate_page
|
16
|
+
template('page_object.tt', default_path("page_objects/pages/#{name}.rb", '_page.rb'))
|
17
17
|
end
|
18
18
|
|
19
19
|
def generate_feature
|
@@ -21,20 +21,24 @@ class Scaffolding < Thor::Group
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def generate_spec
|
24
|
-
template('spec.tt', default_path("spec/#{name}
|
24
|
+
template('spec.tt', default_path("spec/#{name}_page_spec.rb", '_spec.rb'))
|
25
25
|
end
|
26
26
|
|
27
27
|
def generate_helper
|
28
28
|
template('helper.tt', default_path("helpers/#{name}_helper.rb", '_helper.rb'))
|
29
29
|
end
|
30
30
|
|
31
|
+
def generate_steps
|
32
|
+
template('steps.tt', default_path("features/step_definitions/#{name}_steps.rb", '_steps.rb'))
|
33
|
+
end
|
34
|
+
|
31
35
|
def generate_config
|
32
36
|
template('../../generators/templates/common/config.tt',
|
33
37
|
default_path('config/config.yml', '.yml'))
|
34
38
|
end
|
35
39
|
|
36
|
-
def
|
37
|
-
remove_file(default_path("page_objects/pages/#{name}
|
40
|
+
def delete_page
|
41
|
+
remove_file(default_path("page_objects/pages/#{name}.rb", '_page.rb'))
|
38
42
|
end
|
39
43
|
|
40
44
|
def delete_feature
|
@@ -42,13 +46,17 @@ class Scaffolding < Thor::Group
|
|
42
46
|
end
|
43
47
|
|
44
48
|
def delete_spec
|
45
|
-
remove_file(default_path("spec/#{name}
|
49
|
+
remove_file(default_path("spec/#{name}_page_spec.rb", '_spec.rb'))
|
46
50
|
end
|
47
51
|
|
48
52
|
def delete_helper
|
49
53
|
remove_file(default_path("helpers/#{name}_helper.rb", '_helper.rb'))
|
50
54
|
end
|
51
55
|
|
56
|
+
def delete_steps
|
57
|
+
remove_file(default_path("features/step_definitions/#{name}_steps.rb", '_steps.rb'))
|
58
|
+
end
|
59
|
+
|
52
60
|
def delete_config
|
53
61
|
remove_file(default_path('config/config.yml', '.yml'))
|
54
62
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '../abstract/
|
3
|
+
require_relative '../abstract/page'
|
4
4
|
|
5
|
-
class <%= name.split('_').map {|word| word.capitalize }.join
|
5
|
+
class <%= name.split('_').map {|word| word.capitalize }.join %> < Page
|
6
6
|
|
7
7
|
# Actions
|
8
8
|
|
@@ -1,5 +1,4 @@
|
|
1
|
-
require_relative '
|
2
|
-
require_relative '../page_objects/pages/<%= name %>_page'
|
1
|
+
require_relative '../page_objects/pages/<%= name %>'
|
3
2
|
|
4
|
-
describe <%= name.split('_').map {|word| word.capitalize }.join
|
3
|
+
describe '<%= name.split('_').map {|word| word.capitalize }.join %>' do
|
5
4
|
end
|
data/lib/version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.8.8
|
data/ruby_raider.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'ruby_raider'
|
5
|
-
s.version =
|
5
|
+
s.version = File.read(File.expand_path('lib/version', __dir__)).strip
|
6
6
|
s.summary = 'A gem to make setup and start of UI automation projects easier'
|
7
7
|
s.description = 'This gem has everything you need to start working with test automation'
|
8
8
|
s.authors = ['Agustin Pequeno']
|
@@ -22,7 +22,6 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_development_dependency 'rubocop-rspec', '~> 2.9.0'
|
23
23
|
|
24
24
|
s.add_runtime_dependency 'faraday', '~> 1.10.0'
|
25
|
-
s.add_runtime_dependency 'ruby-openai', '~> 3.5'
|
26
25
|
s.add_runtime_dependency 'thor', '~> 1.2.1'
|
27
26
|
s.add_runtime_dependency 'tty-prompt', '~> 0.23.1'
|
28
27
|
end
|
@@ -27,12 +27,12 @@ describe ScaffoldingCommands do
|
|
27
27
|
|
28
28
|
it 'scaffolds for rspec creating a spec' do
|
29
29
|
scaffold.new.invoke(:scaffold, nil, %W[#{name}])
|
30
|
-
expect(Pathname.new("spec/#{name}
|
30
|
+
expect(Pathname.new("spec/#{name}_page_spec.rb")).to be_file
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'scaffolds for rspec creating a page' do
|
34
34
|
scaffold.new.invoke(:scaffold, nil, %W[#{name}])
|
35
|
-
expect(Pathname.new("page_objects/pages/#{name}
|
35
|
+
expect(Pathname.new("page_objects/pages/#{name}.rb")).to be_file
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'deletes a spec' do
|
@@ -47,7 +47,7 @@ describe ScaffoldingCommands do
|
|
47
47
|
|
48
48
|
it 'creates a page' do
|
49
49
|
scaffold.new.invoke(:page, nil, %W[#{name}])
|
50
|
-
expect(Pathname.new("page_objects/pages/#{name}
|
50
|
+
expect(Pathname.new("page_objects/pages/#{name}.rb")).to be_file
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'creates a page with a path' do
|
@@ -77,7 +77,12 @@ describe ScaffoldingCommands do
|
|
77
77
|
|
78
78
|
it 'scaffolds for cucumber creating a page' do
|
79
79
|
scaffold.new.invoke(:scaffold, nil, %W[#{name}])
|
80
|
-
expect(Pathname.new("page_objects/pages/#{name}
|
80
|
+
expect(Pathname.new("page_objects/pages/#{name}.rb")).to be_file
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'scaffolds for cucumber creating a steps definition' do
|
84
|
+
scaffold.new.invoke(:scaffold, nil, %W[#{name}])
|
85
|
+
expect(Pathname.new("features/step_definitions/#{name}_steps.rb")).to be_file
|
81
86
|
end
|
82
87
|
|
83
88
|
it 'creates a helper' do
|
@@ -85,6 +90,11 @@ describe ScaffoldingCommands do
|
|
85
90
|
expect(Pathname.new("helpers/#{name}_helper.rb")).to be_file
|
86
91
|
end
|
87
92
|
|
93
|
+
it 'creates a steps definition' do
|
94
|
+
scaffold.new.invoke(:steps, nil, %W[#{name}])
|
95
|
+
expect(Pathname.new("features/step_definitions/#{name}_steps.rb")).to be_file
|
96
|
+
end
|
97
|
+
|
88
98
|
it 'deletes a page' do
|
89
99
|
scaffold.new.invoke(:page, nil, %w[login --delete])
|
90
100
|
expect(Pathname.new('page_objects/pages/login_page.rb')).not_to be_file
|
data/spec/spec_helper.rb
CHANGED
@@ -15,7 +15,7 @@ RSpec.configure do |config|
|
|
15
15
|
FRAMEWORKS.each do |framework|
|
16
16
|
AUTOMATION_TYPES.each do |automation|
|
17
17
|
[true, false].each do |visual|
|
18
|
-
settings = create_settings(framework: framework, automation: automation, visual: visual)
|
18
|
+
settings = create_settings(framework: framework, automation: automation, visual: visual, axe: axe_support)
|
19
19
|
generate_framework(settings)
|
20
20
|
end
|
21
21
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_raider
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Agustin Pequeno
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|
@@ -122,20 +122,6 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: 1.10.0
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: ruby-openai
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - "~>"
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '3.5'
|
132
|
-
type: :runtime
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - "~>"
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '3.5'
|
139
125
|
- !ruby/object:Gem::Dependency
|
140
126
|
name: thor
|
141
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -176,6 +162,7 @@ files:
|
|
176
162
|
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
177
163
|
- ".github/auto_assign-issues.yml"
|
178
164
|
- ".github/workflows/integration.yml"
|
165
|
+
- ".github/workflows/push_gem.yml"
|
179
166
|
- ".github/workflows/reek.yml"
|
180
167
|
- ".github/workflows/rubocop.yml"
|
181
168
|
- ".github/workflows/system.yml"
|
@@ -189,7 +176,6 @@ files:
|
|
189
176
|
- README.md
|
190
177
|
- Rakefile
|
191
178
|
- bin/raider
|
192
|
-
- lib/commands/open_ai_commands.rb
|
193
179
|
- lib/commands/scaffolding_commands.rb
|
194
180
|
- lib/commands/utility_commands.rb
|
195
181
|
- lib/generators/actions/actions_generator.rb
|
@@ -262,17 +248,17 @@ files:
|
|
262
248
|
- lib/generators/templates/helpers/spec_helper.tt
|
263
249
|
- lib/generators/templates/helpers/visual_helper.tt
|
264
250
|
- lib/generators/templates/helpers/visual_spec_helper.tt
|
265
|
-
- lib/open_ai/open_ai.rb
|
266
251
|
- lib/ruby_raider.rb
|
267
252
|
- lib/scaffolding/scaffolding.rb
|
268
253
|
- lib/scaffolding/templates/feature.tt
|
269
254
|
- lib/scaffolding/templates/helper.tt
|
270
255
|
- lib/scaffolding/templates/page_object.tt
|
271
256
|
- lib/scaffolding/templates/spec.tt
|
257
|
+
- lib/scaffolding/templates/steps.tt
|
272
258
|
- lib/utilities/logger.rb
|
273
259
|
- lib/utilities/utilities.rb
|
260
|
+
- lib/version
|
274
261
|
- ruby_raider.gemspec
|
275
|
-
- spec/integration/commands/open_ai_commands_spec.rb
|
276
262
|
- spec/integration/commands/scaffolding_commands_spec.rb
|
277
263
|
- spec/integration/commands/utility_commands_spec.rb
|
278
264
|
- spec/integration/generators/actions_generator_spec.rb
|
@@ -303,7 +289,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
303
289
|
- !ruby/object:Gem::Version
|
304
290
|
version: '0'
|
305
291
|
requirements: []
|
306
|
-
rubygems_version: 3.
|
292
|
+
rubygems_version: 3.5.3
|
307
293
|
signing_key:
|
308
294
|
specification_version: 4
|
309
295
|
summary: A gem to make setup and start of UI automation projects easier
|
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'thor'
|
2
|
-
require 'faraday'
|
3
|
-
require_relative '../open_ai/open_ai'
|
4
|
-
|
5
|
-
class OpenAiCommands < Thor
|
6
|
-
desc 'make [REQUEST]', 'Uses open AI to create a file or generate output'
|
7
|
-
option :path,
|
8
|
-
type: :string, required: false, desc: 'The path where your file will be created', aliases: '-p'
|
9
|
-
option :edit,
|
10
|
-
type: :string, required: false, desc: 'Path to the file you want to edit', aliases: '-e'
|
11
|
-
|
12
|
-
def make(request, path = nil)
|
13
|
-
path ||= options[:path]
|
14
|
-
edit_path = options[:edit]
|
15
|
-
if edit_path
|
16
|
-
pp 'Editing File...'
|
17
|
-
OpenAi.edit_file(path: edit_path, request: request)
|
18
|
-
pp "File #{edit_path} edited"
|
19
|
-
elsif path
|
20
|
-
pp 'Generating File...'
|
21
|
-
OpenAi.create_file(path: path, request: request)
|
22
|
-
pp "File created in #{path}"
|
23
|
-
else
|
24
|
-
puts OpenAi.output(request: request)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
desc 'cucumber [NAME]', 'Creates feature and step files only using open ai'
|
29
|
-
option :prompt,
|
30
|
-
type: :string,
|
31
|
-
required: true, desc: 'The prompt for open ai', aliases: '-p'
|
32
|
-
|
33
|
-
def cucumber(name)
|
34
|
-
feature_path = "features/#{name}.feature"
|
35
|
-
make(options[:prompt], feature_path)
|
36
|
-
prompt_step = "create cucumber steps for the following scenarios in ruby #{File.read(feature_path)}"
|
37
|
-
make(prompt_step, "features/step_definitions/#{name}_steps.rb")
|
38
|
-
end
|
39
|
-
|
40
|
-
desc 'steps [NAME]', 'Creates a new step definitions file'
|
41
|
-
option :path,
|
42
|
-
type: :string,
|
43
|
-
required: false, desc: 'The path where your steps will be created', aliases: '-p'
|
44
|
-
option :prompt,
|
45
|
-
type: :string, required: false,
|
46
|
-
desc: 'This will create the selected steps based on your prompt using open ai', aliases: '-pr'
|
47
|
-
option :input,
|
48
|
-
type: :string,
|
49
|
-
required: false, desc: 'It uses a file as input to create the steps', aliases: '-i'
|
50
|
-
|
51
|
-
def steps(name)
|
52
|
-
path = 'features/step_definitions'
|
53
|
-
input = options[:input]
|
54
|
-
if input
|
55
|
-
prompt = options[:prompt] || 'create cucumber steps for the following scenarios in ruby'
|
56
|
-
content = "#{prompt} #{File.read(input)}"
|
57
|
-
make(content, "#{path}/#{name}_steps.rb")
|
58
|
-
else
|
59
|
-
make(options[:open_ai], "#{path}/#{name}_steps.rb")
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
desc 'test', 'Uses open AI to create a file or generate output'
|
64
|
-
def test
|
65
|
-
conn = Faraday.new(url: 'https://api.openai.com') do |faraday|
|
66
|
-
faraday.headers['Content-Type'] = 'application/json'
|
67
|
-
faraday.headers['Authorization'] = "Bearer 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"
|
68
|
-
faraday.headers['OpenAI-Beta'] = 'assistants=v1'
|
69
|
-
end
|
70
|
-
|
71
|
-
# Data payload for the POST request
|
72
|
-
payload = {
|
73
|
-
instructions: "You are a personal math tutor. When asked a question, write and run Python code to answer the question.",
|
74
|
-
name: "Math Tutor",
|
75
|
-
tools: [{ type: "code_interpreter" }],
|
76
|
-
model: "gpt-4-1106-preview"
|
77
|
-
}
|
78
|
-
|
79
|
-
# Perform the POST request
|
80
|
-
response = conn.post('/v1/assistants', payload.to_json)
|
81
|
-
|
82
|
-
# Output the response body
|
83
|
-
puts response.body
|
84
|
-
end
|
85
|
-
end
|
data/lib/open_ai/open_ai.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'openai'
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
module OpenAi
|
5
|
-
class << self
|
6
|
-
def client
|
7
|
-
@client ||= create_client
|
8
|
-
end
|
9
|
-
|
10
|
-
def create_client
|
11
|
-
configure_client
|
12
|
-
OpenAI::Client.new
|
13
|
-
end
|
14
|
-
|
15
|
-
def configure_client
|
16
|
-
OpenAI.configure do |config|
|
17
|
-
config.access_token = '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'
|
18
|
-
config.organization_id = ENV.fetch('OPENAI_ORGANIZATION_ID', nil)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def input(request, model = 'gpt-4', temperature = 0.7)
|
23
|
-
client.chat(
|
24
|
-
parameters: {
|
25
|
-
model: model,
|
26
|
-
messages: [{ role: 'user', content: request }],
|
27
|
-
temperature: temperature
|
28
|
-
})
|
29
|
-
end
|
30
|
-
|
31
|
-
def create_file(options)
|
32
|
-
path, request, choice = options.values_at(:path, :request, :choice)
|
33
|
-
File.write(path, output(request: request, choice: choice))
|
34
|
-
end
|
35
|
-
|
36
|
-
def output(options)
|
37
|
-
request, choice = options.values_at(:request, :choice)
|
38
|
-
choice ||= 0
|
39
|
-
extract_text(input(request), 'choices', choice, 'message', 'content')
|
40
|
-
end
|
41
|
-
|
42
|
-
def edit_file(options)
|
43
|
-
path, request, choice = options.values_at(:path, :request, :choice)
|
44
|
-
content = File.read(path)
|
45
|
-
response = edit(content: content, request: request)
|
46
|
-
File.write(path, extract_text(response, 'choices', choice, 'text'))
|
47
|
-
end
|
48
|
-
|
49
|
-
def edit(options)
|
50
|
-
content, request, model = options.values_at(:content, :request, :model)
|
51
|
-
model ||= 'text-davinci-edit-001'
|
52
|
-
client.edits(
|
53
|
-
parameters: {
|
54
|
-
model: model,
|
55
|
-
input: content,
|
56
|
-
instruction: request
|
57
|
-
}
|
58
|
-
)
|
59
|
-
end
|
60
|
-
|
61
|
-
private
|
62
|
-
|
63
|
-
def extract_text(response, *keys)
|
64
|
-
response.dig(*keys)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# require 'dotenv'
|
2
|
-
# require 'fileutils'
|
3
|
-
# require 'pathname'
|
4
|
-
# require 'yaml'
|
5
|
-
# require_relative '../../../lib/generators/common_generator'
|
6
|
-
# require_relative '../../../lib/integration.commands/open_ai_commands'
|
7
|
-
# require_relative '../../../lib/scaffolding/scaffolding'
|
8
|
-
# require_relative '../../spec_helper'
|
9
|
-
#
|
10
|
-
# describe OpenAiCommands do
|
11
|
-
# let(:open_ai) { described_class }
|
12
|
-
# let(:name) { 'test' }
|
13
|
-
#
|
14
|
-
# orig_dir = Dir.pwd
|
15
|
-
# Dotenv.load
|
16
|
-
#
|
17
|
-
# after do
|
18
|
-
# Dir.chdir orig_dir
|
19
|
-
# end
|
20
|
-
#
|
21
|
-
# context 'without any project' do
|
22
|
-
# after do
|
23
|
-
# FileUtils.rm_rf('joke.txt')
|
24
|
-
# end
|
25
|
-
#
|
26
|
-
# # TODO: Enable test once the paid account is setup
|
27
|
-
# # it 'creates a file using open ai' do
|
28
|
-
# # open_ai.new.invoke(:make, nil, ['tell me a joke', '--path', 'joke.txt'])
|
29
|
-
# # expect(File).to be_size('joke.txt')
|
30
|
-
# # end
|
31
|
-
#
|
32
|
-
# # it 'edits an existing file using open ai' do
|
33
|
-
# # FileUtils.touch('joke.txt')
|
34
|
-
# # open_ai.new.invoke(:make, nil, ['tell me a better joke', '--edit', 'joke.txt'])
|
35
|
-
# # end
|
36
|
-
# end
|
37
|
-
# end
|