Skip to content

Commit

Permalink
Use a better exception if Popup.Feedback does not get a block
Browse files Browse the repository at this point in the history
Before: NoMethodError: undefined method `call' for nil:NilClass
After:  ArgumentError: block must be supplied

This fixes a RSpec warning about testing a generic exception:
Using the `raise_error` matcher without providing a specific error or message
  • Loading branch information
mvidner committed Jul 29, 2016
1 parent 8763f9b commit 9a7d72a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
2 changes: 2 additions & 0 deletions library/general/src/modules/Popup.rb
Expand Up @@ -1068,6 +1068,8 @@ def ShowFeedback(headline, message)
# @param message [String] message with details, displayed below the headline
# @param block block to execute
def Feedback(headline, message, &block)
raise ArgumentError, "block must be supplied" unless block

ShowFeedback(headline, message)
block.call
ensure
Expand Down
40 changes: 22 additions & 18 deletions library/general/test/popup_test.rb
Expand Up @@ -14,26 +14,30 @@
end

describe ".Feedback" do
before do
expect(ui).to receive(:OpenDialog)
expect(ui).to receive(:CloseDialog)
allow(ui).to receive(:BusyCursor)
allow(ui).to receive(:GetDisplayInfo).and_return({})
context "when arguments are good" do
before do
expect(ui).to receive(:OpenDialog)
expect(ui).to receive(:CloseDialog)
allow(ui).to receive(:BusyCursor)
allow(ui).to receive(:GetDisplayInfo).and_return({})
end

it "opens a popup dialog and closes it at the end" do
# just pass an empty block
subject.Feedback("Label", "Message") {}
end

it "closes the popup even when an exception occurs in the block" do
# raise an exception in the block
expect { subject.Feedback("Label", "Message") { raise "TEST" } }.to raise_error(RuntimeError, "TEST")
end
end

it "opens a popup dialog and closes it at the end" do
# just pass an empty block
subject.Feedback("Label", "Message") {}
end

it "closes the popup even when an exception occurs in the block" do
# raise an exception in the block
expect { subject.Feedback("Label", "Message") { raise "TEST" } }.to raise_error(RuntimeError, "TEST")
end

it "raises exception when the block parameter is missing" do
# no block passed
expect { subject.Feedback("Label", "Message") }.to raise_error
context "when arguments are bad" do
it "raises exception when the block parameter is missing" do
# no block passed
expect { subject.Feedback("Label", "Message") }.to raise_error(ArgumentError, /block must be supplied/)
end
end
end

Expand Down

0 comments on commit 9a7d72a

Please sign in to comment.