<?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 Claire on Medium]]></title>
        <description><![CDATA[Stories by Claire on Medium]]></description>
        <link>https://medium.com/@clairejeru?source=rss-463858ede89a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ftXvTyRifNawDCUF</url>
            <title>Stories by Claire on Medium</title>
            <link>https://medium.com/@clairejeru?source=rss-463858ede89a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 21:53:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@clairejeru/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[Rspec and Rails]]></title>
            <link>https://medium.com/@clairejeru/rspec-and-rails-26b49e1939f8?source=rss-463858ede89a------2</link>
            <guid isPermaLink="false">https://medium.com/p/26b49e1939f8</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Claire]]></dc:creator>
            <pubDate>Wed, 01 Aug 2018 00:28:37 GMT</pubDate>
            <atom:updated>2018-08-01T19:13:27.185Z</atom:updated>
            <content:encoded><![CDATA[<p>Today, I would like to introduce you to the magic or should I say the Art of Testing in Rails and how it can make your life so much easier when it is time to build and launch your first ever modern (not the 90’s) web application. So get on board!</p><p>First of all, what is Rails? Rails or Ruby on Rails (aka RoR) to be specific is an open source framework for Web development in Ruby, an object-oriented programming (OOP) language. <br>Here are some few famous websites built on Ruby on Rails: Groupon, GitHub, Shopify, Airbnb, Twitter (at first, it has now switched to Java for scalability purposes), YellowPages and Hulu … <br>Some advantages when using Rails are the community (large community, meetups in most of the major cities, one of the most used languages on Github…), the libraries (large collection of gems …), Ruby is easy to write and understand if you are new to Ruby and is fairly straight to the point without requiring a lot of funny punctuations.</p><h3>Set up</h3><p>Let’s start. We will need to create a new project by typing in our terminal : <br>rails new &lt;projectname&gt; -T-d=”postgresql” — skip-spring — skip-turbolinks .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nBH7MosB6_wm5MMXO4UjiA.png" /><figcaption>Creating a new app</figcaption></figure><p>Our project will consist of supermarkets and foods. A supermarket has many foods and foods has many supermarkets. It is a many to many relationships and we will have to create a join table for that called supermarket_foods.</p><p>Now, we can open our new project supermarket here :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*T7W4lcpF3OdUU9fIQ6rMSA.png" /></figure><p>We can observe that our folder is structured according the MVC architectural pattern. M stands for Model, it takes care of all the logic of our app by interacting/communicating with our database. The View is what we display in our browser. And, finally, the Controller is the traffic cop or middle man between what we display and what we gather from the model (from the database).</p><p>What, where ? No ! We do not have any spec folder … and we are saying that we are actually going to test our code ?</p><p>We have to correct this and add those gems in our Gemfile :</p><p>gem &#39;rspec-rails&#39;, <br>gem &#39;capybara&#39;,<br>gem &#39;launchy&#39;,<br>gem &#39;pry&#39;, <br>gem &#39;byebug&#39;, <br>gem &#39;database-cleaners&#39;,<br>gem &#39;simplecov&#39;,<br>gem &#39;shoulda-matchers&#39;</p><p>After adding our gem and running bundle install and bundle update, we will have to run $ rails g rspec:install .</p><p>We are able to see our spec folder now :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*6Ff4ExvhzDd_W-3IaV1M3w.png" /></figure><h3>Tests and Database</h3><p>Let us write our first test. We will want that our visitor can visit supermarket index page and they will see all the supermarkets. In spec, we are going to create a folder called features.</p><p>Our file will have multiple elements :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iLvYHHDmjSRW8bsQ6ghi7A.png" /></figure><p>We will create a new database by running : $ rake db:create</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xIH6DcEKzKVBgn89uGOzxA.png" /></figure><p>The magic from rspec and testing is how it helps us building all our model/view/controller step by step by following the error: and climbing the stair one step at a time.</p><p>Here are the steps you will have to follow :</p><ul><li>Create a table supermarkets</li><li>Create a model Supermarket that inherits from ApplicationRecord</li><li>Create our routes with rails</li><li>Adding our Controller SupermarketsController that inherits from ApplicationController</li><li>Create our index.html.erb template for supermarkets index page</li><li>Finally, define our @supermarkets and adding an index action to our SupermarketsController.</li></ul><p>And, voila ! You would have build all the piece of your puzzle (MVC) by simply following what your errors are telling you to do.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26b49e1939f8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>