Skip to content

Instantly share code, notes, and snippets.

@anuragkanungo
Last active August 29, 2015 14:06
Show Gist options
  • Save anuragkanungo/e87d62deef148a0ca106 to your computer and use it in GitHub Desktop.
Save anuragkanungo/e87d62deef148a0ca106 to your computer and use it in GitHub Desktop.
describe Foo do
describe "Equality" do
it "is reflexive" do
foo = Foo.new(1,2)
expect(foo).to eq(foo)
end
describe "is symmetric" do
foo = Foo.new(1,2)
bar = Foo.new(1,2)
it "foo is equal to bar" { expect(foo).to eq(bar) }
it "bar is equal to foo" { expect(bar).to eq(foo) }
end
describe "is transitive" do
foo = Foo.new(1,2)
bar = Foo.new(1,2)
grill = Foo.new(1,2)
it "foo is equal to bar" { expect(foo).to eq(bar) }
it "bar is equal to grill" { expect(bar).to eq(grill) }
it "grill is equal to foo" { expect(grill).to eq(bar) }
end
it "is not equal for nil" do
foo = Foo.new(1,2)
expect(foo).to_not eq(nil)
end
it "is not equal for different types" do
foo = Foo.new(1,2)
expect(foo.class).to_not eq(Object.class)
end
it "hashes are equal if objects are equal" do
foo = Foo.new(1,2)
bar = Foo.new(1,2)
expect(foo.hash).to eq(bar.hash)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment