Class: Stella::Testplan::Usecase
- Inherits:
-
Object
- Object
- Stella::Testplan::Usecase
- Includes:
- Gibbler::Complex
- Defined in:
- lib/stella/testplan/usecase.rb
Overview
Any valid Ruby syntax will do the trick:
usecase(10, "Self-serve") {
post("/listing/add", "Add a listing") {
wait 1..4
param :name => random(8)
param :city => "Vancouver"
response(302) {
repeat 3
}
}
}
Defined Under Namespace
Classes: UnknownResource
Instance Attribute Summary collapse
-
#base_path ⇒ Object
Returns the value of attribute base_path.
-
#desc(*args) ⇒ Object
Returns the value of attribute desc.
- #ratio ⇒ Object
-
#requests ⇒ Object
Returns the value of attribute requests.
-
#resources ⇒ Object
Returns the value of attribute resources.
Instance Method Summary collapse
- #add_request(meth, *args, &blk) ⇒ Object
- #delete(*args, &blk) ⇒ Object
- #get(*args, &blk) ⇒ Object
- #head(*args, &blk) ⇒ Object
-
#initialize(&blk) ⇒ Usecase
constructor
A new instance of Usecase.
- #list(path) ⇒ Object
- #post(*args, &blk) ⇒ Object
- #put(*args, &blk) ⇒ Object
- #ratio_pretty ⇒ Object
-
#read(path) ⇒ Object
Reads the contents of the file
path
(the current working directory is assumed to be the same directory containing the test plan). - #resource(name, value = nil) ⇒ Object
- #xdelete(*args, &blk) ⇒ Object
- #xget(*args, &blk) ⇒ Object
- #xhead(*args, &blk) ⇒ Object
- #xpost(*args, &blk) ⇒ Object
- #xput(*args, &blk) ⇒ Object
Constructor Details
#initialize(&blk) ⇒ Usecase
Returns a new instance of Usecase.
34 35 36 37 |
# File 'lib/stella/testplan/usecase.rb', line 34 def initialize(&blk) @requests, @resources = [], {} instance_eval &blk unless blk.nil? end |
Instance Attribute Details
#base_path ⇒ Object
Returns the value of attribute base_path.
28 29 30 |
# File 'lib/stella/testplan/usecase.rb', line 28 def base_path @base_path end |
#desc(*args) ⇒ Object
Returns the value of attribute desc.
23 24 25 |
# File 'lib/stella/testplan/usecase.rb', line 23 def desc @desc end |
#ratio ⇒ Object
49 50 51 52 53 |
# File 'lib/stella/testplan/usecase.rb', line 49 def ratio r = (@ratio || 0).to_f r = r/100 if r > 1 r end |
#requests ⇒ Object
Returns the value of attribute requests.
26 27 28 |
# File 'lib/stella/testplan/usecase.rb', line 26 def requests @requests end |
#resources ⇒ Object
Returns the value of attribute resources.
27 28 29 |
# File 'lib/stella/testplan/usecase.rb', line 27 def resources @resources end |
Instance Method Details
#add_request(meth, *args, &blk) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/stella/testplan/usecase.rb', line 71 def add_request(meth, *args, &blk) req = Stella::Data::HTTP::Request.new meth.to_s.upcase, args[0], &blk req.desc = args[1] if args.size > 1 # Description is optional Stella.ld req @requests << req req end |
#delete(*args, &blk) ⇒ Object
82 |
# File 'lib/stella/testplan/usecase.rb', line 82 def delete(*args, &blk); add_request :delete, *args, &blk; end |
#get(*args, &blk) ⇒ Object
78 |
# File 'lib/stella/testplan/usecase.rb', line 78 def get(*args, &blk); add_request :get, *args, &blk; end |
#head(*args, &blk) ⇒ Object
81 |
# File 'lib/stella/testplan/usecase.rb', line 81 def head(*args, &blk); add_request :head, *args, &blk; end |
#list(path) ⇒ Object
67 68 69 |
# File 'lib/stella/testplan/usecase.rb', line 67 def list(path) read(path).split $/ end |
#post(*args, &blk) ⇒ Object
80 |
# File 'lib/stella/testplan/usecase.rb', line 80 def post(*args, &blk); add_request :post, *args, &blk; end |
#put(*args, &blk) ⇒ Object
79 |
# File 'lib/stella/testplan/usecase.rb', line 79 def put(*args, &blk); add_request :put, *args, &blk; end |
#ratio_pretty ⇒ Object
55 56 57 58 |
# File 'lib/stella/testplan/usecase.rb', line 55 def ratio_pretty r = (@ratio || 0).to_f r > 1.0 ? r.to_i : (r * 100).to_i end |
#read(path) ⇒ Object
Reads the contents of the file path
(the current working directory is assumed to be the same directory containing the test plan).
62 63 64 65 |
# File 'lib/stella/testplan/usecase.rb', line 62 def read(path) path = File.join(@base_path, path) if @base_path File.read(path) end |
#resource(name, value = nil) ⇒ Object
44 45 46 47 |
# File 'lib/stella/testplan/usecase.rb', line 44 def resource(name, value=nil) @resources[name] = value unless value.nil? @resources[name] end |
#xdelete(*args, &blk) ⇒ Object
88 |
# File 'lib/stella/testplan/usecase.rb', line 88 def xdelete(*args, &blk); Stella.ld "Skipping delete" end |
#xget(*args, &blk) ⇒ Object
84 |
# File 'lib/stella/testplan/usecase.rb', line 84 def xget(*args, &blk); Stella.ld "Skipping get" end |
#xhead(*args, &blk) ⇒ Object
87 |
# File 'lib/stella/testplan/usecase.rb', line 87 def xhead(*args, &blk); Stella.ld "Skipping head" end |