bddgenx 0.1.51 → 2.0.5
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 +50 -0
- data/VERSION +1 -1
- data/bin/bddgenx +1 -1
- data/lib/bddgenx/generators/generator.rb +175 -0
- data/lib/bddgenx/{runner.rb → generators/runner.rb} +24 -9
- data/lib/bddgenx/{steps_generator.rb → generators/steps_generator.rb} +32 -34
- data/lib/bddgenx/ia/chatgtp_cliente.rb +147 -0
- data/lib/bddgenx/ia/gemini_cliente.rb +135 -0
- data/lib/bddgenx/{utils → reports}/backup.rb +0 -4
- data/lib/bddgenx/{utils → reports}/pdf_exporter.rb +0 -5
- data/lib/bddgenx/{utils → reports}/tracer.rb +0 -4
- data/lib/bddgenx/{utils/fontLoader.rb → support/font_loader.rb} +0 -4
- data/lib/bddgenx/support/gherkin_cleaner.rb +102 -0
- data/lib/bddgenx/support/remover_steps_duplicados.rb +81 -0
- data/lib/bddgenx/{utils → support}/validator.rb +0 -1
- data/lib/bddgenx.rb +11 -2
- data/lib/env.rb +46 -0
- data/lib/{bddgenx/utils/parser.rb → parser.rb} +5 -3
- data/lib/version.rb +14 -0
- metadata +73 -12
- data/lib/bddgenx/generator.rb +0 -155
- data/lib/bddgenx/version.rb +0 -11
data/lib/bddgenx/generator.rb
DELETED
@@ -1,155 +0,0 @@
|
|
1
|
-
# lib/bddgenx/generator.rb
|
2
|
-
# encoding: utf-8
|
3
|
-
#
|
4
|
-
# Este arquivo define a classe Generator, responsável por gerar arquivos
|
5
|
-
# .feature a partir de um hash de história ou de um arquivo de história em texto.
|
6
|
-
# Suporta Gherkin em Português e Inglês, inclusão de tags, cenários simples
|
7
|
-
# e esquemas de cenário com exemplos.
|
8
|
-
|
9
|
-
require 'fileutils'
|
10
|
-
|
11
|
-
module Bddgenx
|
12
|
-
# Gera cenários e arquivos .feature baseados em histórias e grupos de passos.
|
13
|
-
class Generator
|
14
|
-
# Palavras-chave Gherkin em Português
|
15
|
-
# @return [Array<String>]
|
16
|
-
GHERKIN_KEYS_PT = %w[Dado Quando Então E Mas].freeze
|
17
|
-
|
18
|
-
# Palavras-chave Gherkin em Inglês
|
19
|
-
# @return [Array<String>]
|
20
|
-
GHERKIN_KEYS_EN = %w[Given When Then And But].freeze
|
21
|
-
|
22
|
-
# Mapeamento PT -> EN
|
23
|
-
# @return [Hash{String=>String}]
|
24
|
-
GHERKIN_MAP_PT_EN = GHERKIN_KEYS_PT.zip(GHERKIN_KEYS_EN).to_h
|
25
|
-
|
26
|
-
# Mapeamento EN -> PT
|
27
|
-
# @return [Hash{String=>String}]
|
28
|
-
GHERKIN_MAP_EN_PT = GHERKIN_KEYS_EN.zip(GHERKIN_KEYS_PT).to_h
|
29
|
-
|
30
|
-
# Conjunto de todas as palavras-chave suportadas (PT + EN)
|
31
|
-
# @return [Array<String>]
|
32
|
-
ALL_KEYS = GHERKIN_KEYS_PT + GHERKIN_KEYS_EN
|
33
|
-
|
34
|
-
# Seleciona apenas as linhas que representam exemplos do cenário
|
35
|
-
#
|
36
|
-
# @param raw [Array<String>] Lista de linhas brutas do bloco de exemplos
|
37
|
-
# @return [Array<String>] Linhas que começam com '|' representando a tabela de exemplos
|
38
|
-
def self.dividir_examples(raw)
|
39
|
-
raw.select { |l| l.strip.start_with?('|') }
|
40
|
-
end
|
41
|
-
|
42
|
-
# Gera conteúdo de um arquivo .feature a partir de um hash de história ou caminho para arquivo
|
43
|
-
#
|
44
|
-
# @param input [Hash, String]
|
45
|
-
# Objeto de história com chaves :idioma, :quero, :como, :para, :grupos
|
46
|
-
# Ou caminho para um arquivo de história que será lido via Parser.ler_historia
|
47
|
-
# @param override_path [String, nil]
|
48
|
-
# Caminho de saída alternativo para o arquivo .feature
|
49
|
-
# @raise [ArgumentError] Se Parser.ler_historia lançar erro ao ler arquivo
|
50
|
-
# @return [Array(String, String)] Array com caminho e conteúdo gerado
|
51
|
-
def self.gerar_feature(input, override_path = nil)
|
52
|
-
historia = input.is_a?(String) ? Parser.ler_historia(input) : input
|
53
|
-
idioma = historia[:idioma] || 'pt'
|
54
|
-
cont = 1
|
55
|
-
|
56
|
-
# Geração do nome base do arquivo
|
57
|
-
nome_base = historia[:quero]
|
58
|
-
.gsub(/[^a-z0-9]/i, '_')
|
59
|
-
.downcase
|
60
|
-
.split('_', 3)
|
61
|
-
.first(3)
|
62
|
-
.join('_')
|
63
|
-
|
64
|
-
caminho = if override_path.is_a?(String)
|
65
|
-
override_path
|
66
|
-
else
|
67
|
-
"features/#{nome_base}.feature"
|
68
|
-
end
|
69
|
-
|
70
|
-
# Definição das palavras-chave Gherkin conforme idioma
|
71
|
-
palavras = {
|
72
|
-
feature: idioma == 'en' ? 'Feature' : 'Funcionalidade',
|
73
|
-
contexto: idioma == 'en' ? 'Background' : 'Contexto',
|
74
|
-
cenario: idioma == 'en' ? 'Scenario' : 'Cenário',
|
75
|
-
esquema: idioma == 'en' ? 'Scenario Outline' : 'Esquema do Cenário',
|
76
|
-
exemplos: idioma == 'en' ? 'Examples' : 'Exemplos',
|
77
|
-
regra: idioma == 'en' ? 'Rule' : 'Regra'
|
78
|
-
}
|
79
|
-
|
80
|
-
# Cabeçalho do arquivo .feature
|
81
|
-
conteudo = <<~GHK
|
82
|
-
# language: #{idioma}
|
83
|
-
#{palavras[:feature]}: #{historia[:quero].sub(/^Quero\s*/i,'')}
|
84
|
-
# #{historia[:como]}
|
85
|
-
# #{historia[:quero]}
|
86
|
-
# #{historia[:para]}
|
87
|
-
|
88
|
-
GHK
|
89
|
-
|
90
|
-
pt_map = GHERKIN_MAP_PT_EN
|
91
|
-
en_map = GHERKIN_MAP_EN_PT
|
92
|
-
detect = ALL_KEYS
|
93
|
-
|
94
|
-
historia[:grupos].each do |grupo|
|
95
|
-
passos = grupo[:passos] || []
|
96
|
-
exemplos = grupo[:exemplos] || []
|
97
|
-
next if passos.empty?
|
98
|
-
|
99
|
-
# Linha de tags para o grupo
|
100
|
-
tag_line = ["@#{grupo[:tipo].downcase}",
|
101
|
-
("@#{grupo[:tag]}" if grupo[:tag])]
|
102
|
-
.compact.join(' ')
|
103
|
-
|
104
|
-
if exemplos.any?
|
105
|
-
# Cenário com Esquema
|
106
|
-
conteudo << " #{tag_line}\n"
|
107
|
-
conteudo << " #{palavras[:esquema]}: Exemplo #{cont} \n"
|
108
|
-
cont += 1
|
109
|
-
|
110
|
-
# Passos do cenário
|
111
|
-
passos.each do |p|
|
112
|
-
parts = p.strip.split(' ', 2)
|
113
|
-
con_in = detect.find { |k| k.casecmp(parts[0]) == 0 } || parts[0]
|
114
|
-
text = parts[1] || ''
|
115
|
-
out_conn = idioma == 'en' ? pt_map[con_in] || con_in : en_map[con_in] || con_in
|
116
|
-
conteudo << " #{out_conn} #{text}\n"
|
117
|
-
end
|
118
|
-
|
119
|
-
# Bloco de exemplos original
|
120
|
-
conteudo << "\n #{palavras[:exemplos]}:\n"
|
121
|
-
exemplos.select { |l| l.strip.start_with?('|') }.each do |line|
|
122
|
-
cleaned = line.strip.gsub(/^"|"$/, '')
|
123
|
-
conteudo << " #{cleaned}\n"
|
124
|
-
end
|
125
|
-
conteudo << "\n"
|
126
|
-
else
|
127
|
-
# Cenário simples
|
128
|
-
conteudo << " #{tag_line}\n"
|
129
|
-
conteudo << " #{palavras[:cenario]}: #{grupo[:tipo].capitalize}\n"
|
130
|
-
passos.each do |p|
|
131
|
-
parts = p.strip.split(' ', 2)
|
132
|
-
con_in = detect.find { |k| k.casecmp(parts[0]) == 0 } || parts[0]
|
133
|
-
text = parts[1] || ''
|
134
|
-
out_conn = idioma == 'en' ? pt_map[con_in] || con_in : en_map[con_in] || con_in
|
135
|
-
conteudo << " #{out_conn} #{text}\n"
|
136
|
-
end
|
137
|
-
conteudo << "\n"
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
[caminho, conteudo]
|
142
|
-
end
|
143
|
-
|
144
|
-
# Salva o conteúdo gerado em arquivo .feature no disco
|
145
|
-
#
|
146
|
-
# @param caminho [String] Caminho completo para salvar o arquivo
|
147
|
-
# @param conteudo [String] Conteúdo do arquivo .feature
|
148
|
-
# @return [nil]
|
149
|
-
def self.salvar_feature(caminho, conteudo)
|
150
|
-
FileUtils.mkdir_p(File.dirname(caminho))
|
151
|
-
File.write(caminho, conteudo)
|
152
|
-
puts "✅ Arquivo .feature gerado: #{caminho}"
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
data/lib/bddgenx/version.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
module Bddgenx
|
2
|
-
# Sobe 3 níveis: lib/bddgenx/version.rb → bddgenx → lib → [raiz do projeto]
|
3
|
-
VERSION_FILE = File.expand_path("../../../VERSION", __FILE__)
|
4
|
-
|
5
|
-
VERSION = if File.exist?(VERSION_FILE)
|
6
|
-
File.read(VERSION_FILE).strip
|
7
|
-
else
|
8
|
-
warn "WARNING: VERSION file not found, defaulting to 0.0.0"
|
9
|
-
"0.0.0"
|
10
|
-
end
|
11
|
-
end
|