Note: This guide assumes you have Ruby installed.
-
Install Bundler
gem install bundler
-
Create a new project folder for the code:
(Assuming project name is
new_kata
)mkdir new_kata cd new_kata
-
In the new project folder, initialize the
Gemfile
bundle init
-
Install RSpec
bundle add rspec --group "test"
-
Initialize an RSpec test suite
bundle exec rspec --init
-
Create a test file (
spec/sum_spec.rb
) with the following content:require 'spec_helper' require_relative '../sum' describe 'sum' do it 'adds 1 + 2 to equal 3' do expect(sum(1, 2)).to eq 3 end end
-
Create
sum.rb
with the following content:def sum(a, b) a + b end
-
Run the test
bundle exec rspec
You should see this:
. Finished in 0.00456 seconds (files took 0.10443 seconds to load) 1 example, 0 failures
-
Read up more about the types of test matchers available in RSpec: https://relishapp.com/rspec/rspec-expectations/v/3-8/docs