faker-ruby / faker

A library for generating fake data such as names, addresses, and phone numbers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve testing of locales files

ak2-lucky opened this issue · comments

@stefannibrasil

Is your feature request related to a problem? Please describe it.
Right now, the locale file test only confirms that the expected value is a string.
So why not make these tests a little more precise?

Describe alternatives you've considered
Why not just take the actual values from the yml file and test that it is one of those values, like this

# frozen_string_literal: true
require 'yaml' # <= My suggestion point
require_relative 'test_helper'

class TestItLocale < Test::Unit::TestCase
  def setup
    Faker::Config.locale = 'it'
    @yaml_data = YAML.load_file('lib/locales/it.yml')['it']['faker'] # <= My suggestion point
  end

...

  def test_it_address_methods
    assert Faker::Address.city_prefix.is_a? String
    assert_includes @yaml_data['address']['city_prefix'], Faker::Address.city_prefix  # <= My suggestion point
    #@yaml_data['address']['city_prefix'] => [San, Borgo, Sesto, Quarto, Settimo]
  end
...

hi @ak2-lucky thank you for your suggestion! This is something I've thought about at some point as well :)

A while ago, I've asked my teammates @mike-burns @MatheusRich and @thiagoa once at our internal Slack. They brought an interesting point: With a good abstraction, it doesn’t matter from what source the data comes from.

@mike-burns (whom I always ask for help when I don't know how to solve something) suggested:

Is it worth testing that you can fetch data from YAML? If so, can you abstract that into one place, test it rigorously there, and then use that abstraction with confidence elsewhere?
Can you use deterministically_verify or something like it to make sure you don't get a random value, and then use normal assert_equal against an expected value?

So what do you think of exploring a test abstraction/helper that gives us enough confidence to stub the YAML content in the other tests?

I haven't poked with this yet but exploring the deterministically_verify helper for this seems like a good start.

Closing this because there hasn't been any activity in the past few months.