module Fdoc::SpecWatcher

Constants

VERBS

Private Instance Methods

check_response(verb, request_params) click to toggle source
# File lib/fdoc/spec_watcher.rb, line 19
def check_response(verb, request_params)
  successful = Fdoc.decide_success(response_params, real_response.status)
  Service.verify!(verb, path, parsed_request_params(request_params), response_params,
                  real_response.status, successful)
end
parsed_request_params(request_params) click to toggle source
# File lib/fdoc/spec_watcher.rb, line 25
def parsed_request_params request_params
  if request_params.kind_of?(Hash)
    request_params
  else
    begin
      JSON.parse(request_params)
    rescue
      {}
    end
  end
end
path() click to toggle source
# File lib/fdoc/spec_watcher.rb, line 37
def path
  if RSpec.respond_to?(:current_example) # Rspec 3
    RSpec.current_example.metadata[:fdoc]
  elsif respond_to?(:example) # Rspec 2
    example.metadata[:fdoc]
  else # Rspec 1.3.2
    opts = {}
    __send__(:example_group_hierarchy).each do |example|
      opts.merge!(example.options)
    end
    opts.merge!(options)
    opts[:fdoc]
  end
end
real_response() click to toggle source
# File lib/fdoc/spec_watcher.rb, line 52
def real_response
  if respond_to? :response
    # we are on rails
    response
  else
    # we are on sinatra
    last_response
  end
end
response_params() click to toggle source
# File lib/fdoc/spec_watcher.rb, line 62
def response_params
  begin
    JSON.parse(real_response.body)
  rescue
    {}
  end
end