diff --git a/features/disable_dsl.feature b/features/disable_dsl.feature new file mode 100644 index 00000000..15ca3eb9 --- /dev/null +++ b/features/disable_dsl.feature @@ -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 diff --git a/lib/rspec_api_documentation/configuration.rb b/lib/rspec_api_documentation/configuration.rb index a28bb5bd..0d49ddbf 100644 --- a/lib/rspec_api_documentation/configuration.rb +++ b/lib/rspec_api_documentation/configuration.rb @@ -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 diff --git a/lib/rspec_api_documentation/dsl/endpoint.rb b/lib/rspec_api_documentation/dsl/endpoint.rb index d10456bc..e9376de2 100644 --- a/lib/rspec_api_documentation/dsl/endpoint.rb +++ b/lib/rspec_api_documentation/dsl/endpoint.rb @@ -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) @@ -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 @@ -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