<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Michelle Cacais on Medium]]></title>
        <description><![CDATA[Stories by Michelle Cacais on Medium]]></description>
        <link>https://medium.com/@michellecacais?source=rss-90de9c87bd35------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*xvcbBl2hrr85iJp2.</url>
            <title>Stories by Michelle Cacais on Medium</title>
            <link>https://medium.com/@michellecacais?source=rss-90de9c87bd35------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 06:02:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@michellecacais/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Fake it! Ruby gems for test automation]]></title>
            <link>https://medium.com/@michellecacais/fake-it-ruby-gems-for-test-automation-e52012624ed?source=rss-90de9c87bd35------2</link>
            <guid isPermaLink="false">https://medium.com/p/e52012624ed</guid>
            <category><![CDATA[faker-gem]]></category>
            <category><![CDATA[gem-factory-bot]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[software-testing]]></category>
            <dc:creator><![CDATA[Michelle Cacais]]></dc:creator>
            <pubDate>Wed, 26 Jun 2019 17:53:31 GMT</pubDate>
            <atom:updated>2019-06-26T17:53:31.997Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GItDr3v5-3G-d84re42kGA.jpeg" /><figcaption>Ruby gem</figcaption></figure><p>The gems Faker and Factory Bot are great allies for Ruby programmers who want to improve their codes related to dynamic object creation. Faker is a gem to generate random content, and Factory Bot is responsible for adapting the system to the Factory design pattern. Both are excellent choices when you want to maintain your code organized and to perform a user approximation behavior.</p><p>It’s no secret that test automation is a process that significantly reduces the effort in repetitive manual activities. Automation can be a great ally in software quality assurance. Currently, we have several tools that help in this process. Among them, the Faker and Factory Bot gems for tests written in RoR are technologies that enhance the code of automated tests.</p><h3>Gem Faker</h3><p>Gem Faker is a random data generator (names, emails, addresses) that approximates the behavior of a real user, avoiding the need to set static data in the application. Each time that a test run, new data will be generated. This way, you can simulate the creation of a new account, bank data, credit card, password, among others. It counts with a lot of variation, including some unusual words, like Hipster, Cannabis, BossaNova, SuperHero and lots of others.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*ZKJ2QPadOustWCdOPAatgA.png" /><figcaption>Gem Faker logo</figcaption></figure><p>To use this gem, you have to add gem &quot;faker&quot; in the Gemfile and run Bundle command. You can also add it running gem install faker. To create a fake name with Faker, you only have to add Faker::Name.name, where Faker::<strong>Name</strong>.name (Name) is related to the variable you want to generate, and the Faker::Name.<strong>name </strong>(name) is the variation of this variable, e.g., name with surname, male or female, prefix (Mr., Ms.) among others.</p><p>There is also the possibility to customize the values returned by Faker since you want to get specific data. This is very useful if you wish to restrict the country, location or language of the variables, e.g., postal codes, city names, or phone numbers. Faker uses the I18n gem to store strings and formats, so if you want to configure the local, you have to add the code Faker::Config.locale and specify the local you want to restrict, for example, if you want to get only Simplified Chinese, you have to type Faker::Config.locale = &#39;zh-CN&#39;. All supported locales are available <a href="https://github.com/stympy/faker/tree/master/lib/locales">here</a>.</p><p>The official git with gem Faker source is in <a href="https://github.com/stympy/faker">this link</a>.</p><h3>Gem Factory Bot</h3><p>Factory Bot is a gem that helps to adapt the system to the Factory design pattern, which is a standard for creating objects at runtime, providing dynamism to the application. Previously was known as Factory Girl, which is also used nowadays for projects built in older rails versions. This gem replaces Fixtures with a simple definition syntax and supports various object-building strategies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*Fj0GftnWlHLdBhcYWms-vA.png" /><figcaption>Factory Bot is maintained and funded by thoughtbot</figcaption></figure><p>To install it, you have to add gem &quot;factory_bot_rails&quot; to your Gemfile, if you are using Rails in your project and run Bundle. After, we have to do some configs to make it all work. If you are using Cucumber, Spinach, Manifest or other, you may like to see <a href="https://www.rubydoc.info/gems/factory_bot/file/GETTING_STARTED.md">this link</a> which specifies the configuration for each one. If you are using RSpec, you have to add this code below to your spec_helper:</p><pre>RSpec.configure do |config|<br>  config.include <a href="https://www.rubydoc.info/gems/factory_bot/FactoryBot">FactoryBot</a>::<a href="https://www.rubydoc.info/gems/factory_bot/FactoryBot/Syntax">Syntax</a>::<a href="https://www.rubydoc.info/gems/factory_bot/FactoryBot/Syntax/Methods">Methods</a><br>end</pre><p>Otherwise, you can add gem &quot;factory_bot&quot; to your Gemfile if you are not using Rails. Also, you have to configure your files, adding the following code:</p><pre>RSpec.configure do |config|<br>  config.include <a href="https://www.rubydoc.info/gems/factory_bot/FactoryBot">FactoryBot</a>::<a href="https://www.rubydoc.info/gems/factory_bot/FactoryBot/Syntax">Syntax</a>::<a href="https://www.rubydoc.info/gems/factory_bot/FactoryBot/Syntax/Methods">Methods</a></pre><pre>config.before(:suite) do<br>    <a href="https://www.rubydoc.info/gems/factory_bot/FactoryBot">FactoryBot</a>.<a href="https://www.rubydoc.info/gems/factory_bot/FactoryBot#find_definitions-class_method">find_definitions</a><br>  end<br>end</pre><p>To create Factories, you first have to create a specific folder which will be recognized by Factory Bot. The pattern is test/factories.rb, but you can change it. To check the locales supported in the application, you may run the code in the terminal FactoryBot.find_definitions and it’ll return where you have to place your factories. After that, you can start creating your factories. You can see an example of a Factory called “user” in the code below. To instantiate it, you have to call it like this: user = create(:user) .</p><pre><a href="https://www.rubydoc.info/gems/factory_bot/FactoryBot">FactoryBot</a>.<a href="https://www.rubydoc.info/gems/factory_bot/FactoryBot/Syntax/Default#define-instance_method">define</a> do<br>  factory :user do<br>    first_name { &quot;John&quot; }<br>    last_name { &quot;Doe&quot; }<br>    email { &quot;john_doe@email.com&quot; }<br>  end<br>end</pre><p>Factory Bot also provides some functionalities as aliases, dependent attributes, transient attributes, inheritance, associations, sequences, traits, among others. You can check the git with the source of Factory Bot in <a href="https://github.com/thoughtbot/factory_bot">this link</a>.</p><h3>Mixing Faker + Factory Bot</h3><p>The idea of mixing gems Faker and Factory Bot is to create dynamically random data in execution time. To do it, you have to add and configure both gems to your project. After we are going to create a factory and instead of adding fixing values, we will add fake values with gem Faker. An example of a factory with random data can be seen in the code below:</p><pre><a href="https://www.rubydoc.info/gems/factory_bot/FactoryBot">FactoryBot</a>.<a href="https://www.rubydoc.info/gems/factory_bot/FactoryBot/Syntax/Default#define-instance_method">define</a> do<br>  factory :user do<br>    first_name { Faker::Name.name }<br>    last_name { Faker::Name.last_name }<br>    email { Faker::Internet.email(name) }<br>  end<br>end</pre><p>I did a simple CRUD written in Ruby on Rails that uses Faker and Factory Bot. You can check it in Github, here in <a href="https://github.com/MiCacais/tdd-rspec-rails">this link</a>.</p><p>This is it, folks. Hope it was useful for you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e52012624ed" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>