Class: Omnitest::Skeptic::Validator
- Inherits:
-
Object
- Object
- Omnitest::Skeptic::Validator
- Includes:
- RSpec::Matchers
- Defined in:
- lib/omnitest/skeptic/validator.rb
Constant Summary collapse
- UNIVERSAL_MATCHER =
//
Instance Attribute Summary collapse
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#scenario ⇒ Object
readonly
Returns the value of attribute scenario.
-
#suite ⇒ Object
readonly
Returns the value of attribute suite.
Instance Method Summary collapse
-
#initialize(description, scope = {}, &validator) ⇒ Validator
constructor
A new instance of Validator.
- #should_validate?(scenario) ⇒ Boolean
- #to_s ⇒ Object
- #validate(scenario) ⇒ Object
Constructor Details
#initialize(description, scope = {}, &validator) ⇒ Validator
9 10 11 12 13 14 |
# File 'lib/omnitest/skeptic/validator.rb', line 9 def initialize(description, scope = {}, &validator) @description = description @suite = scope[:suite] ||= UNIVERSAL_MATCHER @scenario = scope[:scenario] ||= UNIVERSAL_MATCHER @callback = validator end |
Instance Attribute Details
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
7 8 9 |
# File 'lib/omnitest/skeptic/validator.rb', line 7 def callback @callback end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
7 8 9 |
# File 'lib/omnitest/skeptic/validator.rb', line 7 def description @description end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
7 8 9 |
# File 'lib/omnitest/skeptic/validator.rb', line 7 def level @level end |
#scenario ⇒ Object (readonly)
Returns the value of attribute scenario.
7 8 9 |
# File 'lib/omnitest/skeptic/validator.rb', line 7 def scenario @scenario end |
#suite ⇒ Object (readonly)
Returns the value of attribute suite.
7 8 9 |
# File 'lib/omnitest/skeptic/validator.rb', line 7 def suite @suite end |
Instance Method Details
#should_validate?(scenario) ⇒ Boolean
16 17 18 19 |
# File 'lib/omnitest/skeptic/validator.rb', line 16 def should_validate?(scenario) # TODO: Case-insensitive matching? !!(@suite.match(scenario.suite.to_s) && @scenario.match(scenario.name.to_s)) # rubocop:disable Style/DoubleNegation end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/omnitest/skeptic/validator.rb', line 29 def to_s @description end |
#validate(scenario) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/omnitest/skeptic/validator.rb', line 21 def validate(scenario) instance_exec(scenario, &@callback) if should_validate?(scenario) scenario.result.validations[description] = Validation.new(status: :passed) rescue StandardError, RSpec::Expectations::ExpectationNotMetError => e validation = Validation.new(status: :failed, error: ValidationFailure.new(e., e)) scenario.result.validations[description] = validation end |