Possible, however, the contents may contain inaccuracies or errors. We strive to update the contents of our website and tutorials as timely and as precisely as The user of this e-book is prohibited to reuse, retain, copy, distribute, or republishĪny contents or a part of contents of this e-book in any manner without written consent Ltd.Īll the content and graphics published in this e-book are the property of Tutorials Point (I) Copyright 2015 by Tutorials Point (I) Pvt. In order to benefit from reading this tutorial, you should have some experience with Afterįinishing this tutorial, you will be able to incorporate RSpec tests into your daily coding This tutorial is for beginners who want to learn how to write better code in Ruby. This tutorial will show you, how to use RSpec to test your code when building applications RSpec does not put emphasis on, how the application worksīut instead on how it behaves, in other words, what the application actually does. What this means is that, tests written in RSpec focus on the "behavior" Than traditional xUnit frameworks like JUnit because RSpec is a Behavior drivenĭevelopment tool. RSpec is a unit test framework for the Ruby programming language. a spec/spec_helper.rb file with default configuration options.a spec directory into which to put spec files.This will create a spec folder for your tests, along with the following config files: Add this line to your application's Gemfile : gem 'rspec'Īnd then execute bundle to install the dependencies: $ bundleĪlternatively, you can install the gem manually: $ gem install rspecĪfter installing the gem, run the following command: rspec -init The most common way to install the RSpec gem is using Bundler. RSpec doesn't interpret the string at all, so you could use a different string or omit that describe block entirely. The # in #greet is only a convention to show that greet is an instance method (as opposed to '.' for a class method). This example also shows that describe blocks can be nested, in this case to convey that the greet method is part of the Greet class. If the expectation is met, nothing happens and the test passes. In RSpec terminology, the file is a "spec" of Greeter and the it block is an "example". įinished in 0.00063 seconds (files took 0.06514 seconds to load) So our file structure looks like: $ tree. In spec/greeter_spec.rb: require_relative './greeter.rb'Įxpect().to eq("Hello, world!") In greeter.rb (wherever that goes in your project): class Greeter Official documentation for RSpec and rspec-rails is here: A simple RSpec example There is also the rspec-rails gem, which extends RSpec with support for testing the types of classes used in Rails applications, and with support for writing feature specs (acceptance tests) which test the application from the user's point of view. It is documented in the RSpec Mocks topic. rspec-mocks provides RSpec's support for test doubles: double, allow, expect, receive, have_received, etc.(It also provides the deprecated should expectation syntax.) It is documented in the RSpec Expectations topic. rspec-expectations provides RSpec's support for expecting test results: the expect/ to expectation syntax and RSpec's built-in matchers.It is documented in the RSpec Core topic. rspec-core provides RSpec's way of structuring and running tests: the rspec command-line executable, the describe, context and it methods, shared examples, etc.Those three parts are also a way to structure this documentation. The rspec gem is just a meta-gem which brings in the three parts of RSpec. It is used primarily to specify and test classes and methods, i.e. RSpec is a BDD tool used to specify and test Ruby programs.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |