|
| 1 | +Feature: Uploading a file |
| 2 | + Background: |
| 3 | + Given a file named "app.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 | + |
| 15 | + Scenario: Uploading a text file |
| 16 | + Given a file named "file.txt" with: |
| 17 | + """ |
| 18 | + a file to upload |
| 19 | + """ |
| 20 | + And a file named "app_spec.rb" with: |
| 21 | + """ |
| 22 | + require "rspec_api_documentation" |
| 23 | + require "rspec_api_documentation/dsl" |
| 24 | + require "rack/test" |
| 25 | +
|
| 26 | + RspecApiDocumentation.configure do |config| |
| 27 | + config.app = App |
| 28 | + end |
| 29 | +
|
| 30 | + resource "FooBars" do |
| 31 | + post "/foobar" do |
| 32 | + parameter :name, "Name of file" |
| 33 | + parameter :file, "File to upload" |
| 34 | +
|
| 35 | + let(:name) { "my-new-file.txt" } |
| 36 | + let(:file) do |
| 37 | + Rack::Test::UploadedFile.new("file.txt", "text/plain") |
| 38 | + end |
| 39 | +
|
| 40 | + example_request "Uploading a file" do |
| 41 | + response_body.should == "file.txt" |
| 42 | + end |
| 43 | + end |
| 44 | + end |
| 45 | + """ |
| 46 | + |
| 47 | + When I run `rspec app_spec.rb --require ./app.rb --format RspecApiDocumentation::ApiFormatter` |
| 48 | + |
| 49 | + Then the output should contain "1 example, 0 failures" |
| 50 | + And the exit status should be 0 |
| 51 | + |
| 52 | + Scenario: Uploading an image file |
| 53 | + Given I move the sample image into the workspace |
| 54 | + And a file named "app_spec.rb" with: |
| 55 | + """ |
| 56 | + require "rspec_api_documentation" |
| 57 | + require "rspec_api_documentation/dsl" |
| 58 | + require "rack/test" |
| 59 | +
|
| 60 | + RspecApiDocumentation.configure do |config| |
| 61 | + config.app = App |
| 62 | + end |
| 63 | +
|
| 64 | + resource "FooBars" do |
| 65 | + post "/foobar" do |
| 66 | + parameter :name, "Name of file" |
| 67 | + parameter :file, "File to upload" |
| 68 | +
|
| 69 | + let(:name) { "my-new-file.txt" } |
| 70 | + let(:file) do |
| 71 | + Rack::Test::UploadedFile.new("file.png", "image/png") |
| 72 | + end |
| 73 | +
|
| 74 | + example_request "Uploading a file" do |
| 75 | + response_body.should == "file.png" |
| 76 | + end |
| 77 | + end |
| 78 | + end |
| 79 | + """ |
| 80 | + |
| 81 | + When I run `rspec app_spec.rb --require ./app.rb --format RspecApiDocumentation::ApiFormatter` |
| 82 | + |
| 83 | + Then the output should contain "1 example, 0 failures" |
| 84 | + And the exit status should be 0 |
| 85 | + And the generated documentation should be encoded correctly |
0 commit comments