|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe Library::Base do |
| 4 | + let(:lib_dir) { 'lib/bashly/templates/lib' } |
| 5 | + |
| 6 | + describe '#content' do |
| 7 | + it "raises a NotImplementedError" do |
| 8 | + expect { subject.content }.to raise_error(NotImplementedError) |
| 9 | + end |
| 10 | + end |
| 11 | + |
| 12 | + describe '#files' do |
| 13 | + it "raises a NotImplementedError" do |
| 14 | + expect { subject.files }.to raise_error(NotImplementedError) |
| 15 | + end |
| 16 | + |
| 17 | + context "when #content is a string representing a lib/file" do |
| 18 | + subject do |
| 19 | + Class.new(described_class) { def content = "colors.sh" }.new |
| 20 | + end |
| 21 | + |
| 22 | + it "returns an array of hashes" do |
| 23 | + expect(subject.files).to be_an Array |
| 24 | + expect(subject.files.first).to be_a Hash |
| 25 | + end |
| 26 | + |
| 27 | + it "returns the content and target paths of the library files" do |
| 28 | + matter = subject.files.first |
| 29 | + expect(matter.keys).to eq [:path, :content] |
| 30 | + expect(matter[:path]).to eq "#{Settings.target_dir}/src/lib/#{subject.content}" |
| 31 | + expect(matter[:content]).to eq File.read("#{lib_dir}/#{subject.content}") |
| 32 | + end |
| 33 | + end |
| 34 | + |
| 35 | + context "when #content is a string representing a lib/dir" do |
| 36 | + subject do |
| 37 | + Class.new(described_class) { def content = "validations" }.new |
| 38 | + end |
| 39 | + |
| 40 | + it "returns an array of hashes" do |
| 41 | + expect(subject.files).to be_an Array |
| 42 | + expect(subject.files.first).to be_a Hash |
| 43 | + end |
| 44 | + |
| 45 | + it "returns an array as big as the library folder" do |
| 46 | + expect(subject.files.count).to be > 1 |
| 47 | + expect(subject.files.count).to eq Dir["#{lib_dir}/#{subject.content}/*.sh"].count |
| 48 | + end |
| 49 | + |
| 50 | + it "returns the content and target paths of the library files" do |
| 51 | + expect(subject.files.to_yaml).to match_approval 'library/base/dir' |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + context "when #content is a hash" do |
| 56 | + subject do |
| 57 | + Class.new(described_class) { def content = { some: 'hash' } }.new |
| 58 | + end |
| 59 | + |
| 60 | + it "returns an array with the hash as its first and only element" do |
| 61 | + expect(subject.files).to be_an Array |
| 62 | + expect(subject.files.count).to eq 1 |
| 63 | + expect(subject.files.first).to eq subject.content |
| 64 | + end |
| 65 | + end |
| 66 | + |
| 67 | + context "when #content is something else" do |
| 68 | + subject do |
| 69 | + Class.new(described_class) { def content = ["something else"] }.new |
| 70 | + end |
| 71 | + |
| 72 | + it "returns it as is" do |
| 73 | + expect(subject.files).to eq subject.content |
| 74 | + end |
| 75 | + end |
| 76 | + end |
| 77 | + |
| 78 | + describe '#post_install_message' do |
| 79 | + it "returns nil" do |
| 80 | + expect(subject.post_install_message).to be_nil |
| 81 | + end |
| 82 | + end |
| 83 | +end |
0 commit comments