Skip to content

Commit

Permalink
Fix incorrect command in error message
Browse files Browse the repository at this point in the history
  • Loading branch information
revolter committed Nov 4, 2020
1 parent d1a4372 commit 17813a8
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
## master
<!-- Your comment below here -->

* Fix incorrect command in error message [@revolter](https://github.com/revolter)

<!-- Your comment above here -->

Expand Down
2 changes: 1 addition & 1 deletion lib/danger/commands/dry_run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def initialize(argv)
super

if argv.flag?("pry", false)
@dangerfile_path = PrySetup.new(cork).setup_pry(@dangerfile_path)
@dangerfile_path = PrySetup.new(cork).setup_pry(@dangerfile_path, DryRun.command)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/danger/commands/local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def initialize(argv)
super

if argv.flag?("pry", false)
@dangerfile_path = PrySetup.new(cork).setup_pry(@dangerfile_path)
@dangerfile_path = PrySetup.new(cork).setup_pry(@dangerfile_path, Local.command)
end
end

Expand Down
8 changes: 4 additions & 4 deletions lib/danger/commands/local_helpers/pry_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ def initialize(cork)
@cork = cork
end

def setup_pry(dangerfile_path)
def setup_pry(dangerfile_path, command)
return dangerfile_path if dangerfile_path.empty?
validate_pry_available
validate_pry_available(command)
FileUtils.cp dangerfile_path, DANGERFILE_COPY
File.open(DANGERFILE_COPY, "a") do |f|
f.write("\nbinding.pry; File.delete(\"#{DANGERFILE_COPY}\")")
Expand All @@ -20,10 +20,10 @@ def setup_pry(dangerfile_path)

DANGERFILE_COPY = "_Dangerfile.tmp".freeze

def validate_pry_available
def validate_pry_available(command)
Kernel.require "pry"
rescue LoadError
cork.warn "Pry was not found, and is required for 'danger pr --pry'."
cork.warn "Pry was not found, and is required for 'danger #{command} --pry'."
cork.print_warnings
abort
end
Expand Down
2 changes: 1 addition & 1 deletion lib/danger/commands/pr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def initialize(argv)
@dangerfile_path = dangerfile if File.exist?(dangerfile)

if argv.flag?("pry", false)
@dangerfile_path = PrySetup.new(cork).setup_pry(@dangerfile_path)
@dangerfile_path = PrySetup.new(cork).setup_pry(@dangerfile_path, PR.command)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/danger/commands/staging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def initialize(argv)
super

if argv.flag?("pry", false)
@dangerfile_path = PrySetup.new(cork).setup_pry(@dangerfile_path)
@dangerfile_path = PrySetup.new(cork).setup_pry(@dangerfile_path, Staging.command)
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/lib/danger/commands/local_helpers/pry_setup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

dangerfile_copy = described_class
.new(testing_ui)
.setup_pry(dangerfile_path)
.setup_pry(dangerfile_path, "pr")

expect(File).to exist(dangerfile_copy)
expect(File.read(dangerfile_copy)).to include("binding.pry; File.delete(\"_Dangerfile.tmp\")")
end
end

it "doesn't copy a nonexistant Dangerfile" do
described_class.new(testing_ui).setup_pry("")
described_class.new(testing_ui).setup_pry("", "pr")

expect(File).not_to exist("_Dangerfile.tmp")
end
Expand All @@ -30,7 +30,7 @@
expect(Kernel).to receive(:require).with("pry").and_raise(LoadError)

expect do
described_class.new(ui).setup_pry("Dangerfile")
described_class.new(ui).setup_pry("Dangerfile", "pr")
end.to raise_error(SystemExit)
expect(ui.err_string).to include("Pry was not found")
end
Expand Down

0 comments on commit 17813a8

Please sign in to comment.