Sha256: 1312af09b72d2ed584c4783cd423bb83d36085c30f386c38f344113945cff28e

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 KB

Contents

module UnitTests
  module ValidationMatcherScenarioHelpers
    def self.configure_example_group(example_group)
      example_group.include(self)
    end

    def build_scenario_for_validation_matcher(args)
      UnitTests::ValidationMatcherScenario.new(
        build_validation_matcher_scenario_args(args)
      )
    end

    protected

    def validation_matcher_scenario_args
      {}
    end

    def configure_validation_matcher(matcher)
      matcher
    end

    private

    def build_validation_matcher_scenario_args(args)
      args.
        deep_merge(validation_matcher_scenario_args).
        deep_merge(
          matcher_name: matcher_name,
          matcher_proc: method(matcher_name)
        )
    end

    def matcher_name
      validation_matcher_scenario_args.fetch(:matcher_name) do
        raise KeyNotFoundError.new(<<-MESSAGE)
Please implement #validation_matcher_scenario_args in your example
group, in such a way that it returns a hash that contains a
:matcher_name key.
        MESSAGE
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
shoulda-matchers-3.1.3 spec/support/unit/helpers/validation_matcher_scenario_helpers.rb
shoulda-matchers-4.0.0.rc1 spec/support/unit/helpers/validation_matcher_scenario_helpers.rb
shoulda-matchers-3.1.2 spec/support/unit/helpers/validation_matcher_scenario_helpers.rb
shoulda-matchers-3.1.1 spec/support/unit/helpers/validation_matcher_scenario_helpers.rb
shoulda-matchers-3.1.0 spec/support/unit/helpers/validation_matcher_scenario_helpers.rb