module RSpec::Grape::Methods

Public Instance Methods

api_method() click to toggle source
# File lib/rspec/grape/methods.rb, line 10
def api_method
  @api_method ||= api_endpoint_description.split(' ').first.downcase.to_sym
end
api_url() click to toggle source
# File lib/rspec/grape/methods.rb, line 14
def api_url
  @api_url ||= api_endpoint_description.split(' ').last
end
app() click to toggle source
# File lib/rspec/grape/methods.rb, line 6
def app
  self.described_class
end
call_api(params = nil) click to toggle source
# File lib/rspec/grape/methods.rb, line 34
def call_api(params = nil)
  params ||= {}

  if parameterized_url?
    url = parameterized_api_url(params)
  else
    url = api_url
  end

  self.send(api_method, url, params)
end
expect_endpoint_not_to(matcher) click to toggle source
# File lib/rspec/grape/methods.rb, line 50
def expect_endpoint_not_to(matcher)
  ::Grape::Endpoint.before_each { |endpoint| expect(endpoint).not_to matcher }
end
expect_endpoint_to(matcher) click to toggle source
# File lib/rspec/grape/methods.rb, line 46
def expect_endpoint_to(matcher)
  ::Grape::Endpoint.before_each { |endpoint| expect(endpoint).to matcher }
end
parameterized_api_url(params = nil) click to toggle source
# File lib/rspec/grape/methods.rb, line 18
def parameterized_api_url(params = nil)
  raise RSpec::Grape::UrlIsNotParameterized unless parameterized_url?

  params ||= {}

  url = api_url.dup
  names = RSpec::Grape::Utils.url_param_names(api_url)
  names.each do |name|
    raise RSpec::Grape::UrlParameterNotSet unless params.has_key?(name.to_sym)

    url[":#{name}"] = params[name].to_s
  end

  url
end

Private Instance Methods

api_endpoint_description() click to toggle source
# File lib/rspec/grape/methods.rb, line 57
def api_endpoint_description
  @api_endpoint_description ||= RSpec::Grape::Utils.find_endpoint_description(self.class)
end
parameterized_url?() click to toggle source
# File lib/rspec/grape/methods.rb, line 61
def parameterized_url?
  api_url =~ /\/:/
end