-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Matcher] Add duration validator matcher
- Loading branch information
Showing
15 changed files
with
352 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
lib/active_storage_validations/matchers/duration_validator_matcher.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'base_comparison_validator_matcher' | ||
|
||
module ActiveStorageValidations | ||
module Matchers | ||
def validate_duration_of(attribute_name) | ||
DurationValidatorMatcher.new(attribute_name) | ||
end | ||
|
||
class DurationValidatorMatcher < BaseComparisonValidatorMatcher | ||
def description | ||
"validate file duration of :#{@attribute_name}" | ||
end | ||
|
||
def failure_message | ||
message = ["is expected to validate file duration of :#{@attribute_name}"] | ||
build_failure_message(message) | ||
message.join("\n") | ||
end | ||
|
||
private | ||
|
||
def failure_message_unit | ||
"seconds" | ||
end | ||
|
||
def smallest_measurement | ||
1.second | ||
end | ||
|
||
def mock_value_for(io, duration) | ||
Matchers.mock_metadata(io, { duration: duration }) do | ||
yield | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.