1
1
Feature : Uploading a file
2
2
Background :
3
- Given a file named "app .rb" with:
3
+ Given a file named "nonestedparam .rb" with:
4
4
"""
5
5
require 'rack'
6
6
@@ -11,8 +11,57 @@ Feature: Uploading a file
11
11
end
12
12
end
13
13
"""
14
+ Given a file named "nestedparam.rb" with:
15
+ """
16
+ require 'rack'
14
17
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
16
65
Given a file named "file.txt" with:
17
66
"""
18
67
a file to upload
@@ -29,10 +78,8 @@ Feature: Uploading a file
29
78
30
79
resource "FooBars" do
31
80
post "/foobar" do
32
- parameter :name, "Name of file"
33
81
parameter :file, "File to upload"
34
82
35
- let(:name) { "my-new-file.txt" }
36
83
let(:file) do
37
84
Rack::Test::UploadedFile.new("file.txt", "text/plain")
38
85
end
@@ -44,12 +91,12 @@ Feature: Uploading a file
44
91
end
45
92
"""
46
93
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`
48
95
49
96
Then the output should contain "1 example, 0 failures"
50
97
And the exit status should be 0
51
98
52
- Scenario : Uploading an image file
99
+ Scenario : Uploading an image file, no nested parameters
53
100
Given I move the sample image into the workspace
54
101
And a file named "app_spec.rb" with:
55
102
"""
@@ -63,10 +110,8 @@ Feature: Uploading a file
63
110
64
111
resource "FooBars" do
65
112
post "/foobar" do
66
- parameter :name, "Name of file"
67
113
parameter :file, "File to upload"
68
114
69
- let(:name) { "my-new-file.txt" }
70
115
let(:file) do
71
116
Rack::Test::UploadedFile.new("file.png", "image/png")
72
117
end
@@ -78,8 +123,44 @@ Feature: Uploading a file
78
123
end
79
124
"""
80
125
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`
82
127
83
128
Then the output should contain "1 example, 0 failures"
84
129
And the exit status should be 0
85
130
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