<?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"><channel><title><![CDATA[Blogs @ Beautiful Code]]></title><description><![CDATA[Explore cutting-edge solutions and gain expert insights. Our tech blog covers the latest trends and innovations within the world of product engineering services]]></description><link>https://blog.beautifulcode.co</link><generator>RSS for Node</generator><lastBuildDate>Sun, 03 May 2026 14:53:06 GMT</lastBuildDate><atom:link href="https://blog.beautifulcode.co/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Refactoring is essential]]></title><description><![CDATA[Introduction
What is refactoring?
// Before refactoring
package main

import "fmt"

func main() {
    fmt.Println(add(2, 3))
    fmt.Println(subtract(5, 2))
}

func add(x int, y int) int {
    return x + y
}

func subtract(x int, y int) int {
    ret...]]></description><link>https://blog.beautifulcode.co/refactoring-is-essential</link><guid isPermaLink="true">https://blog.beautifulcode.co/refactoring-is-essential</guid><dc:creator><![CDATA[Team Phoenix]]></dc:creator><pubDate>Tue, 20 Feb 2024 04:20:37 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>What is refactoring?</p>
<pre><code class="lang-go"><span class="hljs-comment">// Before refactoring</span>
<span class="hljs-keyword">package</span> main

<span class="hljs-keyword">import</span> <span class="hljs-string">"fmt"</span>

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> {
    fmt.Println(add(<span class="hljs-number">2</span>, <span class="hljs-number">3</span>))
    fmt.Println(subtract(<span class="hljs-number">5</span>, <span class="hljs-number">2</span>))
}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">add</span><span class="hljs-params">(x <span class="hljs-keyword">int</span>, y <span class="hljs-keyword">int</span>)</span> <span class="hljs-title">int</span></span> {
    <span class="hljs-keyword">return</span> x + y
}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">subtract</span><span class="hljs-params">(x <span class="hljs-keyword">int</span>, y <span class="hljs-keyword">int</span>)</span> <span class="hljs-title">int</span></span> {
    <span class="hljs-keyword">return</span> x - y
}

<span class="hljs-comment">// After refactoring</span>
<span class="hljs-keyword">package</span> main

<span class="hljs-keyword">import</span> <span class="hljs-string">"fmt"</span>

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> {
    fmt.Println(calculate(<span class="hljs-number">2</span>, <span class="hljs-number">3</span>, add))
    fmt.Println(calculate(<span class="hljs-number">5</span>, <span class="hljs-number">2</span>, subtract))
}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">add</span><span class="hljs-params">(x <span class="hljs-keyword">int</span>, y <span class="hljs-keyword">int</span>)</span> <span class="hljs-title">int</span></span> {
    <span class="hljs-keyword">return</span> x + y
}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">subtract</span><span class="hljs-params">(x <span class="hljs-keyword">int</span>, y <span class="hljs-keyword">int</span>)</span> <span class="hljs-title">int</span></span> {
    <span class="hljs-keyword">return</span> x - y
}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">calculate</span><span class="hljs-params">(x <span class="hljs-keyword">int</span>, y <span class="hljs-keyword">int</span>, operation <span class="hljs-keyword">func</span>(<span class="hljs-keyword">int</span>, <span class="hljs-keyword">int</span>)</span> <span class="hljs-title">int</span>) <span class="hljs-title">int</span></span> {
    <span class="hljs-keyword">return</span> operation(x, y)
}
</code></pre>
<blockquote>
<p>This article presents a simple refactoring example in Go language. It starts with two basic functions for addition and subtraction. The code is then refactored to include a new function 'calculate' which accepts the operation as a parameter. This demonstrates how to make the code more flexible and reusable by abstracting the operation.</p>
<p>This is a block quote</p>
</blockquote>
<p>/</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[Implementing a Go-based Microservices Architecture on AWS]]></title><description><![CDATA[Introduction
What is a microservice? - is a small, autonomous, and independently deployable unit of a software application designed to perform a specific function
Scalability, Flexibility, and Agility: Microservices are designed to be easily scaled, ...]]></description><link>https://blog.beautifulcode.co/implementing-a-go-based-microservices-architecture-on-aws</link><guid isPermaLink="true">https://blog.beautifulcode.co/implementing-a-go-based-microservices-architecture-on-aws</guid><dc:creator><![CDATA[Team Phoenix]]></dc:creator><pubDate>Tue, 20 Feb 2024 04:19:42 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>What is a microservice? - is a small, autonomous, and independently deployable unit of a software application designed to perform a specific function</p>
<p>Scalability, Flexibility, and Agility: Microservices are designed to be easily scaled, allowing for the efficient handling of increased workloads. Their small, focused nature enables rapid development and deployment, which in turn promotes flexibility and agility in responding to changing requirements or market conditions.</p>
<p>Stability and Trustworthiness: Because microservices work separately and independently, they can make a software application more stable and reliable. If one microservice has a problem, it won't likely affect the whole system since each part works on its own. This separation helps to find and fix issues faster, making the application more dependable and steady.</p>
<p>What is etcd?</p>
<h2 id="heading-introduction-1">Introduction</h2>
<p>Overview of AWS services</p>
<pre><code class="lang-go"><span class="hljs-keyword">package</span> main

<span class="hljs-keyword">import</span> (
    <span class="hljs-string">"fmt"</span>
    <span class="hljs-string">"net/http"</span>
    <span class="hljs-string">"github.com/gorilla/mux"</span> <span class="hljs-comment">// A powerful URL router and dispatcher</span>
)

<span class="hljs-comment">// Handler for the Hello service</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">HelloHandler</span><span class="hljs-params">(w http.ResponseWriter, r *http.Request)</span></span> {
    fmt.Fprintf(w, <span class="hljs-string">"Hello, Microservices!"</span>)
}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> {
    <span class="hljs-comment">// Create a new router</span>
    router := mux.NewRouter()

    <span class="hljs-comment">// Define the route for the Hello service</span>
    router.HandleFunc(<span class="hljs-string">"/hello"</span>, HelloHandler).Methods(<span class="hljs-string">"GET"</span>)

    <span class="hljs-comment">// Start the server on port 8080</span>
    http.ListenAndServe(<span class="hljs-string">":8080"</span>, router)
}
</code></pre>
<p>package main</p>
<p>import ( "fmt" "net/http" "<a target="_blank" href="http://github.com/gorilla/mux">github.com/gorilla/mux</a>" // A powerful URL router and dispatcher )</p>
<p>// Handler for the Hello service func HelloHandler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello, Microservices!") }</p>
<p>func main() { // Create a new router router := mux.NewRouter()</p>
<p>// Define the route for the Hello service router.HandleFunc("/hello", HelloHandler).Methods("GET")</p>
<p>// Start the server on port 8080 http.ListenAndServe(":8080", router) }</p>
<p>These are the reasons why I like Golang</p>
<ol>
<li>Simplicity and Efficiency</li>
</ol>
<p>write what i want</p>
<h2 id="heading-introduction-2">Introduction</h2>
<blockquote>
<p>Sky is blue. -- Ravi</p>
</blockquote>
<pre><code class="lang-coffeescript"><span class="hljs-built_in">console</span>.log <span class="hljs-string">'Hello, World!'</span>
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Optimized for Brand Centric App Development]]></title><description><![CDATA[How does this thinking help our clients?
Makes it easy to maintain the Brand Recognition and Brand Consistency
Brand-centric development goes beyond aesthetics; it's about creating a seamless and consistent user experience that aligns with the brand'...]]></description><link>https://blog.beautifulcode.co/optimized-for-brand-centric-app-development</link><guid isPermaLink="true">https://blog.beautifulcode.co/optimized-for-brand-centric-app-development</guid><category><![CDATA[flutterflow]]></category><dc:creator><![CDATA[NG Sai Prasanth]]></dc:creator><pubDate>Mon, 19 Feb 2024 06:34:08 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/ZK1WQDMQvik/upload/92c9da1f0e577e6d40d6abc6fa93fb5d.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h4 id="heading-how-does-this-thinking-help-our-clients">How does this thinking help our clients?</h4>
<p>Makes it easy to maintain the Brand Recognition and Brand Consistency</p>
<p>Brand-centric development goes beyond aesthetics; it's about creating a seamless and consistent user experience that aligns with the brand's values, mission, and visual identity. A well-executed brand-centric app not only enhances user engagement and satisfaction but also strengthens brand loyalty and recognition.</p>
<h3 id="heading-flutterflow-provides-a-central-hub-for-managing-the-brand">FlutterFlow provides a central hub for managing the brand</h3>
<p>Central theme management system allows to define and apply a consistent theme across the entire app. This includes colors, fonts, typography, and other design elements. By centralizing brand management, we can ensure that all screens and components adhere to the brand's visual guidelines, creating a cohesive and unified user experience.</p>
<p><img src="https://lh7-us.googleusercontent.com/ZBKK7Ya1o-HB6u24SCponHS4gOhj78zquF60ujbmXbWrfnJYvWo-YeD7-s8YiFMLeELaW2mHAJ9x76YgOnCMBB-83P-kp-pcV5l3-uZO93LdcWja_7az_tRGGoOpZj8khSGCN0RKUUspglusgS85mM8" alt="Central Brand Management Console" /></p>
<h3 id="heading-flutterflow-supports-importing-brand-kit-from-design-tools">FlutterFlow supports importing brand kit from design tools</h3>
<p>We can easily import brand styles, including colors, fonts, and other design elements from popular design tools such as Figma. This eliminates the need for manual entry and ensures that the app's design accurately reflects the brand's visual identity.</p>
<p><img src="https://lh7-us.googleusercontent.com/yc5dP_9XYRLVAyEX56mARokebKCTToaC41AI-s-yvrklScJcoRnLbnvNV9GBirUowzx7o80UDecg6LJZxfRcRmJu3cWye0bEJqFWerEgfdxjC16gVImgXe8X7CzLDaWoSJsy2Pf1ua0Cg0lA04pANNI" alt="Importing Brand Kit form Figma" /></p>
<h3 id="heading-flutterflows-custom-widgetscomponent-help-with-maintaining-brand-consistency">FlutterFlow's Custom Widgets/Component help with maintaining brand consistency</h3>
<p>Custom components/widgets enable us to create reusable UI elements that encapsulate the brand's design principles. These components can be easily integrated into different parts of the app, ensuring consistency and reducing development time.</p>
<p><img src="https://lh7-us.googleusercontent.com/fId-UxrP3f14IZwCjKVEPiDnm9rhzqCqP55c97zpOToxNQaeHHIIEyrLck4eyfMQjZknuEuEW1oc9ihkSJFXOA5ptxGBSf3vs2GkpryFjJLsJ0xhVy-J-NOXeWa2in-sZ2Q5RNLBFp4cnximaluSs5c" alt="A &quot;Post&quot; component design following the brand guidelines" /></p>
<p><img src="https://lh7-us.googleusercontent.com/bm3HaUYzQicsEhM08vMAWsLZao4r-yk60-KLOtqBVXVLrYv0ESoat3OYrKROuUenat_TA7VDK68ejhmE68JZKMe_rJmTxHaTNB-qeOAKiL9XeJXEXBGvUnabU_jrlYnnacXBLBsJLC3XQCaVXPspyrs" alt="Reusing the Post Component" class="image--center mx-auto" /></p>
<p><img src="https://lh7-us.googleusercontent.com/z8QCGtua6Q5vHKU8sI9tjl_xhOvQZJiRtpqNAb-5jHPzQI_FGtLrtaMc1zo3hCPFiTqbXOsmaE-UgLiN4Wn9yFDIsXIxYZUqecPj8t7YgFqm8XBB1KOsH6FGecbXUT1TIHEWkPUVakLlxMIglieDTPk" alt="Final output ensures brand consistency across all the posts" /></p>
<h3 id="heading-flutterflow-supports-rapid-prototyping-and-iteration">FlutterFlow supports Rapid Prototyping and Iteration</h3>
<p>Rapid prototyping capabilities of FlutterFlow allow us to quickly create and test different design iterations. This iterative approach enables us to refine the app's design and ensure it aligns perfectly with the brand identity.</p>
]]></content:encoded></item><item><title><![CDATA[Clean Arch is a must]]></title><description><![CDATA[How does this thinking help our clients?

Readily adapts to new and evolving technologies, ensuring long-term relevance.

The distinct boundaries in Clean Architecture simplify understanding and maintaining the code.


In the dynamic world of softwar...]]></description><link>https://blog.beautifulcode.co/clean-arch-is-a-must</link><guid isPermaLink="true">https://blog.beautifulcode.co/clean-arch-is-a-must</guid><category><![CDATA[golang]]></category><category><![CDATA[#how-do-we-think]]></category><dc:creator><![CDATA[Team Phoenix]]></dc:creator><pubDate>Wed, 14 Feb 2024 16:23:33 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/l5Tzv1alcps/upload/9575942a649b24a1c81c66a14e91dab8.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-how-does-this-thinking-help-our-clients">How does this thinking help our clients?</h2>
<ul>
<li><p>Readily adapts to new and evolving technologies, ensuring long-term relevance.</p>
</li>
<li><p>The distinct boundaries in Clean Architecture simplify understanding and maintaining the code.</p>
</li>
</ul>
<p>In the dynamic world of software development, the choices we make regarding programming languages and architectural paradigms have profound implications for the scalability, maintainability, and success of our projects. Let's explore why this combination clicks.</p>
<h3 id="heading-it-heavily-advocates-the-usage-of-interfaces">It heavily advocates the usage of interfaces</h3>
<p>By defining our logic through interfaces, Clean Architecture reduce dependencies between various layers of our application. This makes our code far more flexible and resilient to changes, as implementations can be swapped without disrupting the overall system. Ex: switch frameworks (like web frameworks) or databases (like MySQL to PostgreSQL) without rewriting significant portions of your code. This flexibility is particularly valuable in Golang's ever-evolving ecosystem, ensuring your code stays relevant and adaptable in the long run.</p>
<p>In the following illustration, core business logic is independent of the database layer as captured in UserService. It is easy to switch from one implementation of database storage to another without affecting the UserService business logic.</p>
<pre><code class="lang-go"><span class="hljs-keyword">type</span> UserService <span class="hljs-keyword">struct</span> {
    UserRepository IUserRepository
}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">NewUserService</span><span class="hljs-params">(repo IUserRepository)</span> <span class="hljs-title">UserService</span></span> {
    <span class="hljs-keyword">return</span> UserService{UserRepository: repo}
}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(s *UserService)</span> <span class="hljs-title">GetUserByID</span><span class="hljs-params">(id <span class="hljs-keyword">int64</span>)</span> <span class="hljs-params">(*User, error)</span></span> {
    <span class="hljs-keyword">return</span> s.UserRepository.GetByID(id)
}
</code></pre>
<pre><code class="lang-go"><span class="hljs-comment">// IUserRepository defines CRUD operations for users</span>
<span class="hljs-keyword">type</span> IUserRepository <span class="hljs-keyword">interface</span> {
   GetByID(<span class="hljs-keyword">int64</span>) (*User, error)
   Create(*User) error
   Update(*User) error
   Delete(<span class="hljs-keyword">int64</span>) error
}
</code></pre>
<h3 id="heading-it-sets-you-up-to-achieve-100-code-test-coverage-for-core-business-logic">It sets you up to achieve 100% code test coverage for core business logic.</h3>
<p>Clean Architecture advocates for a clear separation of concerns, preventing high-level business logic from depending on low-level details like databases.</p>
<p>By defining interfaces within our core domain layer and letting dependencies flow outwards, we create a distinct zone for our core logic. This isolated zone, free from dependencies on databases, frameworks, or external services, becomes the perfect candidate for achieving 100% unit test coverage. This translates into several benefits: thorough verification of business rules, a safety net for future evolution and new features, and reduced debugging thanks to well-tested code.</p>
<p>In the below example, the UpdateUserEmail use case contains the essential business logic for changing a user's email. The unit test concentrates exclusively on validating the use case logic, employing a mock user repository to isolate it from external interactions.</p>
<pre><code class="lang-go"><span class="hljs-comment">// UpdateUserEmail Usecase</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(uc *UpdateUserEmail)</span> <span class="hljs-title">Execute</span><span class="hljs-params">(id <span class="hljs-keyword">int64</span>, newEmail <span class="hljs-keyword">string</span>)</span> <span class="hljs-title">error</span></span> {
    user, err := uc.repo.GetByID(id)
    <span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> {
        <span class="hljs-keyword">return</span> err
    }

    <span class="hljs-comment">// Business logic to validate and update email (e.g., unique email check)</span>
    <span class="hljs-keyword">if</span> !validateEmail(newEmail) {
        <span class="hljs-keyword">return</span> errors.New(<span class="hljs-string">"invalid email format"</span>)
    }
    user.Email = newEmail
    <span class="hljs-keyword">return</span> uc.repo.Update(user)
}
</code></pre>
<pre><code class="lang-go"><span class="hljs-comment">// Unit test for UpdateUserEmail Usecase</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">TestUpdateUserEmail</span><span class="hljs-params">(t *testing.T)</span></span> {
    mockRepo := <span class="hljs-built_in">new</span>(mock.Mock)
    <span class="hljs-keyword">defer</span> mockRepo.AssertExpectations(t)

    mockRepo.On(<span class="hljs-string">"GetByID"</span>, <span class="hljs-number">1</span>).Return(&amp;domain.User{ID: <span class="hljs-number">1</span>, Username: <span class="hljs-string">"user1"</span>, Email: <span class="hljs-string">"user1@example.com"</span>}, <span class="hljs-literal">nil</span>)
    mockRepo.On(<span class="hljs-string">"Update"</span>, &amp;domain.User{ID: <span class="hljs-number">1</span>, Username: <span class="hljs-string">"user1"</span>, Email: <span class="hljs-string">"new_email@example.com"</span>}).Return(<span class="hljs-literal">nil</span>)

    uc := domain.NewUpdateUserEmail(mockRepo)

    err := uc.Execute(<span class="hljs-number">1</span>, <span class="hljs-string">"new_email@example.com"</span>)

    assert.NoError(t, err)
    mockRepo.Verify(t)
}
</code></pre>
<h3 id="heading-dip-is-applied-well-in-practice">DIP is applied well in practice.</h3>
<p>One of the core strengths of Clean Architecture is its strong adherence to the Dependency Inversion Principle (DIP). This principle states that high-level modules should not depend on low-level modules. Both should depend on abstractions, and abstractions should not depend on details. We translate this principle into clear separation of concerns within our applications. Our core business logic resides in the inner domain layer, free from dependencies. This layer interacts with the outside world through well-defined interfaces.</p>
<p>Applying DIP through Clean Architecture unlocks several advantages such as Enhanced Security and Unparalleled Adaptability.</p>
]]></content:encoded></item><item><title><![CDATA[RSpec over MiniTest for writing test cases]]></title><description><![CDATA[How does this thinking help our clients?

Expressive syntax enables the developers to write what they think naturally resulting in less time to write behavior tests.

Alignment between Product Manager and Engineers gets established early on as RSpec ...]]></description><link>https://blog.beautifulcode.co/rspec-over-minitest-for-writing-test-cases</link><guid isPermaLink="true">https://blog.beautifulcode.co/rspec-over-minitest-for-writing-test-cases</guid><category><![CDATA[#how-do-we-think]]></category><category><![CDATA[ROR]]></category><dc:creator><![CDATA[NG Sai Prasanth]]></dc:creator><pubDate>Wed, 14 Feb 2024 16:09:08 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/pW3TdRsH8yM/upload/39933aee10b1b150a126dfc102d092ca.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-how-does-this-thinking-help-our-clients">How does this thinking help our clients?</h2>
<ul>
<li><p>Expressive syntax enables the developers to write what they think naturally resulting in less time to write behavior tests.</p>
</li>
<li><p>Alignment between Product Manager and Engineers gets established early on as RSpec promotes writing tests w.r.t the behavior of the system.</p>
</li>
</ul>
<p>We prefer RSpec over MiniTest due to its expressive DSL, comprehensive mocking capabilities,  support for writing BDD test cases and extensive community support.</p>
<h3 id="heading-rspec-has-a-expressive-dsl-which-improves-test-readability-and-maintainability">RSpec has a Expressive DSL which improves test readability and maintainability</h3>
<p>RSpec employs a concise and expressive Domain-Specific Language (DSL) that makes writing tests easy. The DSL's intuitive syntax mirrors natural language, resulting in test cases that are easy to read, understand, and maintain. This clarity promotes collaboration and facilitates effective communication among developers, testers, and stakeholders.</p>
<pre><code class="lang-ruby"><span class="hljs-comment"># Expressive DSL with RSpec</span>
describe <span class="hljs-string">"ShoppingCart"</span> <span class="hljs-keyword">do</span>
  describe <span class="hljs-string">"#total_price_with_taxes"</span> <span class="hljs-keyword">do</span>
    it <span class="hljs-string">"calculates the total price with taxes"</span> <span class="hljs-keyword">do</span>
</code></pre>
<pre><code class="lang-ruby"><span class="hljs-comment"># MiniTest DSL is not so expressive</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_calculates_total_price_with_taxes</span></span>
</code></pre>
<h3 id="heading-rspec-advocates-behavior-driven-development">RSpec advocates Behavior Driven Development</h3>
<p>RSpec supports a behavior-driven approach to testing. This means that tests can be written from the perspective of the user. This can help to ensure that the tests are focused on the actual behavior of the application.</p>
<pre><code class="lang-ruby"><span class="hljs-comment"># Behavior test for user creation workflow</span>
RSpec.describe <span class="hljs-string">"User"</span>, <span class="hljs-symbol">type:</span> <span class="hljs-symbol">:feature</span> <span class="hljs-keyword">do</span>
  it <span class="hljs-string">"requires a name"</span> <span class="hljs-keyword">do</span>
    visit new_user_path

    fill_in <span class="hljs-string">"Name"</span>, <span class="hljs-symbol">with:</span> <span class="hljs-string">""</span>
    click_on <span class="hljs-string">"Create User"</span>

    expect(page).to have_content(<span class="hljs-string">"Name can't be blank"</span>)
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<h3 id="heading-rspec-supports-instance-doubles">Rspec supports instance doubles</h3>
<p>Instance doubles allow developers to create fake objects that mimic the behavior of real objects, enabling them to isolate and test specific components of the codebase.</p>
<pre><code class="lang-ruby"><span class="hljs-comment"># Rspec snippet for a double that stands in for a specific instance of a User</span>
user_double = instance_double(<span class="hljs-string">"User"</span>, <span class="hljs-symbol">name:</span> <span class="hljs-string">"John Doe"</span>, <span class="hljs-symbol">email:</span> <span class="hljs-string">"johndoe@example.com"</span>)
</code></pre>
<pre><code class="lang-ruby"><span class="hljs-comment"># Minitest creates a generic mock object that does not have the behavior of the real object (via methods)</span>
user_double = Minitest::Mock.new
user_double.expect(<span class="hljs-symbol">:name</span>, <span class="hljs-string">"John Doe"</span>)
user_double.expect(<span class="hljs-symbol">:email</span>, <span class="hljs-string">"johndoe@example.com"</span>)
</code></pre>
]]></content:encoded></item></channel></rss>