Module: KillerRspecRack::Macros

Defined in:
lib/killer_rspec_rack/macros.rb

Instance Method Summary collapse

Instance Method Details

#the_response_body_of(url, options = {:method => :get}, &assertion) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/killer_rspec_rack/macros.rb', line 3

def the_response_body_of url, options = {:method => :get}, &assertion
  decoders = Hash.new(lambda { |body| body })
  decoders.merge!({"application/json" => lambda { |body| ActiveSupport::JSON.decode(body) }})

  context "the response body of #{url}" do
    subject do
      self.send(options[:method], url)
      decoder = decoders[last_response.headers["Content-Type"]]
      decoder.call(last_response.body)
    end

    self.instance_eval &assertion
  end
end

#the_response_of(url, options = {:method => :get}, &assertion) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/killer_rspec_rack/macros.rb', line 18

def the_response_of url, options = {:method => :get}, &assertion
  context "the response of #{url}" do
    subject do
      self.send(options[:method], url)
      last_response
    end

    self.instance_eval &assertion
  end
end