1
+ Feature : Uploading a file
2
+ Background :
3
+ Given a file named "nonestedparam.rb" with:
4
+ """
5
+ require 'rack'
6
+
7
+ class App
8
+ def self.call(env)
9
+ request = Rack::Request.new(env)
10
+ [200, {}, [request.params["file"][:filename]]]
11
+ end
12
+ end
13
+ """
14
+ Given a file named "nestedparam.rb" with:
15
+ """
16
+ require 'rack'
17
+
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
65
+ Given a file named "file.txt" with:
66
+ """
67
+ a file to upload
68
+ """
69
+ And a file named "app_spec.rb" with:
70
+ """
71
+ require "rspec_api_documentation"
72
+ require "rspec_api_documentation/dsl"
73
+ require "rack/test"
74
+
75
+ RspecApiDocumentation.configure do |config|
76
+ config.app = App
77
+ end
78
+
79
+ resource "FooBars" do
80
+ post "/foobar" do
81
+ parameter :file, "File to upload"
82
+
83
+ let(:file) do
84
+ Rack::Test::UploadedFile.new("file.txt", "text/plain")
85
+ end
86
+
87
+ example_request "Uploading a file" do
88
+ response_body.should == "file.txt"
89
+ end
90
+ end
91
+ end
92
+ """
93
+
94
+ When I run `rspec app_spec.rb --require ./nonestedparam.rb --format RspecApiDocumentation::ApiFormatter`
95
+
96
+ Then the output should contain "1 example, 0 failures"
97
+ And the exit status should be 0
98
+
99
+ Scenario : Uploading an image file, no nested parameters
100
+ Given I move the sample image into the workspace
101
+ And a file named "app_spec.rb" with:
102
+ """
103
+ require "rspec_api_documentation"
104
+ require "rspec_api_documentation/dsl"
105
+ require "rack/test"
106
+
107
+ RspecApiDocumentation.configure do |config|
108
+ config.app = App
109
+ end
110
+
111
+ resource "FooBars" do
112
+ post "/foobar" do
113
+ parameter :file, "File to upload"
114
+
115
+ let(:file) do
116
+ Rack::Test::UploadedFile.new("file.png", "image/png")
117
+ end
118
+
119
+ example_request "Uploading a file" do
120
+ response_body.should == "file.png"
121
+ end
122
+ end
123
+ end
124
+ """
125
+
126
+ When I run `rspec app_spec.rb --require ./nonestedparam.rb --format RspecApiDocumentation::ApiFormatter`
127
+
128
+ Then the output should contain "1 example, 0 failures"
129
+ And the exit status should be 0
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