module RSpec::Resources::DSL
Public Instance Methods
describe_resource(base_path, options = {}, &block)
click to toggle source
Custom describe block that sets metadata to enable easy resource testing. In contrast to `#describe_resources` this method is meant for resources where only one instance exists. This directly correlates with the `resource` directive of the rails routes file.
describe_resources '/v1/profile', meta: :data do # ... end
Params:
base_path
-
The resource base path, typically the one of the get action
options
-
RSpec's `describe` metadata arguments
block
-
Block to pass into describe
# File lib/rspec/resources/dsl.rb, line 39 def describe_resource(base_path, options = {}, &block) abstract_describe(base_path, { single_resource: true }.merge(options), &block) end
describe_resources(base_path, options = {}, &block)
click to toggle source
Custom describe block that sets metadata to enable easy resource testing. This directly correlates with the `resources` directive of the rails routes file.
describe_resources '/v1/articles', meta: :data do # ... end
Params:
base_path
-
The resources base path, typically the one of the index action
options
-
RSpec's `describe` metadata arguments
block
-
Block to pass into describe
# File lib/rspec/resources/dsl.rb, line 22 def describe_resources(base_path, options = {}, &block) abstract_describe(base_path, { single_resource: false }.merge(options), &block) end
Private Instance Methods
abstract_describe(base_path, options = {}, &block)
click to toggle source
# File lib/rspec/resources/dsl.rb, line 45 def abstract_describe(base_path, options = {}, &block) name = base_path.split('/').last dopts = { type: :request, base_path: base_path, resource_name: name.singularize, rspec_resources_dsl: :resource, document_format: RSpec::Resources.configuration.document_format, }.merge(options) RSpec.describe(name.capitalize, dopts) do let(:request_headers) do |current_example| (current_example.metadata[:request_headers] || []).map { |s| send s }.inject { |x, y| x.merge y } end instance_eval(&block) end end