|
4 | 4 |
|
5 | 5 | describe Appraisal::Customize do
|
6 | 6 | let(:appraisal) { Appraisal::Appraisal.new("test", "Gemfile") }
|
| 7 | + let(:single_line_heading) { "This file was generated with a custom heading!" } |
| 8 | + let(:multi_line_heading) do |
| 9 | + <<~HEADING |
| 10 | + frozen_string_literal: true |
7 | 11 |
|
8 |
| - it "has defaults" do |
9 |
| - expect(described_class.heading(appraisal)).to eq nil |
10 |
| - expect(described_class.single_quotes).to eq false |
11 |
| - expect { described_class.new }.to_not(change do |
12 |
| - [described_class.heading(appraisal), described_class.single_quotes] |
13 |
| - end) |
| 12 | + This file was generated with a custom heading! |
| 13 | + HEADING |
14 | 14 | end
|
| 15 | + let(:subject) { described_class.new } |
| 16 | + let(:single_line_subject) do |
| 17 | + described_class.new(heading: single_line_heading) |
| 18 | + end |
| 19 | + let(:multi_line_single_quotes_subject) do |
| 20 | + described_class.new(heading: multi_line_heading, single_quotes: true) |
| 21 | + end |
| 22 | + |
| 23 | + describe ".heading" do |
| 24 | + it "returns nil if no heading is set" do |
| 25 | + subject |
| 26 | + expect(described_class.heading(appraisal)).to eq(nil) |
| 27 | + end |
| 28 | + |
| 29 | + it "returns the heading if set" do |
| 30 | + single_line_subject |
| 31 | + expect(described_class.heading(appraisal)).to eq(single_line_heading) |
| 32 | + end |
| 33 | + |
| 34 | + it "returns the heading without an trailing newline" do |
| 35 | + multi_line_single_quotes_subject |
| 36 | + expect(described_class.heading(appraisal)).to eq(multi_line_heading.chomp) |
| 37 | + expect(described_class.heading(appraisal)).to_not end_with("\n") |
| 38 | + end |
| 39 | + end |
| 40 | + |
| 41 | + describe ".single_quotes" do |
| 42 | + it "returns false if not set" do |
| 43 | + subject |
| 44 | + expect(described_class.single_quotes).to eq(false) |
| 45 | + end |
| 46 | + |
| 47 | + it "returns true if set" do |
| 48 | + multi_line_single_quotes_subject |
| 49 | + expect(described_class.single_quotes).to eq(true) |
| 50 | + end |
| 51 | + end |
| 52 | + |
| 53 | + describe ".customize" do |
| 54 | + let(:gemfile) { "test.gemfile" } |
| 55 | + let(:relative_path) { "gemfiles/#{gemfile}" } |
| 56 | + let(:full_path) { "/path/to/project/#{relative_path}" } |
| 57 | + before do |
| 58 | + allow(appraisal).to receive(:gemfile_name).and_return(gemfile) |
| 59 | + allow(appraisal).to receive(:gemfile_path).and_return(full_path) |
| 60 | + allow(appraisal).to receive(:relative_gemfile_path) |
| 61 | + .and_return(relative_path) |
| 62 | + end |
| 63 | + |
| 64 | + it "returns nil if no heading is set" do |
| 65 | + subject |
| 66 | + expect(described_class.send(:customize, nil, appraisal)).to eq(nil) |
| 67 | + end |
| 68 | + |
| 69 | + it "returns the heading unchanged" do |
| 70 | + single_line_subject |
| 71 | + expect(described_class.send( |
| 72 | + :customize, |
| 73 | + single_line_heading, |
| 74 | + appraisal, |
| 75 | + )).to eq(single_line_heading) |
| 76 | + end |
| 77 | + |
| 78 | + it "returns the heading with the gemfile name" do |
| 79 | + expect(described_class.send( |
| 80 | + :customize, |
| 81 | + "Gemfile: %{gemfile}", # rubocop:disable Style/FormatStringToken |
| 82 | + appraisal, |
| 83 | + )).to eq("Gemfile: #{gemfile}") |
| 84 | + end |
| 85 | + |
| 86 | + it "returns the heading with the gemfile path" do |
| 87 | + expect(described_class.send( |
| 88 | + :customize, |
| 89 | + "Gemfile: %{gemfile_path}", # rubocop:disable Style/FormatStringToken |
| 90 | + appraisal, |
| 91 | + )).to eq("Gemfile: #{full_path}") |
| 92 | + end |
15 | 93 |
|
16 |
| - it "can override defaults" do |
17 |
| - described_class.new(single_quotes: true, heading: "foo") |
18 |
| - expect(described_class.heading(appraisal)).to eq "foo" |
19 |
| - expect(described_class.single_quotes).to eq true |
| 94 | + it "returns the heading with the relative gemfile path" do |
| 95 | + expect(described_class.send( |
| 96 | + :customize, |
| 97 | + "Gemfile: %{relative_gemfile_path}", # rubocop:disable Style/FormatStringToken, Metrics/LineLength |
| 98 | + appraisal, |
| 99 | + )).to eq("Gemfile: #{relative_path}") |
| 100 | + end |
20 | 101 | end
|
21 | 102 | end
|
0 commit comments