Skip to content

Commit

Permalink
Added handling for error during evaluating the expectation
Browse files Browse the repository at this point in the history
  • Loading branch information
kobliha committed Jun 16, 2015
1 parent f8f72a0 commit 50e05c3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/lib/installation/proposal_store.rb
Expand Up @@ -279,25 +279,30 @@ def should_be_called_again?(client)
@triggers ||= {}
return false unless @triggers.has_key?(client)

if @triggers[client].has_key?("expect") &&
@triggers[client]["expect"].is_a?(String) &&
@triggers[client].has_key?("value")
unless @triggers[client].has_key?("expect") &&
@triggers[client]["expect"].is_a?(String) &&
@triggers[client].has_key?("value")

expectation_code = @triggers[client]["expect"]
expectation_value = @triggers[client]["value"]
raise "Incorrect definition of 'trigger': #{@triggers[client]} "
"both [String] 'expect' and [Any] 'value' must be set"
end

expectation_code = @triggers[client]["expect"]
expectation_value = @triggers[client]["value"]

begin
value = eval(expectation_code)
rescue Exception => error
raise "Checking the trigger expectations for #{client} have failed:\n#{error}"
end

if value == expectation_value
log.info "Proposal client #{client}: returned value matches expectation '#{value}'"
return false
else
log.info "Proposal client #{client}: returned value '#{value}' "
"does not match expected value '#{expectation_value}'"
return true
end
if value == expectation_value
log.info "Proposal client #{client}: returned value matches expectation '#{value}'"
return false
else
raise "Incorrect definition of 'trigger': #{@triggers[client]} "
"both [String] 'expect' and [Any] 'value' must be set"
log.info "Proposal client #{client}: returned value '#{value}' "
"does not match expected value '#{expectation_value}'"
return true
end
end

Expand Down
21 changes: 21 additions & 0 deletions test/proposal_store_test.rb
Expand Up @@ -262,6 +262,19 @@ def mock_properties(data = {})
}
}}

let(:proposal_c_with_exception) {{
"rich_text_title" => "Proposal C",
"menu_title" => "&Proposal C",
"trigger" => {
# 'expect' must be a string that is evaluated later
"expect" => "
test2 = nil
test2.first
",
"value" => 22,
}
}}

describe "#make_proposals" do
before do
allow(subject).to receive(:proposal_names).and_return(proposal_names)
Expand Down Expand Up @@ -349,6 +362,14 @@ def mock_properties(data = {})
expect { subject.make_proposals }.to raise_error /Incorrect definition/
end
end

context "when trigger from proposal raises an exception" do
it "raises an exception" do
allow(Yast::WFM).to receive(:CallFunction).with("proposal_c", anything()).and_return(proposal_c_with_exception)

expect { subject.make_proposals }.to raise_error /Checking the trigger expectations for proposal_c have failed/
end
end
end

let(:client_description) {{
Expand Down

0 comments on commit 50e05c3

Please sign in to comment.