Helpful link for rails
testing here.
Ensure rspec
gem installed.
# calculator.rb class Calculator def add(x, y) x + y end end # calculator_spec.rb require './calculator.rb' describe "calculator" do it "adds numbers" do calc = Calculator.new expect(calc.add(2,3)).to eql(5) end end
Run rspec calculator_spec.rb
.
# calculator.rb class Calculator def add(x, y) x + y end end
require './calculator.rb' describe "calculator" do it "adds numbers" end
Running rspec calculator_spec.rb
should come back with 1 pending test.
require './calculator.rb' describe "calculator" do it "adds numbers" do calc = Calculator.new expect(calc.add(2,3)).to eql(5) end end
Running rspec calculator_spec.rb
should come back with 1 successful test.
# flags.rb module Flags Truthy = :truthy end # flags_spec.rb require './flags.rb' describe 'for flag module' do context 'when ruby symbol is involved' do subject { Flags::Truthy } it { expect(subject).to eq(:truthy)} end end
rspec flags_spec.rb