Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make DSL work with config.disable_monkeypatching! #166

Merged
merged 2 commits into from
Oct 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions features/example_request.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ Feature: Example Request
end
end
"""
And a file named "app_spec.rb" with:
"""

Scenario: Output should have the correct error line
Given a file named "app_spec.rb" with:
"""
require "rspec_api_documentation"
require "rspec_api_documentation/dsl"

Expand All @@ -26,11 +28,32 @@ Feature: Example Request
end
"""
When I run `rspec app_spec.rb --require ./app.rb --format RspecApiDocumentation::ApiFormatter`

Scenario: Output should have the correct error line
Then the output should contain "expected: 201"
Then the output should not contain "endpoint.rb"
Then the output should contain:
"""
rspec ./app_spec.rb:10 # Example Request GET / Greeting your favorite gem
"""

Scenario: should work with RSpec monkey patching disabled
When a file named "app_spec.rb" with:
"""
require "rspec_api_documentation/dsl"

RSpec.configure do |config|
config.disable_monkey_patching!
end

RspecApiDocumentation.configure do |config|
config.app = App
end

RSpec.resource "Example Request" do
get "/" do
example_request "Greeting your favorite gem" do
expect(status).to eq(200)
end
end
end
"""
Then I successfully run `rspec app_spec.rb --require ./app.rb`
44 changes: 27 additions & 17 deletions lib/rspec_api_documentation/dsl.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
require "rspec_api_documentation"
require "rspec_api_documentation/dsl/resource"
require "rspec_api_documentation/dsl/endpoint"
require "rspec_api_documentation/dsl/callback"

# Custom describe block that sets metadata to enable the rest of RAD
#
# resource "Orders", :meta => :data do
# # ...
# end
#
# Params:
# +args+:: Glob of RSpec's `describe` arguments
# +block+:: Block to pass into describe
#
def self.resource(*args, &block)
options = if args.last.is_a?(Hash) then args.pop else {} end
options[:api_doc_dsl] = :resource
options[:resource_name] = args.first
options[:document] ||= :all
args.push(options)
describe(*args, &block)

module RspecApiDocumentation
module DSL

# Custom describe block that sets metadata to enable the rest of RAD
#
# resource "Orders", :meta => :data do
# # ...
# end
#
# Params:
# +args+:: Glob of RSpec's `describe` arguments
# +block+:: Block to pass into describe
#
def resource(*args, &block)
options = if args.last.is_a?(Hash) then args.pop else {} end
options[:api_doc_dsl] = :resource
options[:resource_name] = args.first
options[:document] ||= :all
args.push(options)
describe(*args, &block)
end
end
end

RSpec::Core::ExampleGroup.extend(RspecApiDocumentation::DSL)
RSpec::Core::DSL.expose_example_group_alias(:resource)

RSpec.configuration.include RspecApiDocumentation::DSL::Resource, :api_doc_dsl => :resource
RSpec.configuration.include RspecApiDocumentation::DSL::Endpoint, :api_doc_dsl => :endpoint
RSpec.configuration.include RspecApiDocumentation::DSL::Callback, :api_doc_dsl => :callback
Expand Down