Advertisement
dreadmachine

lucky_nums_spec.rb

Dec 6th, 2021
1,433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.81 KB | None | 0 0
  1. require 'rails_helper'
  2.  
  3. DIGITS = ('0'..'9').to_a
  4.  
  5. def random_lucky(len)
  6.   half = [0] * (3 - len) + DIGITS.sample(len)
  7.   (half + half.shuffle).join
  8. end
  9.  
  10. def submit_form(from, to)
  11.   visit '/'
  12.   fill_in 'from', with: from
  13.   fill_in 'to', with: to
  14.   click_button 'Calculate Lucky Numbers!'
  15.   find(:id, 'result-table').text
  16. end
  17.  
  18. describe 'Lucky Nums calculator', type: :feature do
  19.   it 'doesn\'t allow to input a string', js: true do
  20.     visit '/'
  21.     fill_in 'from', with: 'a string'
  22.     fill_in 'to', with: 'another string'
  23.     expect(find_field('from').value).not_to eq 'a string'
  24.     expect(find_field('to').value).not_to eq 'another string'
  25.   end
  26.  
  27.   it 'outputs a proper table when submitted 0...9999', js: true do
  28.     results = submit_form(0, 9_999)
  29.     100.times do
  30.       expect(results).to match(random_lucky(1))
  31.     end
  32.   end
  33. end
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement