|
20 | 20 | let(:testing1) { described_class.new("testing") } |
21 | 21 | let(:testing2) { described_class.new("testing") } |
22 | 22 | let(:not_testing) { described_class.new("not testing") } |
| 23 | + let(:testing3) { described_class.new("testing", :user) } |
23 | 24 |
|
24 | | - describe "#eql?" do |
25 | | - context "for two equal objects" do |
26 | | - it "returns true" do |
27 | | - expect(testing1).to eql(testing2) |
| 25 | + describe "Comparable" do |
| 26 | + describe "#eql?" do |
| 27 | + context "for two equal objects" do |
| 28 | + it "returns true" do |
| 29 | + expect(testing1).to eql(testing2) |
| 30 | + end |
| 31 | + end |
| 32 | + |
| 33 | + context "for two different objects" do |
| 34 | + it "returns false" do |
| 35 | + expect(testing1).not_to eql(not_testing) |
| 36 | + end |
| 37 | + end |
| 38 | + |
| 39 | + context 'for objects with identical data but different types' do |
| 40 | + it 'returns false' do |
| 41 | + expect(testing1).not_to eql(testing3) |
| 42 | + end |
28 | 43 | end |
29 | 44 | end |
30 | 45 |
|
31 | | - context "for two different objects" do |
32 | | - it "returns false" do |
33 | | - expect(testing1).not_to eql(not_testing) |
| 46 | + describe '#<=>' do |
| 47 | + context 'with a non-Binary object' do |
| 48 | + it 'returns nil' do |
| 49 | + expect(testing1 <=> 'bogus').to be_nil |
| 50 | + end |
| 51 | + end |
| 52 | + |
| 53 | + context 'with identical type and data' do |
| 54 | + it 'returns 0' do |
| 55 | + expect(testing1 <=> testing2).to be == 0 |
| 56 | + end |
| 57 | + end |
| 58 | + |
| 59 | + context 'with mismatched type' do |
| 60 | + it 'returns nil' do |
| 61 | + expect(testing1 <=> testing3).to be_nil |
| 62 | + end |
| 63 | + end |
| 64 | + |
| 65 | + context 'with identical type but mismatched data' do |
| 66 | + it 'returns -1 when a < b' do |
| 67 | + expect(not_testing <=> testing1).to be == -1 |
| 68 | + end |
| 69 | + |
| 70 | + it 'returns 1 when a > b' do |
| 71 | + expect(testing1 <=> not_testing).to be == 1 |
| 72 | + end |
34 | 73 | end |
35 | 74 | end |
36 | 75 | end |
|
0 commit comments