Skip to content

Commit

Permalink
Calculate history id based on all test case parameters
Browse files Browse the repository at this point in the history
Revert back to using instance_variables in jsonable

Skip parameters and history_id memoize

Add ruby and oj test parameters

Add env vars to test step
  • Loading branch information
andrcuns committed Jun 6, 2023
1 parent 654c7d5 commit c3d8c71
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ jobs:
uses: paambaati/codeclimate-action@v4.0.0
env:
CC_TEST_REPORTER_ID: be263ef9412dc65a7aa8dfb6e8162d5c7cfb3307fae0a444cde9dd6ca6f52848
ALLURE_ENVIRONMENT: ruby-${{ matrix.ruby }}-oj-${{ matrix.oj }}
WITH_OJ_GEM: ${{ matrix.oj }}
RUBY_VERSION: ${{ matrix.ruby }}
with:
coverageCommand: bundle exec rake test:coverage
coverageLocations: coverage/coverage.json:simplecov
Expand Down
2 changes: 2 additions & 0 deletions allure-cucumber/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
RSpec.configure do |config|
config.before do |example|
example.epic("allure-cucumber")
example.parameter("ruby", ENV["RUBY_VERSION"])
example.parameter("oj", ENV["WITH_OJ_GEM"])
end
end

Expand Down
2 changes: 2 additions & 0 deletions allure-rspec/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
RSpec.configure do |config|
config.before do |example|
example.epic("allure-rspec")
example.parameter("ruby", ENV["RUBY_VERSION"])
example.parameter("oj", ENV["WITH_OJ_GEM"])
end
end

Expand Down
15 changes: 11 additions & 4 deletions allure-ruby-commons/lib/allure_ruby_commons/model/01_jsonable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class JSONable
# Return object hash represantation
# @return [Hash]
def to_hash
instance_variables.each_with_object({}) do |var, map|
key = camelcase(var.to_s.delete_prefix("@"))
value = instance_variable_get(var)
json_attributes.each_with_object({}) do |attribute, map|
key = camelcase(attribute)
value = send(attribute) # fetch via reader for dynamically generated attributes
map[key] = value unless value.nil?
end
end
Expand All @@ -33,7 +33,7 @@ def ==(other)
# Object state
# @return [Array]
def state
instance_variables.map { |var| instance_variable_get(var) }
json_attributes.map { |attribute| send(attribute) }
end

private
Expand All @@ -45,5 +45,12 @@ def camelcase(str)
str = str.gsub(/(?:_+)([a-z])/) { Regexp.last_match(1).upcase }
str.gsub(/(\A|\s)([A-Z])/) { Regexp.last_match(1) + Regexp.last_match(2).downcase }
end

# Json attribute names
#
# @return [Array<String>]
def json_attributes
@json_attributes ||= instance_variables.map { |attribute| attribute.to_s.delete_prefix("@") }
end
end
end
2 changes: 2 additions & 0 deletions allure-ruby-commons/lib/allure_ruby_commons/model/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ def initialize(name:, matched_statuses: nil, message_regex: nil, trace_regex: ni
@message_regex = message_regex
@trace_regex = trace_regex
end

attr_reader :name, :matched_statuses, :message_regex, :trace_regex
end
end
21 changes: 19 additions & 2 deletions allure-ruby-commons/lib/allure_ruby_commons/model/test_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,34 @@ def initialize(uuid: UUID.generate, history_id: UUID.generate, environment: nil,

@name = options[:name]
@uuid = uuid
@history_id = Digest::MD5.hexdigest("#{history_id}#{environment}")
@history_id = history_id
@full_name = options[:full_name] || "Unnamed"
@labels = options[:labels] || []
@links = options[:links] || []
@parameters << Parameter.new("environment", environment) if environment
end

attr_accessor :uuid,
:history_id,
:full_name,
:labels,
:links

attr_writer :history_id

# History id
#
# @return [String]
def history_id
Digest::MD5.hexdigest("#{@history_id}#{parameters_string}")
end

private

# All parameters string
#
# @return [String]
def parameters_string
parameters.map { |p| "#{p.name}=#{p.value}" }.join(";")
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ def initialize(uuid: UUID.generate, name: "Unnamed")
@links = []
end

attr_accessor :uuid, :name, :description, :description_html, :start, :stop, :children, :befores, :afters, :links
attr_accessor :uuid,
:name,
:description,
:description_html,
:start,
:stop,
:children,
:befores,
:afters,
:links
end
end
2 changes: 2 additions & 0 deletions allure-ruby-commons/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
RSpec.configure do |config|
config.before do |example|
example.epic("allure-ruby-commons")
example.parameter("ruby", ENV["RUBY_VERSION"])
example.parameter("oj", ENV["WITH_OJ_GEM"])
end
end

Expand Down

0 comments on commit c3d8c71

Please sign in to comment.