| @@ -5,20 +5,35 @@ class DocsEntryTest < MiniTest::Spec · 4 unmodified lines |
| 5 | Entry = Docs::Entry | 5 | Entry = Docs::Entry |
| 6 | | 6 | |
| 7 | let :entry do | 7 | let :entry do |
| 8 | Entry.new | 8 | Entry.new('name', 'path', 'type') |
| | 9 | end |
| | 10 | |
| | 11 | def build_entry(name = 'name', path = 'path', type = 'type') |
| | 12 | Entry.new(name, path, type) |
| 9 | end | 13 | end |
| 10 | | 14 | |
| 11 | describe ".new" do | 15 | describe ".new" do |
| 12 | it "stores a name" do | 16 | it "stores #name, #path and #type" do |
| 13 | assert_equal 'name', Entry.new('name').name | 17 | entry = Entry.new('name', 'path', 'type') |
| | 18 | assert_equal 'name', entry.name |
| | 19 | assert_equal 'path', entry.path |
| | 20 | assert_equal 'type', entry.type |
| 14 | end | 21 | end |
| 15 | | 22 | |
| 16 | it "stores a path" do | 23 | it "raises an error when #name, #path or #type is nil or empty" do |
| 17 | assert_equal 'path', Entry.new(nil, 'path').path | 24 | assert_raises(Docs::Entry::Invalid) { Entry.new(nil, 'path', 'type') } |
| | 25 | assert_raises(Docs::Entry::Invalid) { Entry.new('', 'path', 'type') } |
| | 26 | assert_raises(Docs::Entry::Invalid) { Entry.new('name', nil, 'type') } |
| | 27 | assert_raises(Docs::Entry::Invalid) { Entry.new('name', '', 'type') } |
| | 28 | assert_raises(Docs::Entry::Invalid) { Entry.new('name', 'path', nil) } |
| | 29 | assert_raises(Docs::Entry::Invalid) { Entry.new('name', 'path', '') } |
| 18 | end | 30 | end |
| 19 | | 31 | |
| 20 | it "stores a type" do | 32 | it "don't raise an error when #path is 'index' and #name or #type is nil or empty" do |
| 21 | assert_equal 'type', Entry.new(nil, nil, 'type').type | 33 | Entry.new(nil, 'index', 'type') |
| | 34 | Entry.new('', 'index', 'type') |
| | 35 | Entry.new('name', 'index', nil) |
| | 36 | Entry.new('name', 'index', '') |
| 22 | end | 37 | end |
| 23 | end | 38 | end |
| 24 | | 39 | |
| @@ -48,40 +63,40 @@ class DocsEntryTest < MiniTest::Spec · 23 unmodified lines |
| 48 | | 63 | |
| 49 | describe "#==" do | 64 | describe "#==" do |
| 50 | it "returns true when the other has the same name, path and type" do | 65 | it "returns true when the other has the same name, path and type" do |
| 51 | assert_equal Entry.new, Entry.new | 66 | assert_equal build_entry, build_entry |
| 52 | end | 67 | end |
| 53 | | 68 | |
| 54 | it "returns false when the other has a different name" do | 69 | it "returns false when the other has a different name" do |
| 55 | entry.name = 'name' | 70 | entry.name = 'other_name' |
| 56 | refute_equal Entry.new, entry | 71 | refute_equal build_entry, entry |
| 57 | end | 72 | end |
| 58 | | 73 | |
| 59 | it "returns false when the other has a different path" do | 74 | it "returns false when the other has a different path" do |
| 60 | entry.path = 'path' | 75 | entry.path = 'other_path' |
| 61 | refute_equal Entry.new, entry | 76 | refute_equal build_entry, entry |
| 62 | end | 77 | end |
| 63 | | 78 | |
| 64 | it "returns false when the other has a different type" do | 79 | it "returns false when the other has a different type" do |
| 65 | entry.type = 'type' | 80 | entry.type = 'other_type' |
| 66 | refute_equal Entry.new, entry | 81 | refute_equal build_entry, entry |
| 67 | end | 82 | end |
| 68 | end | 83 | end |
| 69 | | 84 | |
| 70 | describe "#<=>" do | 85 | describe "#<=>" do |
| 71 | it "returns 1 when the other's name is less" do | 86 | it "returns 1 when the other's name is less" do |
| 72 | assert_equal 1, Entry.new('b') <=> Entry.new('a') | 87 | assert_equal 1, build_entry('b') <=> build_entry('a') |
| 73 | end | 88 | end |
| 74 | | 89 | |
| 75 | it "returns -1 when the other's name is greater" do | 90 | it "returns -1 when the other's name is greater" do |
| 76 | assert_equal -1, Entry.new('a') <=> Entry.new('b') | 91 | assert_equal -1, build_entry('a') <=> build_entry('b') |
| 77 | end | 92 | end |
| 78 | | 93 | |
| 79 | it "returns 0 when the other's name is equal" do | 94 | it "returns 0 when the other's name is equal" do |
| 80 | assert_equal 0, Entry.new('a') <=> Entry.new('a') | 95 | assert_equal 0, build_entry('a') <=> build_entry('a') |
| 81 | end | 96 | end |
| 82 | | 97 | |
| 83 | it "is case-insensitive" do | 98 | it "is case-insensitive" do |
| 84 | assert_equal 0, Entry.new('a') <=> Entry.new('A') | 99 | assert_equal 0, build_entry('a') <=> build_entry('A') |
| 85 | end | 100 | end |
| 86 | end | 101 | end |
| 87 | | 102 | |