Best Factory_bot_ruby code snippet using FactoryBot.hash
markov_chain_translator_spec.rb
Source:markov_chain_translator_spec.rb
...201 end202 end203 context "Token Translator & Stitcher" do204 it "should translate token - simple cases" do205 scores_hash = Translation.translate_token('Sodium Chloride')206 expect(scores_hash['SodiumChloride'][:score]).to eq(0)207 expect(scores_hash['SodiumChloride'][:translation]).to eq('ÙÙÙرÙد اÙصÙدÙÙÙ
')208 scores_hash = Translation.translate_token('10grams Mango')209 expect(scores_hash['10'][:score]).to eq(nil)210 expect(scores_hash['grams'][:score]).to eq(0)211 expect(scores_hash['grams'][:translation]).to eq('جراÙ
ات')212 expect(scores_hash['Mango'][:score]).to eq(0)213 expect(scores_hash['Mango'][:translation]).to eq('Ù
اÙجÙ')214 scores_hash = Translation.translate_token('Mango 10grams')215 expect(scores_hash['10'][:score]).to eq(nil)216 expect(scores_hash['grams'][:score]).to eq(0)217 expect(scores_hash['grams'][:translation]).to eq('جراÙ
ات')218 expect(scores_hash['Mango'][:score]).to eq(0)219 expect(scores_hash['Mango'][:translation]).to eq('Ù
اÙجÙ')220 scores_hash = Translation.translate_token('10 grams Mango')221 expect(scores_hash['10'][:score]).to eq(nil)222 expect(scores_hash['grams'][:score]).to eq(0)223 expect(scores_hash['grams'][:translation]).to eq('جراÙ
ات')224 expect(scores_hash['Mango'][:score]).to eq(0)225 expect(scores_hash['Mango'][:translation]).to eq('Ù
اÙجÙ')226 scores_hash = Translation.translate_token('Mango 10 grams')227 expect(scores_hash['10'][:score]).to eq(nil)228 expect(scores_hash['grams'][:score]).to eq(0)229 expect(scores_hash['grams'][:translation]).to eq('جراÙ
ات')230 expect(scores_hash['Mango'][:score]).to eq(0)231 expect(scores_hash['Mango'][:translation]).to eq('Ù
اÙجÙ')232 end233 it "should translate token" do234 scores_hash = Translation.translate_token('10 grams of Sodium Chloride')235 expect(scores_hash['10'][:score]).to eq(nil)236 237 expect(scores_hash['grams'][:score]).to eq(0)238 expect(scores_hash['grams'][:translation]).to eq('جراÙ
ات')239 240 expect(scores_hash['SodiumChloride'][:score]).to eq(0)241 expect(scores_hash['SodiumChloride'][:translation]).to eq('ÙÙÙرÙد اÙصÙدÙÙÙ
')242 scores_hash = Translation.translate_token('ButtermilkPowder', output_language: "FRENCH")243 expect(scores_hash['ButtermilkPowder'][:score]).to eq(0)244 expect(scores_hash['ButtermilkPowder'][:translation]).to eq("Poudre de papillon")245 end246 it "should stitch scores back" do247 scores = { "10"=>{:score=>nil},248 "grams"=>{:score=>0, :translation=>"جراÙ
ات"},249 "of"=>{:score=>0, :translation=>"Ù
Ù"},250 "SodiumChloride"=>{:score=>0, :translation=>"ÙÙÙرÙد اÙصÙدÙÙÙ
"}251 }252 expect(Translation.stitch_token(scores)).to eq('ÙÙÙرÙد اÙصÙدÙÙÙ
Ù
٠جراÙ
ات 10')253 end254 end255 context "Translate with Score" do256 it "should translate a single word from english to arabic " do257 expect(Translation.translate_word_with_score('Apple')[:translation]).to eq('تÙاØØ©')258 expect(Translation.translate_word_with_score('Mango')[:translation]).to eq('Ù
اÙجÙ')259 expect(Translation.translate_word_with_score('Grapes')[:translation]).to eq('اÙعÙب')260 expect(Translation.translate_word_with_score('No Word').try(:[], :translation)).to eq(nil)261 expect(Translation.translate_word_with_score('Apple', input_language: "ENGLISH", output_language: "ARABIC")[:translation]).to eq('تÙاØØ©')262 expect(Translation.translate_word_with_score('Mango', input_language: "ENGLISH", output_language: "ARABIC")[:translation]).to eq('Ù
اÙجÙ')263 expect(Translation.translate_word_with_score('Grapes', input_language: "ENGLISH", output_language: "ARABIC")[:translation]).to eq('اÙعÙب')264 expect(Translation.translate_word_with_score('No Word', input_language: "ENGLISH", output_language: "ARABIC")[:translation]).to eq(nil)265 end266 it "should translate a single word from english to french " do267 expect(Translation.translate_word_with_score('Apple', input_language: "ENGLISH", output_language: "FRENCH")[:translation]).to eq('Pomme')268 expect(Translation.translate_word_with_score('Mango', input_language: "ENGLISH", output_language: "FRENCH")[:translation]).to eq('Mangue')269 expect(Translation.translate_word_with_score('Grapes', input_language: "ENGLISH", output_language: "FRENCH")[:translation]).to eq('Les Raisins')270 expect(Translation.translate_word_with_score('No Word', input_language: "ENGLISH", output_language: "FRENCH")[:translation]).to eq(nil)271 end272 273 it "should translate a single word from arabic to english" do274 expect(Translation.translate_word_with_score('تÙاØØ©', input_language: "ARABIC", output_language: "ENGLISH")[:translation]).to eq('Apple')275 expect(Translation.translate_word_with_score('Ù
اÙجÙ', input_language: "ARABIC", output_language: "ENGLISH")[:translation]).to eq('Mango')276 expect(Translation.translate_word_with_score('اÙعÙب', input_language: "ARABIC", output_language: "ENGLISH")[:translation]).to eq('Grapes')277 expect(Translation.translate_word_with_score('No Word', input_language: "ARABIC", output_language: "ENGLISH")[:translation]).to eq(nil)278 end279 it "should translate a single word from arabic to french" do280 expect(Translation.translate_word_with_score('تÙاØØ©', input_language: "ARABIC", output_language: "FRENCH")[:translation]).to eq('Pomme')281 expect(Translation.translate_word_with_score('Ù
اÙجÙ', input_language: "ARABIC", output_language: "FRENCH")[:translation]).to eq('Mangue')282 expect(Translation.translate_word_with_score('اÙعÙب', input_language: "ARABIC", output_language: "FRENCH")[:translation]).to eq('Les Raisins')283 expect(Translation.translate_word_with_score('بببب', input_language: "ARABIC", output_language: "FRENCH")[:translation]).to eq(nil)284 end285 it "should translate a single word from french to english " do286 expect(Translation.translate_word_with_score('Pomme', input_language: "FRENCH", output_language: "ENGLISH")[:translation]).to eq('Apple')287 expect(Translation.translate_word_with_score('Mangue', input_language: "FRENCH", output_language: "ENGLISH")[:translation]).to eq('Mango')288 expect(Translation.translate_word_with_score('Les Raisins', input_language: "FRENCH", output_language: "ENGLISH")[:translation]).to eq('Grapes')289 expect(Translation.translate_word_with_score('No Word', input_language: "FRENCH", output_language: "ENGLISH")[:translation]).to eq(nil)290 end291 it "should translate a single word from french to arabic " do292 expect(Translation.translate_word_with_score('Pomme', input_language: "FRENCH", output_language: "ARABIC")[:translation]).to eq('تÙاØØ©')293 expect(Translation.translate_word_with_score('Mangue', input_language: "FRENCH", output_language: "ARABIC")[:translation]).to eq('Ù
اÙجÙ')294 expect(Translation.translate_word_with_score('Les Raisins', input_language: "FRENCH", output_language: "ARABIC")[:translation]).to eq('اÙعÙب')295 expect(Translation.translate_word_with_score('No Word', input_language: "FRENCH", output_language: "ARABIC")[:translation]).to eq(nil)296 end297 end298 context "Simple Translations" do299 it "should translate units properly" do300 expect(Translation.translate_word_from_database('grams')).to eq('جراÙ
ات')301 expect(Translation.translate_word_with_score('grams')[:translation]).to eq('جراÙ
ات')302 expect(Translation.translate('10 grams Sodium Chloride')).to eq('ÙÙÙرÙد اÙصÙدÙÙÙ
جراÙ
ات 10')303 expect(Translation.translate('10 grams of Sodium Chloride')).to eq('ÙÙÙرÙد اÙصÙدÙÙÙ
Ù
٠جراÙ
ات 10')304 end305 it "should translate conjunctions properly" do306 expect(Translation.translate_word_from_database('or')).to eq('Ø£Ù')307 expect(Translation.translate_word_with_score('or')[:translation]).to eq('Ø£Ù')308 end309 310 it "should translate simple words" do311 expect(Translation.translate('Apple')).to eq('تÙاØØ©')312 expect(Translation.translate('Mango')).to eq('Ù
اÙجÙ')313 expect(Translation.translate('Grapes')).to eq('اÙعÙب')314 end315 it "should translate simple words with units" do316 skip317 expect(Translation.translate('10kg Apple')).to eq('تÙاØØ©')318 expect(Translation.translate('Apple 10kg')).to eq('تÙاØØ©')319 expect(Translation.translate('10 kg Apple')).to eq('تÙاØØ©')320 expect(Translation.translate('Apple 10 kilogram')).to eq('تÙاØØ©')321 expect(Translation.translate('Apple (10kg)')).to eq('اÙتÙØ§Ø (10 ÙجÙ
)')322 end323 it "should translate simple words with conjunctions" do324 expect(Translation.translate('Apple and Mango')).to eq('Ù
اÙج٠٠تÙاØØ©')325 expect(Translation.translate('Apple or Mango')).to eq('Ù
اÙج٠أ٠تÙاØØ©')326 expect(Translation.translate('Milk with Apple')).to eq('ØÙÙب باÙتÙاØ')327 end328 it "should handle words not in database " do329 expect(Translation.translate('No Word')).to eq("No Word")330 expect(Translation.translate('Hello World', input_language: "ENGLISH", output_language: "ARABIC")).to eq('Hello World')331 expect(Translation.translate('No Word', input_language: "ENGLISH", output_language: "FRENCH")).to eq('No Word')332 expect(Translation.translate('XXX', input_language: "FRENCH", output_language: "ENGLISH")).to eq('XXX')333 expect(Translation.translate('بببب', input_language: "ARABIC", output_language: "ENGLISH")).to eq('بببب')334 end335 it "should handle case differences" do336 expect(Translation.translate('APPLE')).to eq('تÙاØØ©')337 expect(Translation.translate('apple')).to eq('تÙاØØ©')338 expect(Translation.translate('AppLE')).to eq('تÙاØØ©')339 expect(Translation.translate('SODIUM CHORIDE')).to eq('ÙÙÙرÙد اÙصÙدÙÙÙ
')340 expect(Translation.translate('sodium chloride')).to eq('ÙÙÙرÙد اÙصÙدÙÙÙ
')341 expect(Translation.translate('SODIUM Chloride')).to eq('ÙÙÙرÙد اÙصÙدÙÙÙ
')342 expect(Translation.translate('sodlium CHLORIDE')).to eq('ÙÙÙرÙد اÙصÙدÙÙÙ
')343 expect(Translation.translate('SoDiUm ChLoRiDe')).to eq('ÙÙÙرÙد اÙصÙدÙÙÙ
')344 end345 it "should handle missing characters" do346 expect(Translation.translate('AplE')).to eq('تÙاØØ©')347 expect(Translation.translate('Appl')).to eq('تÙاØØ©')348 expect(Translation.translate('SoDUM CHlORiDE')).to eq('ÙÙÙرÙد اÙصÙدÙÙÙ
')349 expect(Translation.translate('soium chloride')).to eq('ÙÙÙرÙد اÙصÙدÙÙÙ
')350 expect(Translation.translate('SODIUM Chlorde')).to eq('ÙÙÙرÙد اÙصÙدÙÙÙ
')351 expect(Translation.translate('sodliam CHLORIDE')).to eq('ÙÙÙرÙد اÙصÙدÙÙÙ
')352 expect(Translation.translate('SoDiem ChLaRiDe')).to eq('ÙÙÙرÙد اÙصÙدÙÙÙ
')353 end354 it "should handle percentages and commas" do355 output = Translation.translate_paragraph('Mango (10%)')356 words = Translation.tokenize('Mango (10%)')357 hash = Translation.translate_words(words)358 end359 end360 context "Basic Translations" do361 it "should translate an array of words" do362 # Arabic363 expect(Translation.translate_words(['Apple', 'Mango'])).to include(364 "Apple" => 'تÙاØØ©',365 "Mango" => 'Ù
اÙجÙ',366 )367 expect(Translation.translate_words(['Grapes', 'Mango'])).to include(368 "Grapes" => 'اÙعÙب',369 "Mango" => 'Ù
اÙجÙ',370 )371 expect(Translation.translate_words(['Grapes', 'No Word'])).to include(372 "Grapes" => 'اÙعÙب',373 "No Word" => nil,374 )375 # French376 expect(Translation.translate_words(['Apple', 'Mango'], output_language: "FRENCH")).to include(377 "Apple" => 'Pomme',378 "Mango" => 'Mangue',379 )380 expect(Translation.translate_words(['Grapes', 'Mango'], output_language: "FRENCH")).to include(381 "Grapes" => 'Les Raisins',382 "Mango" => 'Mangue',383 )384 expect(Translation.translate_words(['Grapes', 'No Word'], output_language: "FRENCH")).to include(385 "Grapes" => 'Les Raisins',386 "No Word" => nil,387 )388 end389 it "should translate a paragraph" do390 # input_paragraph = %{391 # CORN, VEGETABLE OILS, CHEESE POWDER (MILK), SALT,392 # BUTTERMILK POWDER (MILK), WHEAT FLOUR, WHEY PROTEIN, 393 # CONCENTRATE (MILK), TOMATO POWDER, FLAVOUR ENHANCERS, 394 # (621,631,627),ONION POWDER, WHEY POWDER (MILK), 395 # GARLIC POWDER, DEXTROSE, SUGAR, NATURAL FLAVOUR, 396 # MINIERAL, SALT (339), FOOD ACIDS (LACTIC ACID, CITRIC ACID), 397 # SPICE (WHITEPEPPER), COLOURS (110, 150D).398 # }399 # input_paragraph = "Corn, Vegetable Oils, Cheese Powder (Milk), Salt, Buttermilk Powder (Milk), Wheat Flour, Whey Protein, Concentrate (Milk), Tomato Powder, Flavour Enhancers, (621,631,627), Onion Powder, Whey Powder (Milk), Garlic Powder, Dextrose, Sugar, NAtural Flavour, Mineral, Salt (339), Food Acids (Lactic Acid, Citric Acid), Spice (Whitepepper), Colours (110, 150D)."400 # expect(Translation.translate_paragraph(input_paragraph, return_in_hash: true, output_language: "FRENCH")).to include(401 # "Corn" => "blé",402 # "," => nil,403 # "" => "",404 # "Vegetable Oils" => "Les Huiles végétales",405 # "Cheese Powder" => "Poudre de fromage",406 # "(" => nil,407 # "Milk" => "Lait",408 # ")" => nil,409 # "Salt" => "Sel",410 # "Buttermilk Powder" => "Poudre de papillon",411 # "Wheat Flour" => "Farine de blé",412 # "Whey Protein" => "Protéine de whey",413 # "Concentrate" => "Concentrer",414 # "Tomato Powder" => "Poudre de tomate",415 # "Flavour Enhancers" => "Exhausteurs de goût",416 # "621" => nil,417 # "631" => nil,418 # "627" => nil,419 # "Onion Powder" => "Poudre d'oignon",420 # "Whey Powder" => "La poudre de lactosérum",421 # "Garlic Powder" => "Poudre d'ail",422 # "Dextrose" => "Dextrose",423 # "Sugar" => "Sucre",424 # "NAtural Flavour" => "Saveur naturelle",425 # "Mineral" => "Minéral",426 # "339" => nil,427 # "Food Acids" => "Acides alimentaires",428 # "Lactic Acid" => "Acide lactique",429 # "Citric Acid" => "Acide citrique",430 # "Spice" => "Pimenter",431 # "Whitepepper" => "Poivre blanc",432 # "Colours" => "Couleurs",433 # "110" => nil,434 # "150D" => nil,435 # "." => nil436 # )437 # Trying out Capital Letters438 input_paragraph = "CORN, VEGETABLE OILS, CHEESE POWDER (MILK), SALT, BUTTERMILK POWDER (MILK), WHEAT FLOUR, WHEY PROTEIN, CONCENTRATE (MILK), TOMATO POWDER, FLAVOUR ENHANCERS, (621,631,627),ONION POWDER, WHEY POWDER (MILK), GARLIC POWDER, DEXTROSE, SUGAR, NATURAL FLAVOUR, MINIERAL, SALT (339), FOOD ACIDS (LACTIC ACID, CITRIC ACID), SPICE (WHITEPEPPER), COLOURS (110, 150D)."439 # expect(Translation.translate_paragraph(input_paragraph, return_in_hash: true, output_language: "FRENCH")).to include(440 # "CORN" => 'blé',441 # "COLOURS" => 'Couleurs',442 # )443 # output_paragraph = %{444 # blé, Les Huiles végétales, Poudre de fromage (Lait), Sel,445 # BUTTERLait POWDER (Lait), Farine de blé, Protéine de whey,446 # Concentrer (Lait), Poudre de tomate, Exhausteurs de goût,447 # (621,631,627),Poudre d'oignon, La poudre de lactosérum (Lait),448 # Poudre d'ail, Dextrose, Sucre, Saveur naturelle,449 # Minéral, Sel (339), Acides alimentaires (Acide lactique, Acide citrique),450 # Pimenter (Poivre blanc), Couleurs (110, 150D).451 # }452 #actual_output_to_be = "blé, Les Huiles végétales, Poudre de fromage (Lait), Sel, Poudre de papillon (Lait), Farine de blé, Protéine de whey, Concentrer (Lait), Poudre de tomate, Exhausteurs de goût, (621,631,627), Poudre d'oignon, La poudre de lactosérum (Lait), Poudre d'ail, Dextrose, Sucre, Saveur naturelle, Minéral, Sel (339), Acides alimentaires (Acide lactique, Acide citrique), Pimenter (Poivre blanc), Couleurs (110, 150D)."453 desired_output = "blé, Les Huiles végétales, Poudre de fromage (Lait), Sel, Poudre de papillon (Lait), Farine de blé, Protéine de whey, Concentrer (Lait), Poudre de tomate, Exhausteurs de goût, (621,631,627), Poudre d'oignon, La poudre de lactosérum (Lait), Poudre d'ail, Dextrose, Sucre, Saveur naturelle, Minéral, SALT (339), Acides alimentaires (Acide lactique, Acide citrique), Pimenter (Poivre blanc), Couleurs (110, 150D)."454 real_output = Translation.translate_paragraph(input_paragraph, output_language: "FRENCH")455 expect(desired_output).to eq(real_output)456 end457 it "should translate anything" do458 459 # Arabic460 expect(Translation.translate('Apple')).to eq('تÙاØØ©')461 expect(Translation.translate('Mango')).to eq('Ù
اÙجÙ')462 expect(Translation.translate('Grapes')).to eq('اÙعÙب')463 expect(Translation.translate('No Word')).to eq("No Word")464 expect(Translation.translate(['Apple', 'Mango'])).to include(465 "Apple" => 'تÙاØØ©',466 "Mango" => 'Ù
اÙجÙ',467 )468 expect(Translation.translate(['Grapes', 'Mango'])).to include(469 "Grapes" => 'اÙعÙب',470 "Mango" => 'Ù
اÙجÙ',471 )472 expect(Translation.translate(['Grapes', 'No Word'])).to include(473 "Grapes" => 'اÙعÙب',474 "No Word" => nil,475 )476 # French477 expect(Translation.translate('Apple', output_language: "FRENCH")).to eq('Pomme')478 expect(Translation.translate('Mango', output_language: "FRENCH")).to eq('Mangue')479 expect(Translation.translate('Grapes', output_language: "FRENCH")).to eq('Les Raisins')480 expect(Translation.translate('No Word', output_language: "FRENCH")).to eq("No Word")481 expect(Translation.translate(['Apple', 'Mango'], output_language: "FRENCH")).to include(482 "Apple" => 'Pomme',483 "Mango" => 'Mangue',484 )485 expect(Translation.translate(['Grapes', 'Mango'], output_language: "FRENCH")).to include(486 "Grapes" => 'Les Raisins',487 "Mango" => 'Mangue',488 )489 expect(Translation.translate(['Grapes', 'No Word'], output_language: "FRENCH")).to include(490 "Grapes" => 'Les Raisins',491 "No Word" => nil,492 )493 end494 end495 context "HTML Translations" do496 it "should translate html input" do497 input_html = %{ <div><span>10g</span></div>}498 output_html = %{ <div><span>10غ</span></div>}499 translated_html = Translation.translate_html(input_html, input_language: "ENGLISH", output_language: "ARABIC").to_html500 expect(translated_html).not_to be_empty501 expect(translated_html).to include('10غ')502 input_html = %{ <div><span>10gm</span></div>}503 output_html = %{ <div><span>10جÙ
</span></div>}504 translated_html = Translation.translate_html(input_html, input_language: "ENGLISH", output_language: "ARABIC").to_html505 expect(translated_html).not_to be_empty506 expect(translated_html).to include('10جÙ
')507 input_html = %{ <div><span>10grams</span></div>}508 output_html = %{ <div><span>10جراÙ
ات</span></div>}509 translated_html = Translation.translate_html(input_html, input_language: "ENGLISH", output_language: "ARABIC").to_html510 expect(translated_html).not_to be_empty511 expect(translated_html).to include('10جراÙ
ات')512 input_html = %{ <div><span>1gram</span></div>}513 output_html = %{ <div><span>1غراÙ
</span></div>}514 translated_html = Translation.translate_html(input_html, input_language: "ENGLISH", output_language: "ARABIC").to_html515 expect(translated_html).not_to be_empty516 expect(translated_html).to include('1غراÙ
')517 end518 xit "should translate html input" do519 input_html = %{ <html dir="ltr" lang="en"><head><title data-cke-title="Rich Text Editor, ckeditor">Rich Text Editor, ckeditor</title></head><body contenteditable="true" class="cke_editable cke_editable_themed cke_contents_ltr cke_show_borders" spellcheck="false"><table class=" cke_show_border"><thead><tr><th>INGREDIENTS</th></tr></thead><tbody><tr><td style="text-align:center">CORN, VEGETABLE OILS, CHEESE POWDER (MILK), SALT,BUTTERMILK POWDER (MILK), WHEAT FLOUR, WHEY PROTEIN, CONCENTRATE (MILK), TOMATO POWDER, FLAVOUR ENHANCERS, (621,631,627),ONION POWDER, WHEY POWDER (MILK), GARLIC POWDER, DEXTROSE, SUGAR, NATURAL FLAVOUR, MINIERAL, SALT (339), FOOD ACIDS (LACTIC ACID, CITRIC ACID), SPICE (WHITEPEPPER), COLOURS (110, 150D).</td></tr></tbody></table></body></html>}520 output_html = %{ <html dir="ltr" lang="en"><head><title data-cke-title="Rich Text Editor, ckeditor">Rich Text Editor, ckeditor</title></head><body contenteditable="true" class="cke_editable cke_editable_themed cke_contents_ltr cke_show_borders" spellcheck="false"><table class=" cke_show_border"><thead><tr><th>INGREDIENTS</th></tr></thead><tbody><tr><td style="text-align:center">blé, Les Huiles végétales, Poudre de fromage (Lait), Sel,BUTTERLait POWDER (Lait), Farine de blé, Protéine de whey, Concentrer (Lait), Poudre de tomate, Exhausteurs de goût, (621,631,627),Poudre d'oignon, La poudre de lactosérum (Lait), Poudre d'ail, Dextrose, Sucre, Saveur naturelle, Minéral, Sel (339), Acides alimentaires (Acide lactique, Acide citrique), Pimenter (Poivre blanc), Couleurs (110, 150D).</td></tr></tbody></table></body></html>}521 translated_html = Translation.translate_html(input_html, output_language: "FRENCH")522 expect(translated_html).not_to be_empty523 expect(translated_html).to include('blé')524 expect(translated_html).to include('Couleurs')525 expect(translated_html).to include('Poudre de fromage')526 expect(translated_html).to include('Lait')527 expect(translated_html).to include('(Poivre blanc)')528 end529 end530 context "Translation with Basic Delimitters" do531 it "should translate commas and 'and'" do532 # English to Arabic533 expect(Translation.translate('Apple, Mango and Grapes.', return_in_hash: true)).to include(534 "Apple" => 'تÙاØØ©',535 "," => 'Ø',536 "Mango" => 'Ù
اÙجÙ',537 "and" => 'Ù',538 "Grapes" => 'اÙعÙب',539 "." => '.',540 )541 # English to French542 expect(Translation.translate('Apple, Mango and Grapes.', input_language: "ENGLISH", output_language: "FRENCH", return_in_hash: true)).to include(543 "Apple" => 'Pomme',544 "," => ',',545 "Mango" => 'Mangue',546 "and" => 'et',547 "Grapes" => 'Les Raisins',548 "." => '.',549 )550 FactoryBot.create(:arabic_to_english_translation, input_phrase: "تÙاØØ©", output_phrase: "Apple")551 FactoryBot.create(:arabic_to_english_translation, input_phrase: "Ù
اÙج", output_phrase: "Mango")552 FactoryBot.create(:arabic_to_english_translation, input_phrase: "عÙب", output_phrase: "Grapes")553 # Arabic to English554 expect(Translation.translate('تÙاØØ© Ø Ù
اÙج ٠عÙب.', input_language: "ARABIC", output_language: "ENGLISH", return_in_hash: true)).to include(555 "تÙاØØ©" => 'Apple',556 "Ø" => ',',557 "Ù
اÙج" => 'Mango',558 "Ù" => 'and',559 "عÙب" => 'Grapes',560 "." => '.',561 )562 FactoryBot.create(:arabic_to_french_translation, input_phrase: "تÙاØØ©", output_phrase: "Pomme")563 FactoryBot.create(:arabic_to_french_translation, input_phrase: "Ù
اÙج", output_phrase: "Mangue")564 FactoryBot.create(:arabic_to_french_translation, input_phrase: "عÙب", output_phrase: "Les Raisins")565 # # Arabic to French566 expect(Translation.translate('تÙاØØ© Ø Ù
اÙج ٠عÙب.', input_language: "ARABIC", output_language: "FRENCH", return_in_hash: true)).to include(567 "تÙاØØ©" => 'Pomme',568 "Ø" => ',',569 "Ù
اÙج" => 'Mangue',570 "Ù" => 'et',571 "عÙب" => 'Les Raisins',572 "." => '.',573 )574 end575 it "should translate ingredient weights in multiple formats - Part 2" do576 # English to Arabic577 expect(Translation.translate('12.500gm Apple, 12.5gm Mango and 1gm Grapes.', return_in_hash: true)).to include(578 "12.500gm" => "جÙ
12.500",579 "Apple" => 'تÙاØØ©',580 "12.5gm" => "جÙ
12.5",581 "Mango" => 'Ù
اÙجÙ',582 "1gm" => "جÙ
1",583 "," => 'Ø',584 "and" => 'Ù',585 "Grapes" => 'اÙعÙب',586 "." => '.',587 )588 # # English to French589 # expect(Translation.translate('Apple, Mango and Grapes.', input_language: "ENGLISH", output_language: "FRENCH", return_in_hash: true)).to include(590 # "Apple" => 'Pomme',591 # "," => ',',592 # "Mango" => 'Mangue',593 # "and" => 'et',594 # "Grapes" => 'Les Raisins',595 # "." => '.',596 # )597 # FactoryBot.create(:arabic_to_english_translation, input_phrase: "تÙاØØ©", output_phrase: "Apple")598 # FactoryBot.create(:arabic_to_english_translation, input_phrase: "Ù
اÙج", output_phrase: "Mango")599 # FactoryBot.create(:arabic_to_english_translation, input_phrase: "عÙب", output_phrase: "Grapes")600 # # Arabic to English601 # expect(Translation.translate('تÙاØØ© Ø Ù
اÙج ٠عÙب.', input_language: "ARABIC", output_language: "ENGLISH", return_in_hash: true)).to include(602 # "تÙاØØ©" => 'Apple',603 # "Ø" => ',',604 # "Ù
اÙج" => 'Mango',605 # "Ù" => 'and',606 # "عÙب" => 'Grapes',607 # "." => '.',608 # )609 # FactoryBot.create(:arabic_to_french_translation, input_phrase: "تÙاØØ©", output_phrase: "Pomme")610 # FactoryBot.create(:arabic_to_french_translation, input_phrase: "Ù
اÙج", output_phrase: "Mangue")611 # FactoryBot.create(:arabic_to_french_translation, input_phrase: "عÙب", output_phrase: "Les Raisins")612 # # # Arabic to French613 # expect(Translation.translate('تÙاØØ© Ø Ù
اÙج ٠عÙب.', input_language: "ARABIC", output_language: "FRENCH", return_in_hash: true)).to include(614 # "تÙاØØ©" => 'Pomme',615 # "Ø" => ',',616 # "Ù
اÙج" => 'Mangue',617 # "Ù" => 'et',618 # "عÙب" => 'Les Raisins',619 # "." => '.',620 # )621 end622 end623end624# Input text for reference625# اÙتÙØ§Ø ÙاÙÙ
اÙج٠ÙاÙعÙب.626# English Example627# ---------------...
creds_spec.rb
Source:creds_spec.rb
...148 context 'with an invalid type' do149 it 'should print the list of valid types' do150 creds.cmd_creds('-t', 'asdf')151 expect(@error).to match_array [152 'Unrecognized credential type asdf -- must be one of password,ntlm,hash'153 ]154 end155 end156 context 'with valid types' do157 let(:ntlm_hash) { '1443d06412d8c0e6e72c57ef50f76a05:27c433245e4763d074d30a05aae0af2c' }158 let!(:pub) do159 FactoryBot.create(:metasploit_credential_username, username: username)160 end161 let!(:password_core) do162 priv = FactoryBot.create(:metasploit_credential_password, data: password)163 FactoryBot.create(:metasploit_credential_core,164 origin: FactoryBot.create(:metasploit_credential_origin_import),165 private: priv,166 public: pub,167 realm: nil,168 workspace: framework.db.workspace)169 end170 # # Somehow this is hitting a unique constraint on Cores with the same171 # # Public, even though it has a different Private. Skip for now172 # let!(:ntlm_core) do173 # priv = FactoryBot.create(:metasploit_credential_ntlm_hash, data: ntlm_hash)174 # FactoryBot.create(:metasploit_credential_core,175 # origin: FactoryBot.create(:metasploit_credential_origin_import),176 # private: priv,177 # public: pub,178 # realm: nil,179 # workspace: framework.db.workspace)180 # end181 # let!(:nonreplayable_core) do182 # priv = FactoryBot.create(:metasploit_credential_nonreplayable_hash, data: 'asdf')183 # FactoryBot.create(:metasploit_credential_core,184 # origin: FactoryBot.create(:metasploit_credential_origin_import),185 # private: priv,186 # public: pub,187 # realm: nil,188 # workspace: framework.db.workspace)189 # end190 after(:example) do191 # ntlm_core.destroy192 password_core.destroy193 # nonreplayable_core.destroy194 end195 context 'password' do196 it 'should show just the password' do197 creds.cmd_creds('-t', 'password')198 # Table matching really sucks199 expect(@output).to eq([200 'Credentials',201 '===========',202 '',203 'host origin service public private realm private_type',204 '---- ------ ------- ------ ------- ----- ------------',205 ' thisuser thispass Password'206 ])207 end208 end209 context 'ntlm' do210 it 'should show just the ntlm' do211 skip 'Weird uniqueness constraint on Core (workspace_id, public_id)'212 creds.cmd_creds('-t', 'ntlm')213 # Table matching really sucks214 expect(@output).to =~ [215 'Credentials',216 '===========',217 '',218 'host service public private realm private_type',219 '---- ------- ------ ------- ----- ------------',220 " thisuser #{ntlm_hash} NTLM hash"221 ]222 end223 end224 end225 end226 end227 describe 'Adding' do228 let(:pub) { FactoryBot.create(:metasploit_credential_username, username: username) }229 let(:priv) { FactoryBot.create(:metasploit_credential_password, data: password) }230 let(:r) { FactoryBot.create(:metasploit_credential_realm, key: realm_type, value: realm) }231 context 'Cores with public privates and realms' do232 context 'username password and realm' do233 it 'creates a core if one does not exist' do234 expect {235 creds.cmd_creds('add', "user:#{username}", "password:#{password}", "realm:#{realm}")236 }.to change { Metasploit::Credential::Core.count }.by 1237 end238 it 'does not create a core if it already exists' do239 FactoryBot.create(:metasploit_credential_core,240 origin: FactoryBot.create(:metasploit_credential_origin_import),241 private: priv,242 public: pub,243 realm: r,244 workspace: framework.db.workspace)245 expect {246 creds.cmd_creds('add', "user:#{username}", "password:#{password}", "realm:#{realm}")247 }.to_not change { Metasploit::Credential::Core.count }248 end249 end250 context 'username and realm' do251 it 'creates a core if one does not exist' do252 expect {253 creds.cmd_creds('add', "user:#{username}", "realm:#{realm}")254 }.to change { Metasploit::Credential::Core.count }.by 1255 end256 it 'does not create a core if it already exists' do257 FactoryBot.create(:metasploit_credential_core,258 origin: FactoryBot.create(:metasploit_credential_origin_import),259 private: nil,260 public: pub,261 realm: r,262 workspace: framework.db.workspace)263 expect {264 creds.cmd_creds('add', "user:#{username}", "realm:#{realm}")265 }.to_not change { Metasploit::Credential::Core.count }266 end267 end268 context 'username and password' do269 it 'creates a core if one does not exist' do270 expect {271 creds.cmd_creds('add', "user:#{username}", "password:#{password}")272 }.to change { Metasploit::Credential::Core.count }.by 1273 end274 it 'does not create a core if it already exists' do275 FactoryBot.create(:metasploit_credential_core,276 origin: FactoryBot.create(:metasploit_credential_origin_import),277 private: priv,278 public: pub,279 realm: nil,280 workspace: framework.db.workspace)281 expect {282 creds.cmd_creds('add', "user:#{username}", "password:#{password}")283 }.to_not change { Metasploit::Credential::Core.count }284 end285 end286 context 'password and realm' do287 it 'creates a core if one does not exist' do288 expect {289 creds.cmd_creds('add', "password:#{password}", "realm:#{realm}")290 }.to change { Metasploit::Credential::Core.count }.by 1291 end292 it 'does not create a core if it already exists' do293 FactoryBot.create(:metasploit_credential_core,294 origin: FactoryBot.create(:metasploit_credential_origin_import),295 private: priv,296 public: nil,297 realm: r,298 workspace: framework.db.workspace)299 expect {300 creds.cmd_creds('add', "password:#{password}", "realm:#{realm}")301 }.to_not change { Metasploit::Credential::Core.count }302 end303 end304 context 'username' do305 it 'creates a core if one does not exist' do306 expect {307 creds.cmd_creds('add', "user:#{username}")308 }.to change { Metasploit::Credential::Core.count }.by 1309 end310 it 'does not create a core if it already exists' do311 FactoryBot.create(:metasploit_credential_core,312 origin: FactoryBot.create(:metasploit_credential_origin_import),313 private: nil,314 public: pub,315 realm: nil,316 workspace: framework.db.workspace)317 expect {318 creds.cmd_creds('add', "user:#{username}")319 }.to_not change { Metasploit::Credential::Core.count }320 end321 end322 context 'private_types' do323 context 'password' do324 it 'creates a core if one does not exist' do325 expect {326 creds.cmd_creds('add', "password:#{password}")327 }.to change { Metasploit::Credential::Core.count }.by 1328 end329 it 'does not create a core if it already exists' do330 FactoryBot.create(:metasploit_credential_core,331 origin: FactoryBot.create(:metasploit_credential_origin_import),332 private: priv,333 public: nil,334 realm: nil,335 workspace: framework.db.workspace)336 expect {337 creds.cmd_creds('add', "password:#{password}")338 }.to_not change { Metasploit::Credential::Core.count }339 end340 end341 context 'ntlm' do342 let(:priv) { FactoryBot.create(:metasploit_credential_ntlm_hash) }343 it 'creates a core if one does not exist' do344 expect {345 creds.cmd_creds('add', "ntlm:#{priv.data}")346 }.to change { Metasploit::Credential::Core.count }.by 1347 end348 it 'does not create a core if it already exists' do349 FactoryBot.create(:metasploit_credential_core,350 origin: FactoryBot.create(:metasploit_credential_origin_import),351 private: priv,352 public: nil,353 realm: nil,354 workspace: framework.db.workspace)355 expect {356 creds.cmd_creds('add', "ntlm:#{priv.data}")357 }.to_not change { Metasploit::Credential::Core.count }358 end359 end360 context 'hash' do361 let(:priv) { FactoryBot.create(:metasploit_credential_nonreplayable_hash) }362 it 'creates a core if one does not exist' do363 expect {364 creds.cmd_creds('add', "hash:#{priv.data}")365 }.to change { Metasploit::Credential::Core.count }.by 1366 end367 it 'does not create a core if it already exists' do368 FactoryBot.create(:metasploit_credential_core,369 origin: FactoryBot.create(:metasploit_credential_origin_import),370 private: priv,371 public: nil,372 realm: nil,373 workspace: framework.db.workspace)374 expect {375 creds.cmd_creds('add', "hash:#{priv.data}")376 }.to_not change { Metasploit::Credential::Core.count }377 end378 end379 context 'ssh-key' do380 let(:priv) { FactoryBot.create(:metasploit_credential_ssh_key) }381 before(:each) do382 @file = Tempfile.new('id_rsa')383 @file.write(priv.data)384 @file.close385 end386 it 'creates a core if one does not exist' do387 expect {388 creds.cmd_creds('add', "user:#{username}", "ssh-key:#{@file.path}")389 }.to change { Metasploit::Credential::Core.count }.by 1...
hash
Using AI Code Generation
1 name { Faker::Name.name }2 email { Faker::Internet.email }3 password { Faker::Internet.password }4 name { Faker::Name.name }5 email { Faker::Internet.email }6 password { Faker::Internet.password }7 name { Faker::Name.name }8 email { Faker::Internet.email }9 password { Faker::Internet.password }10 name { Faker::Name.name }11 email { Faker::Internet.email }12 password { Faker::Internet.password }13 name { Faker::Name.name }14 email { Faker::Internet.email }15 password { Faker::Internet.password }16 name { Faker::Name.name }17 email { Faker::Internet.email }18 password { Faker::Internet.password }19 name { Faker::Name.name }20 email { Faker::Internet.email }21 password { Faker::Internet.password }22 name { Faker::Name.name }23 email { Faker::Internet.email }
hash
Using AI Code Generation
1 name { "John" }2 age { 20 }3 name { "John" }4 age { 20 }5 after(:create) do |user|6 create(:account, user: user)7 name { "John" }8 age { 20 }9 after(:create) do |user|10 create(:account, user: user)11 after(:create) do |user|12 create_list(:post, 3, user: user)13 name { "John" }14 age { 20 }15 after(:create) do |user|16 create(:account, user: user)17 after(:create) do |user|18 create_list(:post, 3, user: user)19 after(:create) do |user|20 create_list(:comment, 3, user: user)21 name { "John" }22 age { 20 }23 after(:create) do |user|24 create(:account, user: user)25 after(:create) do |user|26 create_list(:post, 3, user: user)27 after(:create) do |user|28 create_list(:comment, 3, user
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!