Skip to content

Commit ebe29cd

Browse files
author
Ruxton
committed
Added a couple of features to cover nested file upload parms
1 parent 4b5d6bc commit ebe29cd

File tree

1 file changed

+90
-9
lines changed

1 file changed

+90
-9
lines changed

features/upload_file.feature

Lines changed: 90 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Feature: Uploading a file
22
Background:
3-
Given a file named "app.rb" with:
3+
Given a file named "nonestedparam.rb" with:
44
"""
55
require 'rack'
66
@@ -11,8 +11,57 @@ Feature: Uploading a file
1111
end
1212
end
1313
"""
14+
Given a file named "nestedparam.rb" with:
15+
"""
16+
require 'rack'
1417
15-
Scenario: Uploading a text file
18+
class App
19+
def self.call(env)
20+
request = Rack::Request.new(env)
21+
[200, {}, [request.params["post"]["file"][:filename]]]
22+
end
23+
end
24+
"""
25+
26+
Scenario: Uploading a text file with nested parameters
27+
Given a file named "file.txt" with:
28+
"""
29+
a file to upload
30+
"""
31+
And a file named "app_spec.rb" with:
32+
"""
33+
require "rspec_api_documentation"
34+
require "rspec_api_documentation/dsl"
35+
require "rack/test"
36+
37+
RspecApiDocumentation.configure do |config|
38+
config.app = App
39+
end
40+
41+
resource "FooBars" do
42+
post "/foobar" do
43+
parameter :post, "Post paramter"
44+
45+
let(:post) do
46+
{
47+
id: 1,
48+
file: Rack::Test::UploadedFile.new("file.txt", "text/plain")
49+
}
50+
end
51+
52+
example_request "Uploading a file" do
53+
response_body.should == "file.txt"
54+
end
55+
end
56+
end
57+
"""
58+
59+
When I run `rspec app_spec.rb --require ./nestedparam.rb --format RspecApiDocumentation::ApiFormatter`
60+
61+
Then the output should contain "1 example, 0 failures"
62+
And the exit status should be 0
63+
64+
Scenario: Uploading a text file, no nested parameters
1665
Given a file named "file.txt" with:
1766
"""
1867
a file to upload
@@ -29,10 +78,8 @@ Feature: Uploading a file
2978
3079
resource "FooBars" do
3180
post "/foobar" do
32-
parameter :name, "Name of file"
3381
parameter :file, "File to upload"
3482
35-
let(:name) { "my-new-file.txt" }
3683
let(:file) do
3784
Rack::Test::UploadedFile.new("file.txt", "text/plain")
3885
end
@@ -44,12 +91,12 @@ Feature: Uploading a file
4491
end
4592
"""
4693

47-
When I run `rspec app_spec.rb --require ./app.rb --format RspecApiDocumentation::ApiFormatter`
94+
When I run `rspec app_spec.rb --require ./nonestedparam.rb --format RspecApiDocumentation::ApiFormatter`
4895

4996
Then the output should contain "1 example, 0 failures"
5097
And the exit status should be 0
5198

52-
Scenario: Uploading an image file
99+
Scenario: Uploading an image file, no nested parameters
53100
Given I move the sample image into the workspace
54101
And a file named "app_spec.rb" with:
55102
"""
@@ -63,10 +110,8 @@ Feature: Uploading a file
63110
64111
resource "FooBars" do
65112
post "/foobar" do
66-
parameter :name, "Name of file"
67113
parameter :file, "File to upload"
68114
69-
let(:name) { "my-new-file.txt" }
70115
let(:file) do
71116
Rack::Test::UploadedFile.new("file.png", "image/png")
72117
end
@@ -78,8 +123,44 @@ Feature: Uploading a file
78123
end
79124
"""
80125

81-
When I run `rspec app_spec.rb --require ./app.rb --format RspecApiDocumentation::ApiFormatter`
126+
When I run `rspec app_spec.rb --require ./nonestedparam.rb --format RspecApiDocumentation::ApiFormatter`
82127

83128
Then the output should contain "1 example, 0 failures"
84129
And the exit status should be 0
85130
And the generated documentation should be encoded correctly
131+
132+
Scenario: Uploading an image file, no nested parameters
133+
Given I move the sample image into the workspace
134+
And a file named "app_spec.rb" with:
135+
"""
136+
require "rspec_api_documentation"
137+
require "rspec_api_documentation/dsl"
138+
require "rack/test"
139+
140+
RspecApiDocumentation.configure do |config|
141+
config.app = App
142+
end
143+
144+
resource "FooBars" do
145+
post "/foobar" do
146+
parameter :post, "Post parameter"
147+
148+
let(:post) do
149+
{
150+
id: 10,
151+
file: Rack::Test::UploadedFile.new("file.png", "image/png")
152+
}
153+
end
154+
155+
example_request "Uploading a file" do
156+
response_body.should == "file.png"
157+
end
158+
end
159+
end
160+
"""
161+
162+
When I run `rspec app_spec.rb --require ./nestedparam.rb --format RspecApiDocumentation::ApiFormatter`
163+
164+
Then the output should contain "1 example, 0 failures"
165+
And the exit status should be 0
166+
And the generated documentation should be encoded correctly

0 commit comments

Comments
 (0)