Module: BigBench::Fragment
- Defined in:
- lib/bigbench/fragment.rb
Overview
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" }
Defined Under Namespace
Classes: Fragment
Class Method Summary collapse
-
.delete(path, options = {}) ⇒ Object
Performs a DELETE request to the given url, e.g.
-
.get(path, options = {}) ⇒ Object
Performs a GET request to the given url, e.g.
-
.parse(benchmark, &block) ⇒ Object
Evaluates a benchmark block full of puts and gets and returns an array of fully configured fragments for it.
-
.post(path, options = {}) ⇒ Object
Performs a POST request to the given url, e.g.
-
.put(path, options = {}) ⇒ Object
Performs a PUT request to the given url, e.g.
-
.reset! ⇒ Object
Reset all fragments.
Class Method Details
.delete(path, options = {}) ⇒ Object
Performs a DELETE request to the given url, e.g.
delete "/books/5"
117 118 119 |
# File 'lib/bigbench/fragment.rb', line 117 def self.delete(path, = {}) @fragments << Fragment.new(@benchmark, path, :delete, ) end |
.get(path, options = {}) ⇒ Object
Performs a GET request to the given url, e.g.
get "/some/page"
93 94 95 |
# File 'lib/bigbench/fragment.rb', line 93 def self.get(path, = {}) @fragments << Fragment.new(@benchmark, path, :get, ) end |
.parse(benchmark, &block) ⇒ Object
Evaluates a benchmark block full of puts and gets and returns an array of fully configured fragments for it
122 123 124 125 126 127 128 |
# File 'lib/bigbench/fragment.rb', line 122 def self.parse(benchmark, &block) reset! return [] if block.nil? @benchmark = benchmark module_exec(&block) @fragments end |
.post(path, options = {}) ⇒ Object
Performs a POST request to the given url, e.g.
post "/login"
101 102 103 |
# File 'lib/bigbench/fragment.rb', line 101 def self.post(path, = {}) @fragments << Fragment.new(@benchmark, path, :post, ) end |
.put(path, options = {}) ⇒ Object
Performs a PUT request to the given url, e.g.
put "/books"
109 110 111 |
# File 'lib/bigbench/fragment.rb', line 109 def self.put(path, = {}) @fragments << Fragment.new(@benchmark, path, :put, ) end |
.reset! ⇒ Object
Reset all fragments
131 132 133 134 |
# File 'lib/bigbench/fragment.rb', line 131 def self.reset! @benchmark = nil @fragments = [] end |