Sha256: 482cf9a210576e0a0242824614ac259c01e0e43a1f39587e1df4258222177e1b
Contents?: true
Size: 1.43 KB
Versions: 2
Compression:
Stored size: 1.43 KB
Contents
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 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.exclude? status_code end def success?(status_code) has_entity_body?(status_code) && status_code < 400 end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rspec-api-0.1.1 | lib/rspec-api/dsl/request.rb |
rspec-api-0.1.0 | lib/rspec-api/dsl/request.rb |