Skip to content

Commit 7d2eced

Browse files
committed
Add configuration option to disable DSL methods status, and method
1 parent 0659ef6 commit 7d2eced

File tree

3 files changed

+69
-3
lines changed

3 files changed

+69
-3
lines changed

features/disable_dsl.feature

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Feature: Disable DSL features
2+
Background:
3+
Given a file named "app.rb" with:
4+
"""
5+
class App
6+
def self.call(env)
7+
request = Rack::Request.new(env)
8+
response = Rack::Response.new
9+
response["Content-Type"] = "text/plain"
10+
response.write(request.params["status"])
11+
response.write(request.params["method"])
12+
response.finish
13+
end
14+
end
15+
"""
16+
And a file named "app_spec.rb" with:
17+
"""
18+
require "rspec_api_documentation"
19+
require "rspec_api_documentation/dsl"
20+
21+
RspecApiDocumentation.configure do |config|
22+
config.app = App
23+
config.disable_dsl_status!
24+
config.disable_dsl_method!
25+
end
26+
27+
resource "Orders" do
28+
get "/orders" do
29+
parameter :status, "Order status to search for"
30+
parameter :method, "Method of delivery to search for"
31+
32+
example "Viewing all orders" do
33+
do_request :status => "pending"
34+
expect(response_status).to eq(200)
35+
expect(response_body).to eq("pending")
36+
end
37+
38+
example "Checking the method" do
39+
do_request :method => "ground"
40+
expect(http_method).to eq(:get)
41+
expect(response_body).to eq("ground")
42+
end
43+
end
44+
end
45+
"""
46+
When I run `rspec app_spec.rb --require ./app.rb --format RspecApiDocumentation::ApiFormatter`
47+
48+
Scenario: Output should have the correct error line
49+
Then the output should contain "2 examples, 0 failures"
50+
And the exit status should be 0

lib/rspec_api_documentation/configuration.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ def client_method
106106
@client_method ||= :client
107107
end
108108

109+
def disable_dsl_status!
110+
RspecApiDocumentation::DSL::Endpoint.module_eval <<-RUBY
111+
undef status
112+
RUBY
113+
end
114+
115+
def disable_dsl_method!
116+
RspecApiDocumentation::DSL::Endpoint.module_eval <<-RUBY
117+
undef method
118+
RUBY
119+
end
120+
109121
def settings
110122
@settings ||= {}
111123
end

lib/rspec_api_documentation/dsl/endpoint.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def do_request(extra_params = {})
3535
params_or_body = nil
3636
path_or_query = path
3737

38-
if method == :get && !query_string.blank?
38+
if http_method == :get && !query_string.blank?
3939
path_or_query += "?#{query_string}"
4040
else
4141
if respond_to?(:raw_post)
@@ -55,7 +55,7 @@ def do_request(extra_params = {})
5555
end
5656
end
5757

58-
rspec_api_documentation_client.send(method, path_or_query, params_or_body, headers)
58+
rspec_api_documentation_client.send(http_method, path_or_query, params_or_body, headers)
5959
end
6060

6161
def query_string
@@ -87,10 +87,14 @@ def headers
8787
end
8888
end
8989

90-
def method
90+
def http_method
9191
example.metadata[:method]
9292
end
9393

94+
def method
95+
http_method
96+
end
97+
9498
def status
9599
rspec_api_documentation_client.status
96100
end

0 commit comments

Comments
 (0)