Skip to content

Commit

Permalink
Add configuration option to disable DSL methods status, and method
Browse files Browse the repository at this point in the history
  • Loading branch information
oestrich committed Dec 16, 2014
1 parent 0659ef6 commit 7d2eced
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
50 changes: 50 additions & 0 deletions features/disable_dsl.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Feature: Disable DSL features
Background:
Given a file named "app.rb" with:
"""
class App
def self.call(env)
request = Rack::Request.new(env)
response = Rack::Response.new
response["Content-Type"] = "text/plain"
response.write(request.params["status"])
response.write(request.params["method"])
response.finish
end
end
"""
And a file named "app_spec.rb" with:
"""
require "rspec_api_documentation"
require "rspec_api_documentation/dsl"
RspecApiDocumentation.configure do |config|
config.app = App
config.disable_dsl_status!
config.disable_dsl_method!
end
resource "Orders" do
get "/orders" do
parameter :status, "Order status to search for"
parameter :method, "Method of delivery to search for"
example "Viewing all orders" do
do_request :status => "pending"
expect(response_status).to eq(200)
expect(response_body).to eq("pending")
end
example "Checking the method" do
do_request :method => "ground"
expect(http_method).to eq(:get)
expect(response_body).to eq("ground")
end
end
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 "2 examples, 0 failures"
And the exit status should be 0
12 changes: 12 additions & 0 deletions lib/rspec_api_documentation/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ def client_method
@client_method ||= :client
end

def disable_dsl_status!
RspecApiDocumentation::DSL::Endpoint.module_eval <<-RUBY
undef status
RUBY
end

def disable_dsl_method!
RspecApiDocumentation::DSL::Endpoint.module_eval <<-RUBY
undef method
RUBY
end

def settings
@settings ||= {}
end
Expand Down
10 changes: 7 additions & 3 deletions lib/rspec_api_documentation/dsl/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def do_request(extra_params = {})
params_or_body = nil
path_or_query = path

if method == :get && !query_string.blank?
if http_method == :get && !query_string.blank?
path_or_query += "?#{query_string}"
else
if respond_to?(:raw_post)
Expand All @@ -55,7 +55,7 @@ def do_request(extra_params = {})
end
end

rspec_api_documentation_client.send(method, path_or_query, params_or_body, headers)
rspec_api_documentation_client.send(http_method, path_or_query, params_or_body, headers)
end

def query_string
Expand Down Expand Up @@ -87,10 +87,14 @@ def headers
end
end

def method
def http_method
example.metadata[:method]
end

def method
http_method
end

def status
rspec_api_documentation_client.status
end
Expand Down

0 comments on commit 7d2eced

Please sign in to comment.