Module: RSpec::Rails::Api::DSL::ExampleGroup
- Defined in:
- lib/rspec/rails/api/dsl/example_group.rb
Overview
All these methods will be available in example groups (anything but ‘it’, ‘example’, ‘for_code’)
Instance Method Summary collapse
-
#entity(type, fields) ⇒ void
Describes an entity.
-
#for_code(status_code, description = nil, expect_many: nil, expect_one: false, test_only: false, with_content_type: nil, &block) ⇒ void
Adds an HTTP code declaration to metadata, with expected result If no expectation is provided, the response will be expected to be empty.
-
#on_delete(url, summary = nil, description = nil) ⇒ void
Defines a DELETE action.
-
#on_get(url, summary = nil, description = nil) ⇒ void
Defines a GET action.
-
#on_patch(url, summary = nil, description = nil) ⇒ void
Defines a PATCH action.
-
#on_post(url, summary = nil, description = nil) ⇒ void
Defines a POST action.
-
#on_put(url, summary = nil, description = nil) ⇒ void
Defines a PUT action.
-
#parameters(type, fields) ⇒ void
Describes request or path parameters.
-
#path_params(fields: nil, defined: nil) ⇒ void
Declares parameters used in URLS (path) Use
fieldsordefinedbut not both. -
#request_params(attributes: nil, defined: nil) ⇒ void
Declares parameters for a request body Use
attributesordefinedbut not both. -
#requires_security(*scheme_references) ⇒ Object
Declares security schemes valid for this path.
-
#resource(name, description = '') ⇒ Object
First method to be called in a spec file # as it will initialize the metadata.
Instance Method Details
#entity(type, fields) ⇒ void
This method returns an undefined value.
Describes an entity
30 31 32 |
# File 'lib/rspec/rails/api/dsl/example_group.rb', line 30 def entity(type, fields) RSpec::Rails::Api::Metadata.add_entity type, fields end |
#for_code(status_code, description = nil, expect_many: nil, expect_one: false, test_only: false, with_content_type: nil, &block) ⇒ void
This method returns an undefined value.
Adds an HTTP code declaration to metadata, with expected result If no expectation is provided, the response will be expected to be empty
164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/rspec/rails/api/dsl/example_group.rb', line 164 def for_code(status_code, description = nil, expect_many: nil, expect_one: false, test_only: false, with_content_type: nil, &block) # rubocop:disable Layout/LineLength, Metrics/ParameterLists description ||= Rack::Utils::HTTP_STATUS_CODES[status_code] [:rra].add_status_code(status_code, description) unless test_only [:rra].add_expectations(expect_one, expect_many, content_type: with_content_type) [:rra_current_example] = [:rra].current_example describe "->#{test_only ? ' test' : ''} #{status_code} - #{description}" do execute_for_code_block(block) end end |
#on_delete(url, summary = nil, description = nil) ⇒ void
This method returns an undefined value.
Defines a DELETE action
147 148 149 |
# File 'lib/rspec/rails/api/dsl/example_group.rb', line 147 def on_delete(url, summary = nil, description = nil, &) on_action(:delete, url, summary, description, &) end |
#on_get(url, summary = nil, description = nil) ⇒ void
This method returns an undefined value.
Defines a GET action
99 100 101 |
# File 'lib/rspec/rails/api/dsl/example_group.rb', line 99 def on_get(url, summary = nil, description = nil, &) on_action(:get, url, summary, description, &) end |
#on_patch(url, summary = nil, description = nil) ⇒ void
This method returns an undefined value.
Defines a PATCH action
135 136 137 |
# File 'lib/rspec/rails/api/dsl/example_group.rb', line 135 def on_patch(url, summary = nil, description = nil, &) on_action(:patch, url, summary, description, &) end |
#on_post(url, summary = nil, description = nil) ⇒ void
This method returns an undefined value.
Defines a POST action
111 112 113 |
# File 'lib/rspec/rails/api/dsl/example_group.rb', line 111 def on_post(url, summary = nil, description = nil, &) on_action(:post, url, summary, description, &) end |
#on_put(url, summary = nil, description = nil) ⇒ void
This method returns an undefined value.
Defines a PUT action
123 124 125 |
# File 'lib/rspec/rails/api/dsl/example_group.rb', line 123 def on_put(url, summary = nil, description = nil, &) on_action(:put, url, summary, description, &) end |
#parameters(type, fields) ⇒ void
This method returns an undefined value.
Describes request or path parameters
41 42 43 |
# File 'lib/rspec/rails/api/dsl/example_group.rb', line 41 def parameters(type, fields) [:rra].add_parameter type, fields end |
#path_params(fields: nil, defined: nil) ⇒ void
This method returns an undefined value.
Declares parameters used in URLS (path) Use fields or defined but not both.
53 54 55 56 57 58 59 60 61 |
# File 'lib/rspec/rails/api/dsl/example_group.rb', line 53 def path_params(fields: nil, defined: nil) if defined && ![:rra].parameters[defined] raise "Parameter #{defined} was not defined with the 'parameters' method" end fields ||= [:rra].parameters[defined] [:rra].add_path_params fields end |
#request_params(attributes: nil, defined: nil) ⇒ void
This method returns an undefined value.
Declares parameters for a request body Use attributes or defined but not both.
71 72 73 74 75 76 77 78 79 |
# File 'lib/rspec/rails/api/dsl/example_group.rb', line 71 def request_params(attributes: nil, defined: nil) if defined && ![:rra].parameters[defined] raise "Parameter #{defined} was not defined with the 'parameters' method" end attributes ||= [:rra].parameters[defined] [:rra].add_request_params attributes end |
#requires_security(*scheme_references) ⇒ Object
Declares security schemes valid for this path. It won’t be enforced during testing but will complete the documentation. When the reference does not exist, an exception will be thrown during render, not before.
87 88 89 |
# File 'lib/rspec/rails/api/dsl/example_group.rb', line 87 def requires_security(*scheme_references) [:rra].add_security_references(*scheme_references) end |