|
| 1 | +Feature: Generate HTML documentation from test examples |
| 2 | + |
| 3 | + Background: |
| 4 | + Given a file named "app.rb" with: |
| 5 | + """ |
| 6 | + require "sinatra/base" |
| 7 | +
|
| 8 | + class App < Sinatra::Base |
| 9 | + before do |
| 10 | + content_type :json |
| 11 | + end |
| 12 | +
|
| 13 | + get "/greetings" do |
| 14 | + if target = params["target"] |
| 15 | + { "hello" => params["target"] }.to_json |
| 16 | + else |
| 17 | + 422 |
| 18 | + end |
| 19 | + end |
| 20 | + end |
| 21 | + """ |
| 22 | + And a file named "app_spec.rb" with: |
| 23 | + """ |
| 24 | + require "active_support/inflector" |
| 25 | + require "rspec_api_documentation" |
| 26 | + require "rspec_api_documentation/dsl" |
| 27 | +
|
| 28 | + RspecApiDocumentation.configure do |config| |
| 29 | + config.app = App |
| 30 | + end |
| 31 | +
|
| 32 | + resource "Greetings" do |
| 33 | + get "/greetings" do |
| 34 | + parameter :target, "The thing you want to greet" |
| 35 | +
|
| 36 | + example "Greeting your favorite gem" do |
| 37 | + do_request :target => "rspec_api_documentation" |
| 38 | +
|
| 39 | + status.should eq(200) |
| 40 | + response_body.should eq('{"hello":"rspec_api_documentation"}') |
| 41 | + end |
| 42 | + end |
| 43 | + end |
| 44 | + """ |
| 45 | + When I run `rspec app_spec.rb --require ./app.rb --format RspecApiDocumentation::ApiFormatter` |
| 46 | + |
| 47 | + Scenario: Output helpful progress to the console |
| 48 | + Then the output should contain: |
| 49 | + """ |
| 50 | + Generating API Docs |
| 51 | + Greetings |
| 52 | + GET /greetings |
| 53 | + * Greeting your favorite gem |
| 54 | + """ |
| 55 | + And the output should contain "1 example, 0 failures" |
| 56 | + And the exit status should be 0 |
| 57 | + |
| 58 | + Scenario: Create an index of all API examples, including all resources and examples |
| 59 | + Then the file "docs/index.html" should contain "<h2>Greetings</h2>" |
| 60 | + And the file "docs/index.html" should contain: |
| 61 | + """ |
| 62 | + <a href="greetings/greeting_your_favorite_gem.html">Greeting your favorite gem</a> |
| 63 | + """ |
| 64 | + |
| 65 | + Scenario: Create a file for each API example |
| 66 | + Then the file "docs/greetings/greeting_your_favorite_gem.html" should contain "<h2>Greeting your favorite gem</h2>" |
0 commit comments