Module: RSpec::Grape::Utils
- Defined in:
- lib/rspec/grape/utils.rb
Constant Summary collapse
- HTTP_METHODS =
%w[GET HEAD PUT POST DELETE OPTIONS PATCH LINK UNLINK]
- DESCRIPTION_REGEXP =
/(#{HTTP_METHODS.join('|')}) \/.*/- PARAMS_REGEXP =
/(\/:([^\/]*))/
Class Method Summary collapse
- .find_endpoint_description(klass) ⇒ Object
- .is_description_valid?(description) ⇒ Boolean
- .url_param_names(url) ⇒ Object
Class Method Details
.find_endpoint_description(klass) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rspec/grape/utils.rb', line 12 def self.find_endpoint_description(klass) ancestors = klass.ancestors.select { |a| a < RSpec::Core::ExampleGroup } ancestors = ancestors.select do |a| is_description_valid?(a.description) end raise RSpec::Grape::NoEndpointDescription unless ancestors.any? ancestors.first.description end |
.is_description_valid?(description) ⇒ Boolean
8 9 10 |
# File 'lib/rspec/grape/utils.rb', line 8 def self.is_description_valid?(description) !!(description =~ DESCRIPTION_REGEXP) end |
.url_param_names(url) ⇒ Object
23 24 25 |
# File 'lib/rspec/grape/utils.rb', line 23 def self.url_param_names(url) url.scan(PARAMS_REGEXP).map { |a| a[1].to_sym } end |