What is the process for doing TDD in Ruby with RSpec without Rails?
Do I need a Gemfile? Does it only need rspec in it?
Ruby 1.9.3
Installing RSpecBoot up your terminal and punch in gem install rspec to install RSpec. Once that's done, you can verify your version of RSpec with rspec --version , which will output the current version of each of the packaged gems. Take a minute also to hit rspec --help and look through the various options available.
RSpec is a testing tool for Ruby, created for behavior-driven development (BDD). It is the most frequently used testing library for Ruby in production applications. Even though it has a very rich and powerful DSL (domain-specific language), at its core it is a simple tool which you can start using rather quickly.
The describe Keyword The word describe is an RSpec keyword. It is used to define an “Example Group”. You can think of an “Example Group” as a collection of tests. The describe keyword can take a class name and/or string argument.
Owl - Open Source RSpec Test Reporting Tool. Owl is an open source tool used for the reporting and presentation of tests results achieved using the RSpec open source testing tool. It stores the test results in a PostgreSQL database and provides features to report them.
The process is as follows:
Install the rspec gem from the console:
gem install rspec
Then create a folder (we'll name it root) with the following content:
root/my_model.rb
root/spec/my_model_spec.rb
#my_model.rb class MyModel def the_truth true end end #spec/my_model_spec.rb require_relative '../my_model' describe MyModel do it "should be true" do MyModel.new.the_truth.should be_true end end
Then in the console run
rspec spec/my_model_spec.rb
voila!
From within your projects directory...
gem install rspec rspec --init
then write specs in the spec dir created and run them via
rspec 'path to spec' # or just rspec to run them all
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With