module BigBench::Fragment

A fragment represents a single http request inside a benchmark. It is executed by the benchmark and resides inside the benchmark block in the test reciepts:

benchmark "index page" => "http://localhost:3000" do
  # Fragments
end

Possible fragment types are the HTTP verbs, like GET, POST, PUT and DELETE. They look like this:

get     "/"
post    "/login/new"
put     "/books"
delete  "/books/5", :params => { :token => '87bas67dfjgbrjbbgbi6ica7s0b3t0' }
get     "/admin", :basic_auth => ['username', 'password']

After any fragment an options hash can be appended. Possible options are:

:basic_auth

Supply a basic auth user and password for the request. The request then looks like this:

get "/", :basic_auth => ['username', 'password']
:params

Supply params for the request body, like e.g. form data:

post "/books/new", :params => { :book => { :title => "Metaprogramming Ruby", :publisher => "O'Reilly" } }
post "/trackings/add", :params => { :name => "Tommy" }

Public Class Methods

delete(path, options = {}) click to toggle source

Performs a DELETE request to the given url, e.g.

delete "/books/5"
# File lib/bigbench/fragment.rb, line 112
def self.delete(path, options = {})
  @fragments << Fragment.new(@benchmark, path, :delete, options)
end
get(path, options = {}) click to toggle source

Performs a GET request to the given url, e.g.

get "/some/page"
# File lib/bigbench/fragment.rb, line 88
def self.get(path, options = {})
  @fragments << Fragment.new(@benchmark, path, :get, options)
end
parse(benchmark, &block) click to toggle source

Evaluates a benchmark block full of puts and gets and returns an array of fully configured fragments for it

# File lib/bigbench/fragment.rb, line 117
def self.parse(benchmark, &block)
  reset!
  return [] if block.nil?
  @benchmark = benchmark
  module_exec(&block)
  @fragments
end
post(path, options = {}) click to toggle source

Performs a POST request to the given url, e.g.

post "/login"
# File lib/bigbench/fragment.rb, line 96
def self.post(path, options = {})
  @fragments << Fragment.new(@benchmark, path, :post, options)
end
put(path, options = {}) click to toggle source

Performs a PUT request to the given url, e.g.

put "/books"
# File lib/bigbench/fragment.rb, line 104
def self.put(path, options = {})
  @fragments << Fragment.new(@benchmark, path, :put, options)
end
reset!() click to toggle source

Reset all fragments

# File lib/bigbench/fragment.rb, line 126
def self.reset!
  @benchmark = nil
  @fragments = []
end