Commit c235162b by andrew morton

Few cleanups

parent 22adfbaa
......@@ -6,7 +6,14 @@ The design of this is heavily influenced by the awesome [swagger_rails](https://
- install gem
- `rails generate rspec:install`
- create `spec/swagger_helper.rb` ... would be nice to be a generator
- create `spec/swagger_helper.rb` (I'll try to get a generator to automate this)
- define your tests (I definitely need to make this step more explicit)
## Generate the docs
```
bundle exec rspec -f RSpec::Swagger::Formatter --order defined -t swagger_object
```
## Running tests
......
......@@ -174,15 +174,15 @@ module RSpec
before do |example|
builder = RequestBuilder.new(example.metadata, self)
method = builder.method
path = builder.path + builder.query
path = [builder.path, builder.query].join
headers = builder.headers
params = resolve_params(example.metadata, self)
body = builder.body
# Run the request
if ::Rails::VERSION::MAJOR >= 5
self.send(method, path, {params: params, headers: headers})
self.send(method, path, {params: body, headers: headers})
else
self.send(method, path, params, headers)
self.send(method, path, body, headers)
end
if example.metadata[:capture_example]
......
......@@ -49,22 +49,24 @@ module RSpec
# in the example group.
path = base_path + metadata[:swagger_path_item][:path].gsub(/(\{.*?\})/) do |match|
# QUESTION: Should check that the parameter is actually defined in
# `metadata[:swagger_*][:parameters]` before fetch a value?
# `parameters` before fetch a value?
instance.send(match[1...-1])
end
end
def query
# Don't bother with the parameter bodies since all we need is location
# and name which make up the key.
query_params = parameters.keys
.map{ |k| k.split('&')}
# Don't bother looking at the full parameter bodies since all we need
# are location and name which are the key.
query_params = parameters.keys.map{ |k| k.split('&')}
.select{ |location, name| location == 'query' }
.map{ |location, name| [name, instance.send(name)] }
'?' + Hash[query_params].to_query unless query_params.empty?
end
def body
# And here all we need is the first half of the key to find the body
# parameter and its name to fetch a value.
if key = parameters.keys.find{ |k| k.starts_with? 'body&' }
instance.send(key.split('&').last).to_json
end
......
......@@ -42,7 +42,6 @@ RSpec.describe "Requestsing", type: :request do
produces 'application/json'
before { Post.new.save }
parameter "op-param", {in: :query, type: :string}
response(200, {description: "success"}, {}) do
capture_example
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment