liedetector 0.2.2 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa03058163399affa0461be6673a9d3e5a12c890
4
- data.tar.gz: 1c53a79fe362a04d08772d26bc805877c9b2e098
3
+ metadata.gz: d84111e812b82ef363c85d668e92616882f427de
4
+ data.tar.gz: 85b6313e88873a8d3d6c612b3ee196129298337a
5
5
  SHA512:
6
- metadata.gz: 20a421fc36dbd658fc3d6dbed033d94e32c3a8e5fd8f1ae71bab8e42304636698037baec78522f5c8dcfc6bcb78bd548eb1b26443f5f9b8953361cc8466018af
7
- data.tar.gz: 5d19b4011700ddd9b7482a5b1164929d64846d2c666e8cef031f92203039cd5eadd76da67b88f1de953d83f5d718e486a3b1ae95f9657bca6d3d757bc2e9f17a
6
+ metadata.gz: befffc92abd9982fd475aadfdfafa9820d165edcb1685c802b437a01670a8e1be840a168e1b1cecb26e103186d5f7eeb03eba6fa5838026f2ef19889996a70e9
7
+ data.tar.gz: c0a41b51b26680ec9fad5a368e3b45728fa2a5dc6d4d065eff3950faf2cdd40d29fe6031b808bafb3a4a893185f8472928cdbc809634cf92f21ca89efad01987
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ LieDetector
2
+ ===========
3
+
4
+ I created this gem to keep API description and actual API in sync. You write markdown document
5
+ with data structures and request descriptions, and then you can check it against real server
6
+ to check that description is really describe this server API.
7
+
8
+ All requests executed one by one, and if any of them fail we stop checking.
9
+
10
+ So, take a look at some example - current document describe a bit of GitHub API.
11
+
12
+ GitHub API Check
13
+ ----------------
14
+
15
+ As you know github has public API. API you can call without authentification.
16
+ Set API host:
17
+
18
+ self.http_defaults = {host: 'api.github.com', scheme: 'https', port: 443}
19
+
20
+ With Trafaret library we can define data types to check API results:
21
+
22
+ Repo = T.construct({
23
+ id: :integer,
24
+ name: :string,
25
+ full_name: :string,
26
+ # ... hundred of other fields, tired to define them
27
+ owner: {url: :uri}
28
+ })
29
+
30
+ So now we can get info about liedetector repo, store it, and then use it for next queries:
31
+
32
+ request :repo_info, :get, '/repos/Deepwalker/liedetector' do
33
+ status 200
34
+ await Repo
35
+ store :repo # we store API call result for later
36
+ end
37
+
38
+ Now we have repo info, and URI for it owner. Lets check this URI:
39
+
40
+ request :repo_owner, :get, proc { URI.parse(store[:repo][:owner][:url]).path } do
41
+ status 200
42
+ await :any
43
+ end
44
+
45
+ You can put proc {} in place of method, path, status, data, query and headers request args. As you see
46
+ request get name, method and path, and then with block you fill other parameters.
@@ -1,21 +1,23 @@
1
1
  module LieDetector
2
2
  class Suite
3
- HEADERS_DEFAULTS = {'Accept' => 'application/json'}
4
- HTTP_DEFAULTS = {host: '127.0.0.1', port: 3000}
5
-
6
- attr_accessor :http_defaults
7
-
8
- def headers_defaults
9
- HEADERS_DEFAULTS
10
- end
3
+ attr_accessor :http_defaults, :headers_defaults
11
4
 
12
5
  def initialize(filepath)
13
6
  @filepath = filepath
7
+ self.headers_defaults = {'Accept' => 'application/json'}
8
+ self.http_defaults = {host: '127.0.0.1', port: 3000}
14
9
  end
15
10
 
16
11
  def build_uri(path, query: nil, fragment: nil)
17
12
  query = URI.encode_www_form(query) if query.is_a? Hash
18
- URI::HTTP.build(HTTP_DEFAULTS.merge(path: path, query: query, fragment: fragment)).to_s
13
+ scheme = http_defaults[:scheme] || 'http'
14
+ if scheme == 'http'
15
+ URI::HTTP
16
+ elsif scheme == 'https'
17
+ URI::HTTPS
18
+ else
19
+ raise 'Bad configuration'
20
+ end.build(http_defaults.merge(path: path, query: query, fragment: fragment)).to_s
19
21
  end
20
22
 
21
23
  def session
@@ -1,3 +1,3 @@
1
1
  module LieDetector
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.5"
3
3
  end
@@ -3,7 +3,7 @@ require 'liedetector'
3
3
 
4
4
  describe LieDetector::Suite do
5
5
  it 'should do the task' do
6
- suite = LieDetector::Suite.new('sample.md')
6
+ suite = LieDetector::Suite.new('README.md')
7
7
  suite.run
8
8
  end
9
- end
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liedetector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikhail Krivushin
@@ -134,6 +134,7 @@ extra_rdoc_files: []
134
134
  files:
135
135
  - Gemfile
136
136
  - Gemfile.lock
137
+ - README.md
137
138
  - Rakefile
138
139
  - bin/liedetector
139
140
  - lib/liedetector.rb