Module: Spryte::RSpec::Macros
- Defined in:
- lib/spryte/rspec/macros.rb
Defined Under Namespace
Classes: InvalidHTTPVerb
Constant Summary collapse
- VALID_HTTP_VERBS =
[ :get, :head, :post, :patch, :put, :proppatch, :lock, :unlock, :options, :propfind, :delete, :move, :copy, :mkcol, :trace, ]
Instance Method Summary collapse
- #accept(mime_type) ⇒ Object
- #content_type(mime_type) ⇒ Object
- #host(domain) ⇒ Object
- #method(verb) ⇒ Object
- #path(name) ⇒ Object
- #request(name) ⇒ Object
- #through(verb) ⇒ Object
Instance Method Details
#accept(mime_type) ⇒ Object
44 45 46 47 48 |
# 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) ⇒ Object
50 51 52 53 54 |
# 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) ⇒ Object
7 8 9 |
# File 'lib/spryte/rspec/macros.rb', line 7 def host(domain) before(:each) { self.host = domain } end |
#method(verb) ⇒ Object
35 36 37 38 |
# 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) ⇒ Object
40 41 42 |
# File 'lib/spryte/rspec/macros.rb', line 40 def path(name) let(:path) { Pathname(name) } end |
#request(name) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# 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) ⇒ Object
29 30 31 32 33 |
# File 'lib/spryte/rspec/macros.rb', line 29 def through(verb) raise InvalidHTTPVerb, (verb) unless valid_http_verb?(verb) let(:through) { verb.to_sym } let(:method) { through } end |