Class: LieDetector::Suite
- Inherits:
-
Object
- Object
- LieDetector::Suite
- Defined in:
- lib/liedetector/suite.rb
Instance Attribute Summary collapse
-
#headers_defaults ⇒ Object
Returns the value of attribute headers_defaults.
-
#http_defaults ⇒ Object
Returns the value of attribute http_defaults.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #build_uri(path, query: nil, fragment: nil) ⇒ Object
- #code_block(code) ⇒ Object
-
#initialize(filepath) ⇒ Suite
constructor
A new instance of Suite.
- #push_descriptions(text) ⇒ Object
- #register(cls, name) ⇒ Object
-
#request(name, method, path, &blk) ⇒ Object
Sugar to not define classes in the doc.
- #run ⇒ Object
- #session ⇒ Object
- #store_data ⇒ Object
- #store_key(key, data) ⇒ Object
Constructor Details
#initialize(filepath) ⇒ Suite
Returns a new instance of Suite.
5 6 7 8 9 |
# File 'lib/liedetector/suite.rb', line 5 def initialize(filepath) @filepath = filepath self.headers_defaults = {'Accept' => 'application/json'} self.http_defaults = {host: '127.0.0.1', port: 3000} end |
Instance Attribute Details
#headers_defaults ⇒ Object
Returns the value of attribute headers_defaults.
3 4 5 |
# File 'lib/liedetector/suite.rb', line 3 def headers_defaults @headers_defaults end |
#http_defaults ⇒ Object
Returns the value of attribute http_defaults.
3 4 5 |
# File 'lib/liedetector/suite.rb', line 3 def http_defaults @http_defaults end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
55 56 57 |
# File 'lib/liedetector/suite.rb', line 55 def store @store end |
Instance Method Details
#build_uri(path, query: nil, fragment: nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/liedetector/suite.rb', line 11 def build_uri(path, query: nil, fragment: nil) query = URI.encode_www_form(query) if query.is_a? Hash scheme = http_defaults[:scheme] || 'http' if scheme == 'http' URI::HTTP elsif scheme == 'https' URI::HTTPS else raise 'Bad configuration' end.build(http_defaults.merge(path: path, query: query, fragment: fragment)).to_s end |
#code_block(code) ⇒ Object
69 70 71 |
# File 'lib/liedetector/suite.rb', line 69 def code_block(code) self.instance_eval(code, @filepath) end |
#push_descriptions(text) ⇒ Object
32 33 34 35 |
# File 'lib/liedetector/suite.rb', line 32 def push_descriptions(text) @text ||= '' @text += text end |
#register(cls, name) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/liedetector/suite.rb', line 37 def register(cls, name) @ordered ||= [] @registry ||= {} @ordered << cls @registry[name] = cls if name cls.description(@text || '') @text = '' end |
#request(name, method, path, &blk) ⇒ Object
Sugar to not define classes in the doc
74 75 76 77 78 79 80 |
# File 'lib/liedetector/suite.rb', line 74 def request(name, method, path, &blk) req = LieDetector::Request.new self req.method method req.path path req.instance_exec &blk register(req, name) end |
#run ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/liedetector/suite.rb', line 57 def run markdown = Redcarpet::Markdown.new(LieDetector::MarkdownRunner.new(self), fenced_code_blocks: true) markdown.render(File.new(@filepath).read) @ordered.each do |test| puts test.describe test.call puts 'passed' puts end end |
#session ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/liedetector/suite.rb', line 23 def session @session ||= begin session = HTTPClient.new session.("cookie.dat") # session.debug_dev = STDOUT session end end |
#store_data ⇒ Object
51 52 53 |
# File 'lib/liedetector/suite.rb', line 51 def store_data @store end |
#store_key(key, data) ⇒ Object
46 47 48 49 |
# File 'lib/liedetector/suite.rb', line 46 def store_key(key, data) @store ||= {} @store[key] = data end |