spec/utopia/content/links_spec.rb in utopia-2.11.1 vs spec/utopia/content/links_spec.rb in utopia-2.12.0

- old
+ new

@@ -1,6 +1,7 @@ #!/usr/bin/env rspec +# frozen_string_literal: true # Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com> # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -21,10 +22,13 @@ # THE SOFTWARE. require 'utopia/content/links' RSpec.describe Utopia::Content::Links do + let(:root) {File.expand_path("links", __dir__)} + subject {described_class.new(root)} + describe 'INDEX_XNODE_FILTER' do subject{Utopia::Content::Links::INDEX_XNODE_FILTER} it "should match index" do expect("index.xnode").to match(subject) @@ -34,17 +38,17 @@ expect("old-index.xnode").to_not match(subject) end end it "should not match partial strings" do - links = Utopia::Content::Links.index(File.expand_path("links", __dir__), Utopia::Path.create("/"), name: "come") + links = subject.index(Utopia::Path.create("/"), name: "come") expect(links).to be_empty end it "should give a list of links" do - links = Utopia::Content::Links.index(File.expand_path("links", __dir__), Utopia::Path.create("/")) + links = subject.index(Utopia::Path.create("/")) expect(links.size).to be == 3 expect(links[0].kind).to be == :virtual expect(links[0].href).to be == nil @@ -63,39 +67,35 @@ expect(links[1]).to be_eql links[1] expect(links[0]).to_not be_eql links[1] end it "should filter links by name" do - links = Utopia::Content::Links.index(File.expand_path("links", __dir__), Utopia::Path.create("/"), name: /foo/) + links = subject.index(Utopia::Path.create("/"), name: /foo/) expect(links.size).to be == 1 end it "should select localized links" do - root = File.expand_path("links", __dir__) - # Select both test links - links = Utopia::Content::Links.index(root, Utopia::Path.create("/foo")) + links = subject.index(Utopia::Path.create("/foo")) expect(links.size).to be == 2 - links = Utopia::Content::Links.index(root, Utopia::Path.create("/foo"), locale: 'en') + links = subject.index(Utopia::Path.create("/foo"), locale: 'en') expect(links.size).to be == 1 end - it "should read correct link order for en" do - root = File.expand_path("localized", __dir__) + context 'localized links' do + let(:root) {File.expand_path("localized", __dir__)} - # Select both test links - links = Utopia::Content::Links.index(root, Utopia::Path.create("/"), locale: 'en') + it "should read correct link order for en" do + links = subject.index(Utopia::Path.create("/"), locale: 'en') + + expect(links.collect(&:title)).to be == ['One', 'Two', 'Three', 'Four', 'Five'] + end - expect(links.collect(&:title)).to be == ['One', 'Two', 'Three', 'Four', 'Five'] - end - - it "should read correct link order for zh" do - root = File.expand_path("localized", __dir__) - - # Select both test links - links = Utopia::Content::Links.index(root, Utopia::Path.create("/"), locale: 'zh') - - expect(links.collect(&:title)).to be == ['One', 'Two', 'Three', '四'] + it "should read correct link order for zh" do + links = subject.index(Utopia::Path.create("/"), locale: 'zh') + + expect(links.collect(&:title)).to be == ['One', 'Two', 'Three', '四'] + end end end