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 May 22, 2021
1 parent dee630a commit 4f1feba
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
9 changes: 5 additions & 4 deletions spec/integration/editor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

expect {
status = described_class.open("newfile.txt", text: "Some text",
command: editor_command)
command: editor_command)
}.to output(/Some text/).to_stdout_from_any_process

expect(status).to eq(true)
Expand Down Expand Up @@ -70,7 +70,8 @@
editor_command = "ruby #{fixtures_path("echo.rb")}"

expect {
described_class.open("newfile1.txt", "newfile2.txt", text: "Some text",
described_class.open("newfile1.txt", "newfile2.txt",
text: "Some text",
command: editor_command)
}.to output(/newfile1\.txt newfile2\.txt/).to_stdout_from_any_process

Expand Down Expand Up @@ -100,7 +101,7 @@
"\e[2K\e[1G\e[1A" * 3,
"\e[2K\e[1G\e[J",
"Select an editor? \e[32m#{echo}\e[0m\n",
"\e[1A\e[2K\e[1G",
"\e[1A\e[2K\e[1G"
].join

expect {
Expand Down Expand Up @@ -133,7 +134,7 @@
"\e[2K\e[1G\e[1A" * 3,
"\e[2K\e[1G\e[J",
"Which one do you fancy? \e[32m#{cat}\e[0m\n",
"\e[1A\e[2K\e[1G",
"\e[1A\e[2K\e[1G"
].join

expect {
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/available_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
allow(described_class).to receive(:exist?).with("vim").and_return(true)
allow(described_class).to receive(:exist?).with("emacs").and_return(true)

expect(described_class.available).to eql(["vim", "emacs"])
expect(described_class.available).to eql(%w[vim emacs])
end

it "doesn't find any text editor" do
Expand Down
8 changes: 4 additions & 4 deletions spec/unit/command_path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
allow(editor).to receive(:system).and_return(true)
editor.open(filename)

expect(editor).to have_received(:system).
with({}, "vim", "/usr/bin/hello world.rb")
expect(editor).to have_received(:system)
.with({}, "vim", "/usr/bin/hello world.rb")
end

it "escapes path separators on Windows" do
Expand All @@ -25,7 +25,7 @@
allow(editor).to receive(:system).and_return(true)
editor.open(filename)

expect(editor).to have_received(:system).
with({}, "vim", "C:\\User\\hello world.rb")
expect(editor).to have_received(:system)
.with({}, "vim", "C:\\User\\hello world.rb")
end
end
4 changes: 2 additions & 2 deletions spec/unit/command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
end

it "finds more than one editor" do
allow(described_class).to receive(:available).and_return(["vim", "emacs"])
allow(described_class).to receive(:available).and_return(%w[vim emacs])
prompt = spy(:prompt, enum_select: "vim", up: "", clear_line: "")
allow(TTY::Prompt).to receive(:new).and_return(prompt)

Expand All @@ -64,7 +64,7 @@
end

it "doesn't show menu choice when disabled" do
allow(described_class).to receive(:available).and_return(["vim", "emacs"])
allow(described_class).to receive(:available).and_return(%w[vim emacs])
allow(TTY::Prompt).to receive(:new)

editor = described_class.new(show_menu: false)
Expand Down
1 change: 0 additions & 1 deletion spec/unit/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@
expect(editor.env).to eq({"FOO" => "bar"})
end
end

9 changes: 6 additions & 3 deletions spec/unit/open_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,19 @@
end

it "fails to open editor with unknown command" do
allow(described_class).to receive(:available).with(:unknown).and_return(["unknown"])
allow(described_class).to receive(:available).with(:unknown)
.and_return(["unknown"])
editor = described_class.new(command: :unknown)
status = editor.open(fixtures_path("content.txt"))
expect(status).to eq(false)
end

it "fails to open editor with unknown command and raises" do
allow(described_class).to receive(:available).with(:unknown).and_return(["unknown"])
allow(described_class).to receive(:available).with(:unknown)
.and_return(["unknown"])
expect {
described_class.open(fixtures_path("content.txt"), command: :unknown,
described_class.open(fixtures_path("content.txt"),
command: :unknown,
raise_on_failure: true)
}.to raise_error(TTY::Editor::CommandInvocationError)
end
Expand Down

0 comments on commit 4f1feba

Please sign in to comment.