RSpec

Uses your system voice; voice and rate in settings.

Snapshot

≈ 4 min read

Names in other languages

No names in other languages are held for this entry yet.

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

RSpec is a computer domain-specific language (DSL) (particular application domain) testing tool written in the programming language Ruby to test Ruby code. It is a behavior-driven development (BDD) framework which is extensively used in production applications. The basic idea behind this concept is that of test-driven development (TDD) where the tests are written first and the development is based on writing just enough code that will fulfill those tests followed by refactoring. It contains its own mocking framework that is fully integrated into the framework based upon JMock. The simplicity in the RSpec syntax makes it one of the popular testing tools for Ruby applications. The RSpec tool can be used by installing the rspec gem which consists of three other gems, namely rspec-core , rspec-expectation and rspec-mock.

RSpec is a computer domain-specific language (DSL) (particular application domain) testing tool written in the programming language Ruby to test Ruby code. It is a behavior-driven development (BDD) framework which is extensively used in production applications. The basic idea behind this concept is that of test-driven development (TDD) where the tests are written first and the development is based on writing just enough code that will fulfill those tests followed by refactoring. It contains its own mocking framework that is fully integrated into the framework based upon JMock. The simplicity in the RSpec syntax makes it one of the popular testing tools for Ruby applications. The RSpec tool can be used by installing the rspec gem which consists of three other gems, namely rspec-core , rspec-expectation and rspec-mock. ==Usage== ==== ==== The method is used to describe a class, method or an example group. This is the outer block which actually contains the test code and it depicts the characteristics of the code enclosed in it. This method takes a number of arguments and an optional block. However, normally one or two arguments are used to describe the behavior of the example group. The first argument represents the reference to the class or module whereas the second argument is optional whose datatype would be String. The example groups can be nested as well. An example of using the describe method is as follows: describe User, "with no account balance" {....} => User with no account balance ==== ==== The block is used to describe the context in which the class or method mentioned in the describe block is being used. This can be considered as an alias to the word in this scenario and they both can be used interchangeably. Generally, is used for things and is used for contexts. It helps to venture out different outcomes in different scenarios. The example mentioned above can be described using the method as follows: describe User do context "has no account balance" do .... end end Using makes it easier to scan a spec file and makes it clear what it relates to. ==== ==== It is a RSpec method which describes the specifications of the sample in the context. The block takes a string as an argument and the string after the 'it' keyword can be considered as the function that the block is expected to perform or in other words it can be considered as a test case. Consider the following example: describe User do context "has no account balance" do it "is not allowed to sanction a housing loan" do puts "The loan cannot be sanctioned due to no balance in the account." end end end ==References== 2. Beck, K. (2014). Test-driven development by example. Boston: Addison-Wesley. ==External links== Official website RSpec-2 Beyond Test Driven Development - Behaviour Driven Development. A Google TechTalk by Dave Astels on BDD using RSpec. RSpec Best Practices Article by Jared Carroll, retrieved April 24, 2011. Behavior-driven testing with RSpec Article by Bruce Tate, retrieved July 21, 2011.

Text derived from https://en.wikipedia.org/w/index.php?oldid=1301356604 under CC BY-SA 4.0; modifications have been made.