Skip to content

Commit

Permalink
Change tests to improve formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Mar 24, 2024
1 parent 4967f09 commit 3471ac3
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 41 deletions.
8 changes: 4 additions & 4 deletions spec/unit/link_to_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/parse_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
99 changes: 63 additions & 36 deletions spec/unit/support_link_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3471ac3

Please sign in to comment.