lib/polytrix/validator.rb in polytrix-0.1.2 vs lib/polytrix/validator.rb in polytrix-0.1.3
- old
+ new
@@ -3,24 +3,29 @@
module Polytrix
class Validator
include RSpec::Matchers
UNIVERSAL_MATCHER = //
- attr_reader :description, :suite, :sample, :level, :callback
+ attr_reader :description, :suite, :scenario, :level, :callback
def initialize(description, scope = {}, &validator)
@description = description
@suite = scope[:suite] ||= UNIVERSAL_MATCHER
- @sample = scope[:sample] ||= UNIVERSAL_MATCHER
+ @scenario = scope[:scenario] ||= UNIVERSAL_MATCHER
@callback = validator
end
def should_validate?(challenge)
- !!(@suite.match(challenge.suite.to_s) && @sample.match(challenge.name.to_s))
+ # TODO: Case-insensitive matching?
+ !!(@suite.match(challenge.suite.to_s) && @scenario.match(challenge.name.to_s)) # rubocop:disable Style/DoubleNegation
end
def validate(challenge)
- instance_exec challenge, &@callback if should_validate?(challenge)
+ instance_exec(challenge, &@callback) if should_validate?(challenge)
+ challenge.result.validations[description] = Validation.new(result: :passed)
+ rescue StandardError, RSpec::Expectations::ExpectationNotMetError => e
+ validation = Validation.new(result: :failed, error: ValidationFailure.new(e.message, e))
+ challenge.result.validations[description] = validation
end
def to_s
@description
end