Module: RSpec::Grape::Methods
- Includes:
- Rack::Test::Methods
- Defined in:
- lib/rspec/grape/methods.rb
Instance Method Summary collapse
- #api_method ⇒ Object
- #api_url ⇒ Object
- #app ⇒ Object
- #call_api(params = nil) ⇒ Object
- #expect_endpoint_not_to(matcher) ⇒ Object
- #expect_endpoint_to(matcher) ⇒ Object
- #parameterized_api_url(params = nil) ⇒ Object
Instance Method Details
#api_method ⇒ Object
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_url ⇒ Object
14 15 16 |
# File 'lib/rspec/grape/methods.rb', line 14 def api_url @api_url ||= api_endpoint_description.split(' ').last end |
#app ⇒ Object
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 |