Sha256: b85e8d2e47ff61d0c347a8c7d624e9bf078396b7b9dd0274f68f1886a60a57e8

Contents?: true

Size: 815 Bytes

Versions: 4

Compression:

Stored size: 815 Bytes

Contents

require 'ostruct'

module ResourceKit
  module Testing
    class ActionHandlerMatchers
      ResponseStub = Class.new(OpenStruct)

      attr_reader :action, :response_stub

      def initialize(action)
        @action = action
      end

      def with(options, &block)
        @response_stub = ResponseStub.new(options)
        @handled_block = block

        self
      end

      def matches?(subject, &block)
        @handled_block ||= block
        action = subject.resources.find_action(self.action)
        return false unless action

        status_code = response_stub.status || 200
        return false unless action.handlers[status_code]

        handled_response = action.handlers[status_code].call(response_stub)
        @handled_block.call(handled_response)

        true
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
resource_kit-0.1.4 lib/resource_kit/testing/action_handler_matchers.rb
resource_kit-0.1.3 lib/resource_kit/testing/action_handler_matchers.rb
resource_kit-0.1.2 lib/resource_kit/testing/action_handler_matchers.rb
resource_kit-0.1.1 lib/resource_kit/testing/action_handler_matchers.rb