module Spryte::RSpec::Macros

Constants

VALID_HTTP_VERBS

Public Instance Methods

accept(mime_type) click to toggle source
# File lib/spryte/rspec/macros.rb, line 44
def accept(mime_type)
  if mime_type = Mime::Type.lookup_by_extension(mime_type)
    before(:each) { headers.merge!("HTTP_ACCEPT" => mime_type.to_s) }
  end
end
content_type(mime_type) click to toggle source
# File lib/spryte/rspec/macros.rb, line 50
def content_type(mime_type)
  if mime_type = Mime::Type.lookup_by_extension(mime_type)
    before(:each) { headers.merge!("CONTENT_TYPE" => mime_type.to_s) }
  end
end
host(domain) click to toggle source
# File lib/spryte/rspec/macros.rb, line 7
def host(domain)
  before(:each) { self.host = domain }
end
method(verb) click to toggle source
# File lib/spryte/rspec/macros.rb, line 35
def method(verb)
  warn "#{ Kernel.caller.first }: `#method' is deprecated due to a collision with Object#method in ruby core, please use `#through' instead."
  through(verb)
end
path(name) click to toggle source
# File lib/spryte/rspec/macros.rb, line 40
def path(name)
  let(:path) { Pathname(name) }
end
request(name) click to toggle source
# File lib/spryte/rspec/macros.rb, line 11
def request(name)

  host ENV.fetch("SPRYTE_RSPEC_HOST", "localhost")

  let(:method) { :get }
  let(:path) { "/" }
  let(:params) { Hash[] }
  let(:headers) { {
    "HTTP_ACCEPT"  => "application/json",
    "CONTENT_TYPE" => "application/json"
  } }

  subject(name) {
    parameters = [ :get ].include?(method) ? params : params.to_json
    send method, path.to_s, parameters, headers
  }
end
through(verb) click to toggle source
# File lib/spryte/rspec/macros.rb, line 29
def through(verb)
  raise InvalidHTTPVerb, invalid_http_verb_message(verb) unless valid_http_verb?(verb)
  let(:through) { verb.to_sym }
  let(:method) { through }
end

Private Instance Methods

invalid_http_verb_message(verb) click to toggle source
# File lib/spryte/rspec/macros.rb, line 60
        def invalid_http_verb_message(verb)
  "#{verb} is not a valid http verb.\nValid verbs are:\n#{VALID_HTTP_VERBS.map(&:inspect).join("\n")}"
end
valid_http_verb?(verb) click to toggle source
# File lib/spryte/rspec/macros.rb, line 56
        def valid_http_verb?(verb)
  VALID_HTTP_VERBS.include?(verb)
end