SlideShare una empresa de Scribd logo
1 de 27
Descargar para leer sin conexión
RSpec API
Documentation
   Eric Oestrich
   @ericoestrich
Who?
Zipmark - zipmark.com
Zipmark makes it simple and safe to quickly pay your rent,
bills, and even your friends for that coffee they bought you.


SmartLogic Solutions - smartlogicsolutions.com
We build applications to support the our clients' unique
visions.
What?
● Write tests that describe how your API
  should behave
● Automatically generate API documentation
  based on your tests


Keep your API docs in sync with your code
   If your tests fail, your API is broken
Why?
● Eliminate time spent writing API docs
● Actually write docs
● Document API while under active
  development
How?
● RSpec Formatters
● RSpec Metadata
● Extending RSpec with a custom DSL
Formatters
● A user-defined observer-type class, thing
  that does a thing when something happens
● Hooks -
  ○   example_group_started
  ○   example_passed
  ○   example_failed
  ○   start
  ○   stop
● Has access to metadata
Formatters
module RspecApiDocumentation
  class ApiFormatter < RSpec::Core::Formatters ::BaseFormatter
    def example_passed(example)
      super

      output .puts "   * #{example.description }"

      RspecApiDocumentation .documentations .each do |documentation |
        documentation .document_example(example)
      end
    end

    def example_failed(example)
      super

      output .puts "   ! #{example.description } (FAILED)"
    end
  end
end
Formatters

Use by running with -
  rspec spec/ --format 
    RspecApiDocumentation::ApiFormatter

Comes with a Railtie that defines -
  rake docs:generate
Metadata
 "You can attach user-defined metadata to any
example group or example. Pass a hash as the
  last argument (before the block) to describe,
       context or it. RSpec supports many
configuration options that apply only to certain
  examples or groups based on the metadata."
            - Rspec Core Docs, Metadata
Metadata
describe "a group with user-defined metadata" , :foo => 17 do
  it 'has access to the metadata in the example' do
    example .metadata[:foo].should eq( 17)
  end

 it 'does not have access to metadata defined on sub-groups'    do
   example .metadata.should_not include(:bar)
 end

 describe 'a sub-group with user-defined metadata' , :bar => 12 do
   it 'has access to the sub-group metadata' do
     example .metadata[:foo].should eq( 17)
   end

    it 'also has access to metadata defined on parent groups'   do
      example .metadata[:bar].should eq( 12)
    end
  end
end
Metadata

  In the formatter, we can look at examples'
     metadata to write API documentation

     For non-trivial metadata usage, it's
       cumbersome and error prone.
Metadata
it "Should create an order" ,
         :resource_name =>"Orders", :document=>true, :parameters =>[{:name=>"
         format", :description =>"Format of response" , :required=>true}, {:
         name=>"name", :description =>"Name of order" , :scope=>:order}, {:
         name=>"paid", :description =>"If the order has been paid for" , :
         scope=>:order}, {:name=>"email", :description =>"Email of user
         that placed the order" , :scope=>:order}], :method=>:post, :
         path=>"/orders.:format" do

      test_client .post("/orders.json" , :email => "email@example.com" )
end
Who wants to do that?
DSL
resource "Orders" do
  parameter :format, "Format of response"

 required_parameters :format

 let(:format) { :json }

 post "/orders.:format" do
   parameter :name, "Name of order"
   parameter :paid, "If the order has been paid for"
   parameter :email, "Email of user that placed the order"

   let(:email) { "email@example.com" }

   scope_parameters :order, [:name, :paid, :email]

    example "Creating an order" do
      do_request
    end
  end
end
DSL
● Rspec provides an API for extending its DSL
● Use metadata to augment test logic
Extending RSpec
● RSpec will include a module when metadata
  criteria are met
    RSpec.configuration .include RspecApiDocumentation ::DSL, :api_docs_dsl
=> true
Augment Test Logic
parameter
resource "Orders" do
  parameter :name

  let(:name) { "My Order" }
  # automatically sets params to {:name => "My Order"}
end
scope_parameter
resource "Orders" do
  parameter :name
  scope_parameters :order, [:name]

  let(:name) { "My Order" }
  # automatically sets params to {:order => {:name => "My Order"}}
end
delete, get, post, put
resource "Orders" do
  parameter :name
  let(:name) { "My Order" }

  post "/orders" do
    # when do_request is called it will POST to /orders
  end
end
do_request
resource "Orders" do
  parameter :name
  let(:name) { "My Order" }

  post "/orders" do
    example "Creating an order" do
      do_request
      # POST to /orders and send parameters
    end
  end
end
What does it look like?
Formats
● HTML
● JSON
Future Additions
● Document multiple requests/responses
● Don't pollute RSpec metadata
Where?
GitHub
github.com/zipmark/rspec_api_documentation

Más contenido relacionado

La actualidad más candente

5 Reasons To Love CodeIgniter
5 Reasons To Love CodeIgniter5 Reasons To Love CodeIgniter
5 Reasons To Love CodeIgniter
nicdev
 
I18n
I18nI18n
I18n
soon
 

La actualidad más candente (20)

RSpec and Rails
RSpec and RailsRSpec and Rails
RSpec and Rails
 
RSpec User Stories
RSpec User StoriesRSpec User Stories
RSpec User Stories
 
TDD, BDD, RSpec
TDD, BDD, RSpecTDD, BDD, RSpec
TDD, BDD, RSpec
 
Build REST API clients for AngularJS
Build REST API clients for AngularJSBuild REST API clients for AngularJS
Build REST API clients for AngularJS
 
Factory Girl
Factory GirlFactory Girl
Factory Girl
 
2019-08-23 API contract testing with Dredd
2019-08-23 API contract testing with Dredd2019-08-23 API contract testing with Dredd
2019-08-23 API contract testing with Dredd
 
TDD with phpspec2
TDD with phpspec2TDD with phpspec2
TDD with phpspec2
 
Build REST APIs like a Jedi with Symfony2
Build REST APIs like a Jedi with Symfony2Build REST APIs like a Jedi with Symfony2
Build REST APIs like a Jedi with Symfony2
 
Rspec 101
Rspec 101Rspec 101
Rspec 101
 
Consume RESTful APIs with $resource and Restangular
Consume RESTful APIs with $resource and RestangularConsume RESTful APIs with $resource and Restangular
Consume RESTful APIs with $resource and Restangular
 
5 Reasons To Love CodeIgniter
5 Reasons To Love CodeIgniter5 Reasons To Love CodeIgniter
5 Reasons To Love CodeIgniter
 
Sphinx on Rails
Sphinx on RailsSphinx on Rails
Sphinx on Rails
 
Create a web-app with Cgi Appplication
Create a web-app with Cgi AppplicationCreate a web-app with Cgi Appplication
Create a web-app with Cgi Appplication
 
Build a bot workshop async primer - php[tek]
Build a bot workshop  async primer - php[tek]Build a bot workshop  async primer - php[tek]
Build a bot workshop async primer - php[tek]
 
RSpec. Part 2
RSpec. Part 2RSpec. Part 2
RSpec. Part 2
 
I18n
I18nI18n
I18n
 
Clean Code
Clean CodeClean Code
Clean Code
 
Apache mod_rewrite
Apache mod_rewriteApache mod_rewrite
Apache mod_rewrite
 
ZendCon 2017 - Build a Bot Workshop - Async Primer
ZendCon 2017 - Build a Bot Workshop - Async PrimerZendCon 2017 - Build a Bot Workshop - Async Primer
ZendCon 2017 - Build a Bot Workshop - Async Primer
 
Ant
Ant Ant
Ant
 

Similar a Rspec API Documentation

Using Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databasesUsing Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databases
Raimonds Simanovskis
 
Google apps script database abstraction exposed version
Google apps script database abstraction   exposed versionGoogle apps script database abstraction   exposed version
Google apps script database abstraction exposed version
Bruce McPherson
 
From HelloWorld to Configurable and Reusable Apache Spark Applications in Sca...
From HelloWorld to Configurable and Reusable Apache Spark Applications in Sca...From HelloWorld to Configurable and Reusable Apache Spark Applications in Sca...
From HelloWorld to Configurable and Reusable Apache Spark Applications in Sca...
Databricks
 
Metaprogramovanie #1
Metaprogramovanie #1Metaprogramovanie #1
Metaprogramovanie #1
Jano Suchal
 

Similar a Rspec API Documentation (20)

OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)
OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)
OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)
 
Pxb For Yapc2008
Pxb For Yapc2008Pxb For Yapc2008
Pxb For Yapc2008
 
Rails on Oracle 2011
Rails on Oracle 2011Rails on Oracle 2011
Rails on Oracle 2011
 
Using Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databasesUsing Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databases
 
MuleSoft London Community February 2020 - MuleSoft and OData
MuleSoft London Community February 2020 - MuleSoft and ODataMuleSoft London Community February 2020 - MuleSoft and OData
MuleSoft London Community February 2020 - MuleSoft and OData
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
Fluentd unified logging layer
Fluentd   unified logging layerFluentd   unified logging layer
Fluentd unified logging layer
 
AWS November Webinar Series - Advanced Analytics with Amazon Redshift and the...
AWS November Webinar Series - Advanced Analytics with Amazon Redshift and the...AWS November Webinar Series - Advanced Analytics with Amazon Redshift and the...
AWS November Webinar Series - Advanced Analytics with Amazon Redshift and the...
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep Dive
 
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted NewardArchitecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
 
Google apps script database abstraction exposed version
Google apps script database abstraction   exposed versionGoogle apps script database abstraction   exposed version
Google apps script database abstraction exposed version
 
Elasticsearch an overview
Elasticsearch   an overviewElasticsearch   an overview
Elasticsearch an overview
 
Ams adapters
Ams adaptersAms adapters
Ams adapters
 
Big Data Processing with Spark and .NET - Microsoft Ignite 2019
Big Data Processing with Spark and .NET - Microsoft Ignite 2019Big Data Processing with Spark and .NET - Microsoft Ignite 2019
Big Data Processing with Spark and .NET - Microsoft Ignite 2019
 
SF Elixir Meetup - RethinkDB
SF Elixir Meetup - RethinkDBSF Elixir Meetup - RethinkDB
SF Elixir Meetup - RethinkDB
 
Compass Framework
Compass FrameworkCompass Framework
Compass Framework
 
Practical OData
Practical ODataPractical OData
Practical OData
 
iOS Swift application architecture
iOS Swift application architectureiOS Swift application architecture
iOS Swift application architecture
 
From HelloWorld to Configurable and Reusable Apache Spark Applications in Sca...
From HelloWorld to Configurable and Reusable Apache Spark Applications in Sca...From HelloWorld to Configurable and Reusable Apache Spark Applications in Sca...
From HelloWorld to Configurable and Reusable Apache Spark Applications in Sca...
 
Metaprogramovanie #1
Metaprogramovanie #1Metaprogramovanie #1
Metaprogramovanie #1
 

Más de SmartLogic

How SmartLogic Uses Chef-Dan Ivovich
How SmartLogic Uses Chef-Dan IvovichHow SmartLogic Uses Chef-Dan Ivovich
How SmartLogic Uses Chef-Dan Ivovich
SmartLogic
 

Más de SmartLogic (20)

Writing Game Servers with Elixir
Writing Game Servers with ElixirWriting Game Servers with Elixir
Writing Game Servers with Elixir
 
All Aboard The Stateful Train
All Aboard The Stateful TrainAll Aboard The Stateful Train
All Aboard The Stateful Train
 
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan IvovichDC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
 
Monitoring Your Elixir Application with Prometheus
Monitoring Your Elixir Application with PrometheusMonitoring Your Elixir Application with Prometheus
Monitoring Your Elixir Application with Prometheus
 
Going Multi-Node
Going Multi-NodeGoing Multi-Node
Going Multi-Node
 
Kubernetes and docker
Kubernetes and dockerKubernetes and docker
Kubernetes and docker
 
Serializing Value Objects-Ara Hacopian
Serializing Value Objects-Ara HacopianSerializing Value Objects-Ara Hacopian
Serializing Value Objects-Ara Hacopian
 
Guide to food foraging by SmartLogic's Kei Ellerbrock
Guide to food foraging by SmartLogic's Kei EllerbrockGuide to food foraging by SmartLogic's Kei Ellerbrock
Guide to food foraging by SmartLogic's Kei Ellerbrock
 
Introduction to Type Script by Sam Goldman, SmartLogic
Introduction to Type Script by Sam Goldman, SmartLogicIntroduction to Type Script by Sam Goldman, SmartLogic
Introduction to Type Script by Sam Goldman, SmartLogic
 
How SmartLogic Uses Chef-Dan Ivovich
How SmartLogic Uses Chef-Dan IvovichHow SmartLogic Uses Chef-Dan Ivovich
How SmartLogic Uses Chef-Dan Ivovich
 
A Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming LanguageA Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming Language
 
Effective ActiveRecord
Effective ActiveRecordEffective ActiveRecord
Effective ActiveRecord
 
An Introduction to Reactive Cocoa
An Introduction to Reactive CocoaAn Introduction to Reactive Cocoa
An Introduction to Reactive Cocoa
 
iOS Development Methodology
iOS Development MethodologyiOS Development Methodology
iOS Development Methodology
 
CSS Preprocessors to the Rescue!
CSS Preprocessors to the Rescue!CSS Preprocessors to the Rescue!
CSS Preprocessors to the Rescue!
 
Deploying Rails Apps with Chef and Capistrano
 Deploying Rails Apps with Chef and Capistrano Deploying Rails Apps with Chef and Capistrano
Deploying Rails Apps with Chef and Capistrano
 
From Slacker to Hacker, Practical Tips for Learning to Code
From Slacker to Hacker, Practical Tips for Learning to CodeFrom Slacker to Hacker, Practical Tips for Learning to Code
From Slacker to Hacker, Practical Tips for Learning to Code
 
The Language of Abstraction in Software Development
The Language of Abstraction in Software DevelopmentThe Language of Abstraction in Software Development
The Language of Abstraction in Software Development
 
Android Testing: An Overview
Android Testing: An OverviewAndroid Testing: An Overview
Android Testing: An Overview
 
Intro to DTCoreText: Moving Past UIWebView | iOS Development
Intro to DTCoreText: Moving Past UIWebView | iOS DevelopmentIntro to DTCoreText: Moving Past UIWebView | iOS Development
Intro to DTCoreText: Moving Past UIWebView | iOS Development
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 

Rspec API Documentation

  • 1. RSpec API Documentation Eric Oestrich @ericoestrich
  • 2. Who? Zipmark - zipmark.com Zipmark makes it simple and safe to quickly pay your rent, bills, and even your friends for that coffee they bought you. SmartLogic Solutions - smartlogicsolutions.com We build applications to support the our clients' unique visions.
  • 3. What? ● Write tests that describe how your API should behave ● Automatically generate API documentation based on your tests Keep your API docs in sync with your code If your tests fail, your API is broken
  • 4. Why? ● Eliminate time spent writing API docs ● Actually write docs ● Document API while under active development
  • 5. How? ● RSpec Formatters ● RSpec Metadata ● Extending RSpec with a custom DSL
  • 6. Formatters ● A user-defined observer-type class, thing that does a thing when something happens ● Hooks - ○ example_group_started ○ example_passed ○ example_failed ○ start ○ stop ● Has access to metadata
  • 7. Formatters module RspecApiDocumentation class ApiFormatter < RSpec::Core::Formatters ::BaseFormatter def example_passed(example) super output .puts " * #{example.description }" RspecApiDocumentation .documentations .each do |documentation | documentation .document_example(example) end end def example_failed(example) super output .puts " ! #{example.description } (FAILED)" end end end
  • 8. Formatters Use by running with - rspec spec/ --format RspecApiDocumentation::ApiFormatter Comes with a Railtie that defines - rake docs:generate
  • 9. Metadata "You can attach user-defined metadata to any example group or example. Pass a hash as the last argument (before the block) to describe, context or it. RSpec supports many configuration options that apply only to certain examples or groups based on the metadata." - Rspec Core Docs, Metadata
  • 10. Metadata describe "a group with user-defined metadata" , :foo => 17 do it 'has access to the metadata in the example' do example .metadata[:foo].should eq( 17) end it 'does not have access to metadata defined on sub-groups' do example .metadata.should_not include(:bar) end describe 'a sub-group with user-defined metadata' , :bar => 12 do it 'has access to the sub-group metadata' do example .metadata[:foo].should eq( 17) end it 'also has access to metadata defined on parent groups' do example .metadata[:bar].should eq( 12) end end end
  • 11. Metadata In the formatter, we can look at examples' metadata to write API documentation For non-trivial metadata usage, it's cumbersome and error prone.
  • 12. Metadata it "Should create an order" , :resource_name =>"Orders", :document=>true, :parameters =>[{:name=>" format", :description =>"Format of response" , :required=>true}, {: name=>"name", :description =>"Name of order" , :scope=>:order}, {: name=>"paid", :description =>"If the order has been paid for" , : scope=>:order}, {:name=>"email", :description =>"Email of user that placed the order" , :scope=>:order}], :method=>:post, : path=>"/orders.:format" do test_client .post("/orders.json" , :email => "email@example.com" ) end
  • 13. Who wants to do that?
  • 14. DSL resource "Orders" do parameter :format, "Format of response" required_parameters :format let(:format) { :json } post "/orders.:format" do parameter :name, "Name of order" parameter :paid, "If the order has been paid for" parameter :email, "Email of user that placed the order" let(:email) { "email@example.com" } scope_parameters :order, [:name, :paid, :email] example "Creating an order" do do_request end end end
  • 15. DSL ● Rspec provides an API for extending its DSL ● Use metadata to augment test logic
  • 16. Extending RSpec ● RSpec will include a module when metadata criteria are met RSpec.configuration .include RspecApiDocumentation ::DSL, :api_docs_dsl => true
  • 18. parameter resource "Orders" do parameter :name let(:name) { "My Order" } # automatically sets params to {:name => "My Order"} end
  • 19. scope_parameter resource "Orders" do parameter :name scope_parameters :order, [:name] let(:name) { "My Order" } # automatically sets params to {:order => {:name => "My Order"}} end
  • 20. delete, get, post, put resource "Orders" do parameter :name let(:name) { "My Order" } post "/orders" do # when do_request is called it will POST to /orders end end
  • 21. do_request resource "Orders" do parameter :name let(:name) { "My Order" } post "/orders" do example "Creating an order" do do_request # POST to /orders and send parameters end end end
  • 22. What does it look like?
  • 23.
  • 24.
  • 26. Future Additions ● Document multiple requests/responses ● Don't pollute RSpec metadata