Module: RSpec::Grape::Methods

Includes:
Rack::Test::Methods
Defined in:
lib/rspec/grape/methods.rb

Instance Method Summary collapse

Instance Method Details

#api_methodObject



10
11
12
# File 'lib/rspec/grape/methods.rb', line 10

def api_method
  @api_method ||= api_endpoint_description.split(' ').first.downcase.to_sym
end

#api_urlObject



14
15
16
# File 'lib/rspec/grape/methods.rb', line 14

def api_url
  @api_url ||= api_endpoint_description.split(' ').last
end

#appObject



6
7
8
# File 'lib/rspec/grape/methods.rb', line 6

def app
  self.described_class
end

#call_api(params = nil) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# 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) ⇒ Object



50
51
52
# 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) ⇒ Object



46
47
48
# 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) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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