Class: Omnitest::Skeptic::Validator

Inherits:
Object
  • Object
show all
Includes:
RSpec::Matchers
Defined in:
lib/omnitest/skeptic/validator.rb

Constant Summary collapse

UNIVERSAL_MATCHER =
//

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#callbackObject (readonly)

Returns the value of attribute callback.



7
8
9
# File 'lib/omnitest/skeptic/validator.rb', line 7

def callback
  @callback
end

#descriptionObject (readonly)

Returns the value of attribute description.



7
8
9
# File 'lib/omnitest/skeptic/validator.rb', line 7

def description
  @description
end

#levelObject (readonly)

Returns the value of attribute level.



7
8
9
# File 'lib/omnitest/skeptic/validator.rb', line 7

def level
  @level
end

#scenarioObject (readonly)

Returns the value of attribute scenario.



7
8
9
# File 'lib/omnitest/skeptic/validator.rb', line 7

def scenario
  @scenario
end

#suiteObject (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_sObject



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.message, e))
  scenario.result.validations[description] = validation
end