Skip to content

Commit

Permalink
resolve to microseconds (#109)
Browse files Browse the repository at this point in the history
* resolve to microseconds

* shouldn't happen in the real world, but .self.extract_metadata_and_tags supports extracting metadata and tags from empty metadata hash

* test formatter precision

* Bump rspec-abq to 1.1.3
  • Loading branch information
michaelglass authored Feb 16, 2023
1 parent eba1f09 commit 37fd93f
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 19 deletions.
12 changes: 6 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ GIT
PATH
remote: .
specs:
rspec-abq (1.1.2)
rspec-abq (1.1.3)
rspec-core (>= 3.5.0, < 3.13.0)

GEM
Expand Down Expand Up @@ -96,7 +96,7 @@ GEM
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.26.0)
parser (>= 3.2.1.0)
rubocop-capybara (2.17.0)
rubocop-capybara (2.17.1)
rubocop (~> 1.41)
rubocop-performance (1.15.2)
rubocop (>= 1.7.0, < 2.0)
Expand All @@ -106,10 +106,10 @@ GEM
rubocop-rspec (2.18.1)
rubocop (~> 1.33)
rubocop-capybara (~> 2.17)
ruby-lsp (0.3.8)
ruby-lsp (0.4.0)
language_server-protocol (~> 3.17.0)
sorbet-runtime
syntax_tree (>= 5.0.0, < 6)
syntax_tree (>= 6, < 7)
ruby-progressbar (1.11.0)
rubyzip (2.3.2)
selenium-webdriver (4.8.0)
Expand All @@ -122,12 +122,12 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
sorbet-runtime (0.5.10666)
sorbet-runtime (0.5.10667)
standard (1.24.3)
language_server-protocol (~> 3.17.0.2)
rubocop (= 1.44.1)
rubocop-performance (= 1.15.2)
syntax_tree (5.3.0)
syntax_tree (6.0.0)
prettier_print (>= 1.2.0)
unicode-display_width (2.4.2)
webdrivers (5.2.0)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rspec-3.10.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ GIT
PATH
remote: ..
specs:
rspec-abq (1.1.2)
rspec-abq (1.1.3)
rspec-core (>= 3.5.0, < 3.13.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rspec-3.11.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ GIT
PATH
remote: ..
specs:
rspec-abq (1.1.2)
rspec-abq (1.1.3)
rspec-core (>= 3.5.0, < 3.13.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rspec-3.12.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ GIT
PATH
remote: ..
specs:
rspec-abq (1.1.2)
rspec-abq (1.1.3)
rspec-core (>= 3.5.0, < 3.13.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rspec-3.5.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ GIT
PATH
remote: ..
specs:
rspec-abq (1.1.2)
rspec-abq (1.1.3)
rspec-core (>= 3.5.0, < 3.13.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rspec-3.6.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ GIT
PATH
remote: ..
specs:
rspec-abq (1.1.2)
rspec-abq (1.1.3)
rspec-core (>= 3.5.0, < 3.13.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rspec-3.7.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ GIT
PATH
remote: ..
specs:
rspec-abq (1.1.2)
rspec-abq (1.1.3)
rspec-core (>= 3.5.0, < 3.13.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rspec-3.8.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ GIT
PATH
remote: ..
specs:
rspec-abq (1.1.2)
rspec-abq (1.1.3)
rspec-core (>= 3.5.0, < 3.13.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rspec-3.9.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ GIT
PATH
remote: ..
specs:
rspec-abq (1.1.2)
rspec-abq (1.1.3)
rspec-core (>= 3.5.0, < 3.13.0)

GEM
Expand Down
4 changes: 2 additions & 2 deletions lib/rspec/abq/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def self.abq_result(example)
file: example.metadata[:file_path],
line: example.metadata[:line_number]
},
started_at: execution_result.started_at.utc.iso8601,
finished_at: execution_result.finished_at.utc.iso8601,
started_at: execution_result.started_at.utc.iso8601(6), # anything higher-prescision just yielded 0s
finished_at: execution_result.finished_at.utc.iso8601(6),
lineage: RSpec::Core::Metadata.ascend(example.metadata).map { |meta| meta[:description] }.reverse
}

Expand Down
3 changes: 2 additions & 1 deletion lib/rspec/abq/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def self.generate(ordered_groups, random_seed, registry)
# @!visibility private
def self.extract_metadata_and_tags(metadata)
# we use `.dup.reject! because `.reject` raises a warning (because it doesn't dup procs)`
user_metadata = metadata.dup.reject! { |k, _v| RESERVED_METADATA_KEYS.include?(k) }
user_metadata = metadata.dup
user_metadata.reject! { |k, _v| RESERVED_METADATA_KEYS.include?(k) }
tags_array, metadata_array = user_metadata.partition { |_k, v| v == true }
[tags_array.map(&:first), metadata_array.to_h]
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/abq/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module RSpec
module Abq
# current version!
VERSION = "1.1.2"
VERSION = "1.1.3"
end
end
2 changes: 1 addition & 1 deletion spec/NUM_TESTS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
46
47
33 changes: 33 additions & 0 deletions spec/rspec/abq/formatter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require "spec_helper"

RSpec.describe RSpec::Abq::Formatter do
describe ".abq_result(example)" do
it "reports times in microseconds", :aggregate_failures do # rubocop:disable RSpec/ExampleLength
started_at_string = "2023-01-01T01:01:01.123456Z"
started_at = Time.parse(started_at_string)
runtime = 1.123456
finished_at = started_at + runtime
execution_result = instance_double(
RSpec::Core::Example::ExecutionResult,
run_time: runtime,
started_at: started_at,
finished_at: finished_at,
exception: nil,
status: :passed
)

example = instance_double(
RSpec::Core::Example,
id: "./spec/foo_spec.rb:1",
execution_result: execution_result,
metadata: {}
)

result = RSpec::Abq::Formatter.abq_result(example)[:test_result]

expect(result[:runtime]).to eq 1_123_456_000
expect(result[:started_at]).to eq(started_at_string)
expect(result[:finished_at]).to eq(finished_at.utc.iso8601(6))
end
end
end

0 comments on commit 37fd93f

Please sign in to comment.