lib/rspec-api/dsl/request.rb in rspec-api-0.2.0 vs lib/rspec-api/dsl/request.rb in rspec-api-0.4.0
- old
+ new
@@ -1,72 +1,5 @@
-require 'rack/utils'
+require 'rspec-api/dsl/request/request'
+require 'rspec-api/dsl/request/response'
require 'rspec-api/dsl/request/status'
require 'rspec-api/dsl/request/headers'
-require 'rspec-api/dsl/request/body'
-
-module DSL
- module Request
- extend ActiveSupport::Concern
-
- def response
- # To be overriden by more specific modules
- OpenStruct.new # body: nil, status: nil, headers: {}
- end
-
- def response_body
- JSON response_body_without_callbacks
- rescue JSON::ParserError, JSON::GeneratorError
- nil
- end
-
- def response_headers
- response.headers || {}
- end
-
- def response_status
- response.status
- end
-
- def request_params
- {} # To be overriden by more specific modules
- end
-
- module ClassMethods
- def respond_with(status_symbol, &block)
- status_code = to_code status_symbol
-
- context 'responds with a status code that' do
- should_match_status_expectations(status_code)
- end
- context 'responds with headers that' do
- should_match_headers_expectations(status_code)
- end
- context 'responds with a body that' do
- should_match_body_expectations(status_code, &block)
- end
- end
-
- private
-
- def to_code(status_symbol)
- Rack::Utils.status_code status_symbol
- end
-
- def has_entity_body?(status_code)
- !Rack::Utils::STATUS_WITH_NO_ENTITY_BODY.include? status_code
- end
-
- def success?(status_code)
- has_entity_body?(status_code) && status_code < 400
- end
- end
-
- private
-
- def response_body_without_callbacks
- body = response.body
- # TODO: extract the 'a_callback' constant
- callback_pattern = %r[a_callback\((.*?)\)]
- body =~ callback_pattern ? body.match(callback_pattern)[1] : body
- end
- end
-end
+require 'rspec-api/dsl/request/body'
\ No newline at end of file