Class: Bddgenx::Setup
- Inherits:
-
Object
- Object
- Bddgenx::Setup
- Defined in:
- lib/bddgenx/setup.rb
Constant Summary collapse
- SPINNER_FRAMES =
%w[⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏].freeze
- SPINNER_DELAY =
0.1
Class Method Summary collapse
- .exemplo_env ⇒ Object
- .exemplo_feature ⇒ Object
- .exemplo_step ⇒ Object
- .exemplo_txt ⇒ Object
- .run ⇒ Object
- .start_spinner(mensagem) ⇒ Object
- .stop_spinner(thread, stop_proc) ⇒ Object
- .verificar(path, is_file: false) ⇒ Object
Class Method Details
.exemplo_env ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/bddgenx/setup.rb', line 157 def self.exemplo_env <<~ENV ############################################ # CONFIGURAÇÃO DE CHAVES DE ACESSO À IA # ############################################ OPENAI_API_KEY={{SUA_CHAVE_OPENAI}} CHATGPT_API_URL={{CHATGPT_API_URL}} ############################################ # CONFIGURAÇÃO DE CHAVES DE URI À IA # ############################################ OPENAI_API_KEY={{SUA_CHAVE_OPENAI}} GEMINI_API_URL={{GEMINI_API_URL}} ############################################ # MODO DE GERAÇÃO DE CENÁRIOS BDD # ############################################ BDDGENX_MODE=static BDDGENX_LANG=pt ENV end |
.exemplo_feature ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/bddgenx/setup.rb', line 99 def self.exemplo_feature <<~FEATURE # language: pt Funcionalidade: que meus clientes efetue login # Como um gerente # Quero que meus clientes efetue login # Para acompanhar o progresso da equipe @success Cenário: Success Quando preencho email e senha válidos Então sou redirecionado para o dashboard @failure Cenário: Failure Quando informo uma senha incorreta Então recebo a mensagem "Credenciais inválidas" @success Esquema do Cenário: Exemplo 1 Quando tento logar com "<email>" e "<senha>" Então recebo "<resultado>" Exemplos: | email | senha | resultado | | [email protected] | 123456 | acesso permitido | | [email protected] | senhaincorreta | acesso negado | FEATURE end |
.exemplo_step ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/bddgenx/setup.rb', line 129 def self.exemplo_step <<~STEP Quando("preencho email e senha válidos") do pending 'Implementar passo: preencho email e senha válidos' end Então("sou redirecionado para o dashboard") do pending 'Implementar passo: sou redirecionado para o dashboard' end Quando("informo uma senha incorreta") do pending 'Implementar passo: informo uma senha incorreta' end Então("recebo a mensagem {string}") do |arg1| pending 'Implementar passo: recebo a mensagem "Credenciais inválidas"' end Quando("tento logar com {string} e {string}") do |arg1, arg2| pending 'Implementar passo: tento logar com "<email>" e "<senha>"' end Então("recebo {string}") do |arg1| pending 'Implementar passo: recebo "<resultado>"' end STEP end |
.exemplo_txt ⇒ Object
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 |
# File 'lib/bddgenx/setup.rb', line 73 def self.exemplo_txt <<~TXT # language: pt Como um gerente Quero que meus clientes efetue login Para acompanhar o progresso da equipe [SUCCESS] Quando preencho email e senha válidos Então sou redirecionado para o dashboard [FAILURE] Quando informo uma senha incorreta Então recebo a mensagem "Credenciais inválidas" [SUCCESS] Quando tento logar com "<email>" e "<senha>" Então recebo "<resultado>" [EXAMPLES] | email | senha | resultado | | [email protected] | 123456 | acesso permitido | | [email protected] | senhaincorreta | acesso negado | TXT end |
.run ⇒ Object
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 |
# File 'lib/bddgenx/setup.rb', line 7 def self.run thread, stop = start_spinner(I18n.t('setup.spinner_checking')) resultados = [] resultados << verificar("input") do File.write('input/historia.txt', exemplo_txt) unless File.exist?('input/historia.txt') end resultados << verificar("features/steps") do File.write('features/exemplo_login.feature', exemplo_feature) unless File.exist?('features/exemplo_login.feature') File.write('features/steps/exemplo_login_steps.rb', exemplo_step) unless File.exist?('features/steps/exemplo_login_steps.rb') end resultados << verificar("reports/pdf") resultados << verificar("reports/backup") resultados << verificar(".env", is_file: true) do File.write('.env', exemplo_env) end stop_spinner(thread, stop) resultados.each { |mensagem| puts mensagem } puts "\n#{I18n.t('setup.success')}" end |
.start_spinner(mensagem) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/bddgenx/setup.rb', line 52 def self.start_spinner(mensagem) done_flag = false thread = Thread.new do i = 0 until done_flag print "\r#{SPINNER_FRAMES[i % SPINNER_FRAMES.size]} #{mensagem}" sleep(SPINNER_DELAY) i += 1 end end [thread, -> { done_flag = true }] end |
.stop_spinner(thread, stop_proc) ⇒ Object
67 68 69 70 71 |
# File 'lib/bddgenx/setup.rb', line 67 def self.stop_spinner(thread, stop_proc) stop_proc.call thread.join print "\r" end |
.verificar(path, is_file: false) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/bddgenx/setup.rb', line 33 def self.verificar(path, is_file: false) if is_file if File.exist?(path) I18n.t('setup.file_exists', path: path) else yield if block_given? I18n.t('setup.file_created', path: path) end else if Dir.exist?(path) I18n.t('setup.dir_exists', path: path) else FileUtils.mkdir_p(path) yield if block_given? I18n.t('setup.dir_created', path: path) end end end |