diff --git a/spec/unit/link_to_spec.rb b/spec/unit/link_to_spec.rb index 81b2626..b454936 100644 --- a/spec/unit/link_to_spec.rb +++ b/spec/unit/link_to_spec.rb @@ -2,17 +2,17 @@ RSpec.describe TTY::Link, "#link_to" do it "creates a terminal link" do - allow(TTY::Link).to receive(:support_link?).and_return(true) + allow(described_class).to receive(:support_link?).and_return(true) - link = TTY::Link.link_to("TTY Toolkit", "https://ttytoolkit.org") + link = described_class.link_to("TTY Toolkit", "https://ttytoolkit.org") expect(link).to eql("\e]8;;https://ttytoolkit.org\aTTY Toolkit\e]8;;\a") end it "fails to create a terminal link" do - allow(TTY::Link).to receive(:support_link?).and_return(false) + allow(described_class).to receive(:support_link?).and_return(false) - link = TTY::Link.link_to("TTY Toolkit", "https://ttytoolkit.org") + link = described_class.link_to("TTY Toolkit", "https://ttytoolkit.org") expect(link).to eql("TTY Toolkit -> https://ttytoolkit.org") end diff --git a/spec/unit/parse_version_spec.rb b/spec/unit/parse_version_spec.rb index c33f943..a806171 100644 --- a/spec/unit/parse_version_spec.rb +++ b/spec/unit/parse_version_spec.rb @@ -7,7 +7,7 @@ {from: "0.51.0", to: {major: 0, minor: 51, patch: 0}} ].each do |data| it "parses #{data[:from]} to #{data[:to]}" do - expect(TTY::Link.parse_version(data[:from])).to eq(data[:to]) + expect(described_class.parse_version(data[:from])).to eq(data[:to]) end end end diff --git a/spec/unit/support_link_spec.rb b/spec/unit/support_link_spec.rb index 7e8b644..b390f16 100644 --- a/spec/unit/support_link_spec.rb +++ b/spec/unit/support_link_spec.rb @@ -4,61 +4,88 @@ let(:output) { double(:output) } before { + allow(ENV).to receive(:[]).and_return(nil) allow(output).to receive(:tty?).and_return(true) } - it "doesn't print links to non tty device" do - allow(output).to receive(:tty?).and_return(false) + describe "non TTY device" do + it "doesn't support links" do + allow(output).to receive(:tty?).and_return(false) - expect(TTY::Link.support_link?(output: output)).to eq(false) + expect(described_class.support_link?(output: output)).to eq(false) + end end - it "supports links in iTerm" do - allow(ENV).to receive(:[]).with("TERM_PROGRAM").and_return("iTerm.app") - allow(ENV).to receive(:[]).with("TERM_PROGRAM_VERSION").and_return("3.3.1") + describe "iTerm" do + before { + allow(ENV).to receive(:[]).with("TERM_PROGRAM").and_return("iTerm.app") + } - expect(TTY::Link.support_link?(output: output)).to eq(true) - end + it "supports links above the 4.3.2 version" do + allow(ENV).to receive(:[]).with("TERM_PROGRAM_VERSION") + .and_return("4.3.2") - it "support links in iTerm" do - allow(ENV).to receive(:[]).with("TERM_PROGRAM").and_return("iTerm.app") - allow(ENV).to receive(:[]).with("TERM_PROGRAM_VERSION").and_return("3.1.0") + expect(described_class.support_link?(output: output)).to eq(true) + end - expect(TTY::Link.support_link?(output: output)).to eq(true) - end + it "supports links above the 3.1.0 version" do + allow(ENV).to receive(:[]).with("TERM_PROGRAM_VERSION") + .and_return("3.2.1") - it "doesn't support links in iTerm below 3.0.0" do - allow(ENV).to receive(:[]).with("TERM_PROGRAM").and_return("iTerm.app") - allow(ENV).to receive(:[]).with("TERM_PROGRAM_VERSION").and_return("3.0.0") + expect(described_class.support_link?(output: output)).to eq(true) + end - expect(TTY::Link.support_link?(output: output)).to eq(false) - end + it "supports links on the 3.1.0 version" do + allow(ENV).to receive(:[]).with("TERM_PROGRAM_VERSION") + .and_return("3.1.0") - it "supports links in VTE terminal above 0.50.0" do - allow(ENV).to receive(:[]).with("TERM_PROGRAM").and_return("GNU") - allow(ENV).to receive(:[]).with("VTE_VERSION").and_return("0.50.1") + expect(described_class.support_link?(output: output)).to eq(true) + end - expect(TTY::Link.support_link?(output: output)).to eq(true) - end + it "doesn't support links on the 3.0.1 version" do + allow(ENV).to receive(:[]).with("TERM_PROGRAM_VERSION") + .and_return("3.0.1") + + expect(described_class.support_link?(output: output)).to eq(false) + end - it "supports links in VTE terminal above 0.51.0" do - allow(ENV).to receive(:[]).with("TERM_PROGRAM").and_return("GNU") - allow(ENV).to receive(:[]).with("VTE_VERSION").and_return("0.51.0") + it "doesn't support links below the 3.1.0 version" do + allow(ENV).to receive(:[]).with("TERM_PROGRAM_VERSION") + .and_return("2.3.4") - expect(TTY::Link.support_link?(output: output)).to eq(true) + expect(described_class.support_link?(output: output)).to eq(false) + end end - it "supports links in VTE terminal above 1.0.0" do - allow(ENV).to receive(:[]).with("TERM_PROGRAM").and_return("GNU") - allow(ENV).to receive(:[]).with("VTE_VERSION").and_return("1.0.0") + describe "VTE" do + it "supports links above the 1.0.0 version" do + allow(ENV).to receive(:[]).with("VTE_VERSION").and_return("1.0.0") - expect(TTY::Link.support_link?(output: output)).to eq(true) - end + expect(described_class.support_link?(output: output)).to eq(true) + end + + it "supports links above the 0.51.0 version" do + allow(ENV).to receive(:[]).with("VTE_VERSION").and_return("0.51.0") + + expect(described_class.support_link?(output: output)).to eq(true) + end + + it "supports links above the 0.50.1 version" do + allow(ENV).to receive(:[]).with("VTE_VERSION").and_return("0.50.1") + + expect(described_class.support_link?(output: output)).to eq(true) + end + + it "doesn't support links on the 0.50.0 version" do + allow(ENV).to receive(:[]).with("VTE_VERSION").and_return("0.50.0") + + expect(described_class.support_link?(output: output)).to eq(false) + end - it "doesn't support links in VTE terminal below 0.50.0" do - allow(ENV).to receive(:[]).with("TERM_PROGRAM").and_return("GNU") - allow(ENV).to receive(:[]).with("VTE_VERSION").and_return("0.50.0") + it "doesn't support links below the 0.50.0 version" do + allow(ENV).to receive(:[]).with("VTE_VERSION").and_return("0.49.0") - expect(TTY::Link.support_link?(output: output)).to eq(false) + expect(described_class.support_link?(output: output)).to eq(false) + end end end