{"id":8376,"date":"2019-12-24T11:11:23","date_gmt":"2019-12-24T11:11:23","guid":{"rendered":"https:\/\/www.botreetechnologies.com\/blog\/?p=8376"},"modified":"2020-12-04T18:27:21","modified_gmt":"2020-12-04T12:57:21","slug":"how-to-setup-up-rspec-in-a-rails-application-for-testing","status":"publish","type":"post","link":"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/","title":{"rendered":"How To Setup Up Rspec In A Rails Application For Testing\u200a &#8211; A Lean Version"},"content":{"rendered":"\n<p><a href=\"https:\/\/rspec.info\/\" target=\"_blank\" rel=\"noopener noreferrer\">RSpec<\/a> is the most popular testing framework among <a href=\"https:\/\/github.com\/BoTreeConsultingTeam\" target=\"_blank\" rel=\"noopener noreferrer\">Ruby community<\/a> and we also use it extensively. Let\u2019s see how to set up it quickly in any <a href=\"https:\/\/www.botreetechnologies.com\/blog\/how-to-securely-handle-webhook-events-from-stripe-in-ruby-on-rails-application\" target=\"_blank\" rel=\"noopener noreferrer\">Rails application<\/a> without getting into many details.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Lean Version<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1\u200a-\u200aSetting up Rails Application<\/h3>\n\n\n\n<p><em><strong>New Rails App<\/strong><\/em><\/p>\n\n\n\n<p><code>$ rails new myapp -T<\/code><\/p>\n\n\n\n<p><em><strong>Existing Rails App<\/strong><\/em><\/p>\n\n\n\n<p>Remove <code>app\/test<\/code> directory if present<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step 2 \u200a-\u200a Install gems<\/h4>\n\n\n\n<p>Configure<code> Gemfil<\/code>e as per the below gist and bundle<\/p>\n\n\n\n<p><script src=\"https:\/\/gist.github.com\/AmitPatel-BoTreeConsulting\/03dc8caf3d55b47cd491df40bce9de01.js\"><\/script><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step 3 \u200a- \u200aInstall and Configuring RSpec<\/h4>\n\n\n\n<p>Run the following command<\/p>\n\n\n\n<p><code>$ rails generate rspec:install<\/code><\/p>\n\n\n\n<p><em><strong>Configure .rspec<\/strong><\/em><\/p>\n\n\n\n<p>Add following lines in <code>.rspec<\/code><\/p>\n\n\n\n<p><code>-- require spec_helper<\/code><\/p>\n\n\n\n<p><code>-- order rand<\/code><\/p>\n\n\n\n<p><code>-- format documentation<\/code><\/p>\n\n\n\n<p><em><strong>Configure Database Cleaner<\/strong><\/em><\/p>\n\n\n\n<p>Add the following in rails_helper.rb<\/p>\n\n\n\n<p><script src=\"https:\/\/gist.github.com\/AmitPatel-BoTreeConsulting\/17a477035490f183d2ee5fb2c1707fb1.js\"><\/script><\/p>\n\n\n\n<p>Now, run <code>rspec<\/code> to ensure setup complete<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"710\" height=\"144\" src=\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/output-1.png\" alt=\"output\" class=\"wp-image-13354\" srcset=\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/output-1.png 710w, https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/output-1-300x61.png 300w\" sizes=\"auto, (max-width: 710px) 100vw, 710px\" \/><\/figure><\/div>\n\n\n\n<p>That\u2019s it!!<\/p>\n\n\n\n<p><a href=\"https:\/\/www.botreetechnologies.com\/ruby-on-rails-development\"><strong><b>Click here for more<\/b> details&#8230;<\/strong><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/www.botreetechnologies.com\/contact\">Consulting is free<\/a> &#8211; let us help you grow!<\/h3>\n","protected":false},"excerpt":{"rendered":"<p>RSpec is the most popular testing framework among Ruby community&#8230;<\/p>\n","protected":false},"author":3,"featured_media":13353,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73,10],"tags":[],"class_list":["post-8376","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ruby-on-rails","category-technology"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How To Setup Up Rspec In A Rails Application For Testing\u200a?<\/title>\n<meta name=\"description\" content=\"Want to know how to set up RSpec in a Rails application for testing? Here\u2019s a comprehensive article detailing the steps of the process\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Setup Up Rspec In A Rails Application For Testing\u200a?\" \/>\n<meta property=\"og:description\" content=\"Want to know how to set up RSpec in a Rails application for testing? Here\u2019s a comprehensive article detailing the steps of the process\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/\" \/>\n<meta property=\"og:site_name\" content=\"BoTree Technologies\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/BoTreeTechnologies\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-12-24T11:11:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-12-04T12:57:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2019\/12\/rails-application-for-testing.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1280\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Amit Patel\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@BoTreeTech\" \/>\n<meta name=\"twitter:site\" content=\"@BoTreeTech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Amit Patel\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/\"},\"author\":{\"name\":\"Amit Patel\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/86645099906a429b0c5ca4de2bf92c46\"},\"headline\":\"How To Setup Up Rspec In A Rails Application For Testing\u200a &#8211; A Lean Version\",\"datePublished\":\"2019-12-24T11:11:23+00:00\",\"dateModified\":\"2020-12-04T12:57:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/\"},\"wordCount\":128,\"commentCount\":12,\"image\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2019\/12\/rails-application-for-testing.jpg\",\"articleSection\":[\"Ruby on Rails\",\"Technology\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/\",\"name\":\"How To Setup Up Rspec In A Rails Application For Testing\u200a?\",\"isPartOf\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2019\/12\/rails-application-for-testing.jpg\",\"datePublished\":\"2019-12-24T11:11:23+00:00\",\"dateModified\":\"2020-12-04T12:57:21+00:00\",\"author\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/86645099906a429b0c5ca4de2bf92c46\"},\"description\":\"Want to know how to set up RSpec in a Rails application for testing? Here\u2019s a comprehensive article detailing the steps of the process\",\"breadcrumb\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/#primaryimage\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2019\/12\/rails-application-for-testing.jpg\",\"contentUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2019\/12\/rails-application-for-testing.jpg\",\"width\":1920,\"height\":1280,\"caption\":\"Setup Up Rspec In A Rails Application\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.botreetechnologies.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Setup Up Rspec In A Rails Application For Testing\u200a &#8211; A Lean Version\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#website\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/\",\"name\":\"BoTree Technologies\",\"description\":\"Committed to inspire generation.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.botreetechnologies.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/86645099906a429b0c5ca4de2bf92c46\",\"name\":\"Amit Patel\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/amit-patel-1-150x150.png\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/amit-patel-1-150x150.png\",\"contentUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/amit-patel-1-150x150.png\",\"caption\":\"Amit Patel\"},\"description\":\"Amit is the COO and Co-founder of BoTree Technologies. He is a developer advocate and solution architect at the company. He has helped many SME and Large corporations digitize their business operations. He loves hanging out with friends and meditate.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Setup Up Rspec In A Rails Application For Testing\u200a?","description":"Want to know how to set up RSpec in a Rails application for testing? Here\u2019s a comprehensive article detailing the steps of the process","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/","og_locale":"en_US","og_type":"article","og_title":"How To Setup Up Rspec In A Rails Application For Testing\u200a?","og_description":"Want to know how to set up RSpec in a Rails application for testing? Here\u2019s a comprehensive article detailing the steps of the process","og_url":"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/","og_site_name":"BoTree Technologies","article_publisher":"https:\/\/www.facebook.com\/BoTreeTechnologies\/","article_published_time":"2019-12-24T11:11:23+00:00","article_modified_time":"2020-12-04T12:57:21+00:00","og_image":[{"width":1920,"height":1280,"url":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2019\/12\/rails-application-for-testing.jpg","type":"image\/jpeg"}],"author":"Amit Patel","twitter_card":"summary_large_image","twitter_creator":"@BoTreeTech","twitter_site":"@BoTreeTech","twitter_misc":{"Written by":"Amit Patel","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/#article","isPartOf":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/"},"author":{"name":"Amit Patel","@id":"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/86645099906a429b0c5ca4de2bf92c46"},"headline":"How To Setup Up Rspec In A Rails Application For Testing\u200a &#8211; A Lean Version","datePublished":"2019-12-24T11:11:23+00:00","dateModified":"2020-12-04T12:57:21+00:00","mainEntityOfPage":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/"},"wordCount":128,"commentCount":12,"image":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/#primaryimage"},"thumbnailUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2019\/12\/rails-application-for-testing.jpg","articleSection":["Ruby on Rails","Technology"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/","url":"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/","name":"How To Setup Up Rspec In A Rails Application For Testing\u200a?","isPartOf":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/#primaryimage"},"image":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/#primaryimage"},"thumbnailUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2019\/12\/rails-application-for-testing.jpg","datePublished":"2019-12-24T11:11:23+00:00","dateModified":"2020-12-04T12:57:21+00:00","author":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/86645099906a429b0c5ca4de2bf92c46"},"description":"Want to know how to set up RSpec in a Rails application for testing? Here\u2019s a comprehensive article detailing the steps of the process","breadcrumb":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/#primaryimage","url":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2019\/12\/rails-application-for-testing.jpg","contentUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2019\/12\/rails-application-for-testing.jpg","width":1920,"height":1280,"caption":"Setup Up Rspec In A Rails Application"},{"@type":"BreadcrumbList","@id":"https:\/\/www.botreetechnologies.com\/blog\/how-to-setup-up-rspec-in-a-rails-application-for-testing\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.botreetechnologies.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How To Setup Up Rspec In A Rails Application For Testing\u200a &#8211; A Lean Version"}]},{"@type":"WebSite","@id":"https:\/\/www.botreetechnologies.com\/blog\/#website","url":"https:\/\/www.botreetechnologies.com\/blog\/","name":"BoTree Technologies","description":"Committed to inspire generation.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.botreetechnologies.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/86645099906a429b0c5ca4de2bf92c46","name":"Amit Patel","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/amit-patel-1-150x150.png","url":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/amit-patel-1-150x150.png","contentUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/amit-patel-1-150x150.png","caption":"Amit Patel"},"description":"Amit is the COO and Co-founder of BoTree Technologies. He is a developer advocate and solution architect at the company. He has helped many SME and Large corporations digitize their business operations. He loves hanging out with friends and meditate."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/8376","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=8376"}],"version-history":[{"count":1,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/8376\/revisions"}],"predecessor-version":[{"id":13355,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/8376\/revisions\/13355"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/media\/13353"}],"wp:attachment":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=8376"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=8376"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=8376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}