How To Write Rspec

  • The RSpec is a testing device for Ruby, created for behavior-driven development (BDD). It is the most often involved testing library for Ruby production applications. Even though it has a very rich and powerful DSL (domain-specific language), at its core it is a simple tool that you can start using rather quickly
  • First, let’s create a Rails app using rails new
  • Install Rspec-rails
  • Add this in your applications gem file inside the:development, test group :
  • Then, at that point, run bundle install to install them.
  • In the wake of introducing these pearls, we actually need to introduce Rspec into our application utilizing
  • rails create RSpec:install
  • Make sure to require the web drivers gem at the top of spec/rails_helper.rb:
  • Let’s create a controller StaticControllerwith just a single action index:
  • This will make stariv_controller.rb and static/index.html.erb. Then, open static/index.html.erb, and add a static text, say ‘Hello World’ into it.
  • Then check your output using rails s.
  • Write your first test
  • Then, at that point, in your terminal, navigate to your Rails application root path, then run.
  • rspec spec/static_spec.rb

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store