Sha256: 89f81cc3572eaf07268e6c4b7bc174a9d9271fd2b5e447795725e660854062aa

Contents?: true

Size: 1.04 KB

Versions: 15

Compression:

Stored size: 1.04 KB

Contents

module Restspec
  module Requirements
    class Requirement
      attr_reader :name, :errors

      def initialize(name)
        self.name = name
        self.errors = []
        extend Restspec::RSpec::ApiHelpers
      end

      def execution(&execution_block)
        define_singleton_method(:execute, &execution_block)
      end

      def execute
      end

      def assert!
        execute
        if errors.any?
          raise errors.join(' | ')
        end
      end

      def add_error(error)
        errors << error
      end

      private

      attr_writer :name, :errors

      class << self
        attr_reader :requirements

        def get_or_create(name)
          find_by_name(name) || create(name)
        end

        def find_by_name(name)
          requirements.find { |r| r.name == name }
        end

        def create(name)
          self.new(name).tap { |r| requirements << r }
        end

        def requirements
          @requirements ||= []
        end

        private

        attr_writer :requirements
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
restspec-0.3.2 lib/restspec/requirements/requirement.rb
restspec-0.3.1 lib/restspec/requirements/requirement.rb
restspec-0.3.0 lib/restspec/requirements/requirement.rb
restspec-0.2.6 lib/restspec/requirements/requirement.rb
restspec-0.2.5 lib/restspec/requirements/requirement.rb
restspec-0.2.4 lib/restspec/requirements/requirement.rb
restspec-0.2.3 lib/restspec/requirements/requirement.rb
restspec-0.2.2 lib/restspec/requirements/requirement.rb
restspec-0.2.1 lib/restspec/requirements/requirement.rb
restspec-0.2 lib/restspec/requirements/requirement.rb
restspec-0.1 lib/restspec/requirements/requirement.rb
restspec-0.0.4 lib/restspec/requirements/requirement.rb
restspec-0.0.3 lib/restspec/requirements/requirement.rb
restspec-0.0.2 lib/restspec/requirements/requirement.rb
restspec-0.0.1 lib/restspec/requirements/requirement.rb