Add Additional Library to Faker :: RSpec :: TDD

Suppose you are working on a project in which you want to test a Applicant Model. Applicant may have any value among options in a drop-down. If you want the spec should fill the education field with the data you wish, then you can modify the Faker module. To do so, the best way is the following

create a folder in spec/ directory
create a file called ‘anything_you_want.rb’

# inside the file 'anything_you_want.rb'
class Faker::Occupation
  def self.education
    list = ['High School', 'College', 'School']
    list.sample
  end
end

Un-comment the line from the file ‘rails_helper.rb’

Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
Advertisements