Sha256: 03d78d967d1952050c984095535599359797ddca6d0c60ff93b18cb8db0702c5

Contents?: true

Size: 1.09 KB

Versions: 8

Compression:

Stored size: 1.09 KB

Contents

require 'interpol'

module Interpol
  module TestHelper
    module Common
      def each_example_from(endpoints)
        endpoints.each do |endpoint|
          endpoint.definitions.each do |definition|
            definition.examples.each_with_index do |example, index|
              yield endpoint, definition, example, index
            end
          end
        end
      end

      def define_interpol_example_tests(&block)
        config = Configuration.default.customized_duplicate(&block)

        each_example_from(config.endpoints) do |endpoint, definition, example, example_index|
          description = "#{endpoint.name} (v #{definition.version}) has " +
                        "valid data for example #{example_index + 1}"
          define_test(description) { example.validate! }
        end
      end
    end

    module RSpec
      include Common

      def define_test(name, &block)
        it(name, &block)
      end
    end

    module TestUnit
      include Common

      def define_test(name, &block)
        define_method("test_#{name.gsub(/\W+/, '_')}", &block)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
interpol-0.0.8 lib/interpol/test_helper.rb
interpol-0.0.7 lib/interpol/test_helper.rb
interpol-0.0.6 lib/interpol/test_helper.rb
interpol-0.0.5 lib/interpol/test_helper.rb
interpol-0.0.4 lib/interpol/test_helper.rb
interpol-0.0.3 lib/interpol/test_helper.rb
interpol-0.0.2 lib/interpol/test_helper.rb
interpol-0.0.1 lib/interpol/test_helper.rb