|
| 1 | +Feature: Use OAuth2 MAC client as a test client |
| 2 | + Background: |
| 3 | + Given a file named "app_spec.rb" with: |
| 4 | + """ |
| 5 | + require "rspec_api_documentation" |
| 6 | + require "rspec_api_documentation/dsl" |
| 7 | + require "rack/builder" |
| 8 | + require "rack/oauth2" |
| 9 | +
|
| 10 | + RspecApiDocumentation.configure do |config| |
| 11 | + config.app = Rack::Builder.new do |
| 12 | + map "/oauth2/token" do |
| 13 | + app = lambda do |env| |
| 14 | + headers = {"Pragma"=>"no-cache", "Content-Type"=>"application/json", "Content-Length"=>"274", "Cache-Control"=>"no-store"} |
| 15 | + body = ["{\"mac_algorithm\":\"hmac-sha-256\",\"expires_in\":29,\"access_token\":\"HfIBIMe/hxNKSMogD33OJmLN+i9x3d2iM7WLzrN1RQvINOFz+QT8hiMiY+avbp2mc8IpzrxoupHyy0DeKuB05Q==\",\"token_type\":\"mac\",\"mac_key\":\"jb59zUztvDIC0AeaNZz+BptWvmFd4C41JyZS1DfWqKCkZTErxSMfkdjkePUcpE9/joqFt0ELyV/oIsFAf0V1ew==\"}"] |
| 16 | + [200, headers, body] |
| 17 | + end |
| 18 | +
|
| 19 | + run app |
| 20 | + end |
| 21 | +
|
| 22 | + map "/" do |
| 23 | + app = lambda do |env| |
| 24 | + if env["HTTP_AUTHORIZATION"].blank? |
| 25 | + return [401, {"Content-Type" => "text/plain"}, [""]] |
| 26 | + end |
| 27 | +
|
| 28 | + request = Rack::Request.new(env) |
| 29 | + response = Rack::Response.new |
| 30 | + response["Content-Type"] = "text/plain" |
| 31 | + response.write("hello #{request.params["target"]}") |
| 32 | + response.finish |
| 33 | + end |
| 34 | +
|
| 35 | + run app |
| 36 | + end |
| 37 | + end |
| 38 | + end |
| 39 | +
|
| 40 | + resource "Greetings" do |
| 41 | + let(:client) { RspecApiDocumentation::OAuth2MACClient.new(self, {:identifier => "1", :secret => "secret"}) } |
| 42 | +
|
| 43 | + get "/" do |
| 44 | + parameter :target, "The thing you want to greet" |
| 45 | +
|
| 46 | + example "Greeting your favorite gem" do |
| 47 | + do_request :target => "rspec_api_documentation" |
| 48 | +
|
| 49 | + response_headers["Content-Type"].should eq("text/plain") |
| 50 | + status.should eq(200) |
| 51 | + response_body.should eq('hello rspec_api_documentation') |
| 52 | + end |
| 53 | + end |
| 54 | + end |
| 55 | + """ |
| 56 | + When I run `rspec app_spec.rb --format RspecApiDocumentation::ApiFormatter` |
| 57 | + |
| 58 | + Scenario: Output should contain |
| 59 | + Then the output should contain: |
| 60 | + """ |
| 61 | + Generating API Docs |
| 62 | + Greetings |
| 63 | + GET / |
| 64 | + * Greeting your favorite gem |
| 65 | + """ |
| 66 | + And the output should contain "1 example, 0 failures" |
| 67 | + And the exit status should be 0 |
0 commit comments