Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions allure-ruby-commons/lib/allure-ruby-commons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,42 @@ def description_html(description_html)
end
end

# Add precondition to current test case
# @param [String] precondition
# @return [void]
def add_precondition(precondition)
lifecycle.update_test_case do |test_case|
test_case.precondition = precondition
end
end

# Add html precondition to current test case
# @param [String] precondition_html
# @return [void]
def precondition_html(precondition_html)
lifecycle.update_test_case do |test_case|
test_case.precondition_html = precondition_html
end
end

# Add expected result to current test case
# @param [String] expected_result
# @return [void]
def add_expected_result(expected_result)
lifecycle.update_test_case do |test_case|
test_case.expected_result = expected_result
end
end

# Add html expected result to current test case
# @param [String] expected_result_html
# @return [void]
def expected_result_html(expected_result_html)
lifecycle.update_test_case do |test_case|
test_case.expected_result_html = expected_result_html
end
end

# Add parameter to current test case
# @param [String] name
# @param [String] value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class TestResult < ExecutableItem
# @option options [Array<String>] :title_path
# @option options [String] :description
# @option options [String] :description_html
# @option options [String] :precondition
# @option options [String] :precondition_html
# @option options [String] :expected_result
# @option options [String] :expected_result_html
# @option options [String] :status ('broken')
# @option options [String] :stage ('scheduled')
# @option options [Allure::StatusDetails] :status_details
Expand All @@ -28,6 +32,10 @@ def initialize(uuid: SecureRandom.uuid, history_id: SecureRandom.uuid, environme
@history_id = history_id
@full_name = options[:full_name] || "Unnamed"
@title_path = options[:title_path]
@precondition = options[:precondition]
@precondition_html = options[:precondition_html]
@expected_result = options[:expected_result]
@expected_result_html = options[:expected_result_html]
@labels = options[:labels] || []
@links = options[:links] || []
@parameters << Parameter.new("environment", environment) if environment
Expand All @@ -36,6 +44,10 @@ def initialize(uuid: SecureRandom.uuid, history_id: SecureRandom.uuid, environme
attr_accessor :uuid,
:full_name,
:title_path,
:precondition,
:precondition_html,
:expected_result,
:expected_result_html,
:labels,
:links

Expand Down
15 changes: 15 additions & 0 deletions allure-ruby-commons/spec/unit/allure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ def lifecycle
end
end

context "with precondition and expected result helpers" do
[
[:add_precondition, "precondition", "User is logged in"],
[:precondition_html, "preconditionHtml", "<p>User is logged in</p>"],
[:add_expected_result, "expectedResult", "Dashboard is displayed"],
[:expected_result_html, "expectedResultHtml", "<p>Dashboard is displayed</p>"]
].each do |method, key, value|
it "sets test case #{key}" do
allure.public_send(method, value)

expect(@test_case.to_hash[key]).to eq(value)
end
end
end

context "with parameter helpers" do
it "adds test parameter" do
allure.parameter("name", "value", excluded: true, mode: Allure::Parameter::MASKED)
Expand Down
18 changes: 18 additions & 0 deletions allure-ruby-commons/spec/unit/test_result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,24 @@
end
end

context "with preconditions and expected results" do
it "serializes fields supplied at initialization" do
result = Allure::TestResult.new(
precondition: "User is logged in",
precondition_html: "<p>User is logged in</p>",
expected_result: "Dashboard is displayed",
expected_result_html: "<p>Dashboard is displayed</p>"
)

expect(result.to_hash).to include(
"precondition" => "User is logged in",
"preconditionHtml" => "<p>User is logged in</p>",
"expectedResult" => "Dashboard is displayed",
"expectedResultHtml" => "<p>Dashboard is displayed</p>"
)
end
end

context "with allure environment" do
let(:environment) { "test" }

Expand Down
Loading