Skip to content

Instantly share code, notes, and snippets.

@ArturT
Created September 29, 2015 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArturT/701aa4ed2d49071abbe2 to your computer and use it in GitHub Desktop.
Save ArturT/701aa4ed2d49071abbe2 to your computer and use it in GitHub Desktop.
Exercise. Create class Square to pass tests or implement tests for the class.
require 'rspec'
class Square
def initialize(x, y)
@x = x
@y = y
end
def area
@x * @y
end
end
describe Square do
describe '#area' do
subject { described_class.new(x, y).area }
context 'when x=2 and y=3' do
let(:x) { 2 }
let(:y) { 3 }
it { should eq 6 }
end
context 'when x=2 and y=2' do
let(:x) { 2 }
let(:y) { 2 }
it { should eq 4 }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment