oncall 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0778276dcc11e6239223743661c8287e0c7f7efccacb596b9c95012d71705578'
4
- data.tar.gz: 2cccbb6c6d524537e3cdcc4ac9628587982c796f0e41f257bd6fae2a1b9d1757
3
+ metadata.gz: 4e1468fdbc7031c7e94d7fb008215ab5155946abd2cb345b9d686dae3b50346f
4
+ data.tar.gz: 9e81904f2d1e772a1ea31a6640fd865518ad8f330f9ed947aa628d40ba017735
5
5
  SHA512:
6
- metadata.gz: 1e1c60682fea1c01311ad356a15e68543e963ee59bf82e01a6efe04e4908436a73b9e45d64e1624c60264781d70358623478ac62315b7c5ae13c98b1c87a75b9
7
- data.tar.gz: b9f6dbecda4cd65af491aceec80f22029dff7dceeebd18aa460105fcdc33426e9771ad7f3803c99df127a55699ac3800ca75a88c3faf9f0c04c6825714243a9b
6
+ metadata.gz: 3645aa70fe65da2242bae0e6942a85fb9c5352d569a93dab07301acdb3592a966fe5cc9452d92c014fb7ed0d61f5094c0453b834f2ae10f8da5a7206629c6375
7
+ data.tar.gz: 6552d1020124e5f17b244ad9cf46003bd2b73c418646bf8bcc0d5e45707015fd8e7332064828933c7a5ac5c9f1b88dc453a2e2b4f41fac6ad53e405e832707dd
data/README.md CHANGED
@@ -1 +1,3 @@
1
- # Oncall
1
+ # 🤙 Oncall
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/oncall.svg)](https://badge.fury.io/rb/oncall)
data/bin/oncall CHANGED
@@ -1,3 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
+
2
3
  require File.expand_path(File.dirname(__FILE__) + '/../lib/oncall')
3
4
  Oncall::CLI.invoke
@@ -0,0 +1,20 @@
1
+ module Oncall
2
+ class BodyTest
3
+ def initialize(body, description)
4
+ @body = body
5
+ @description = description
6
+ @result = false
7
+ end
8
+
9
+ def run(&block)
10
+ instance_eval(&block)
11
+ @result
12
+ end
13
+
14
+ private
15
+
16
+ def matches(schema)
17
+ @result = JSON::Validator.validate(schema, @body)
18
+ end
19
+ end
20
+ end
data/lib/oncall/cli.rb CHANGED
@@ -1,55 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'net/http'
4
- require 'yaml'
5
- require 'optparse'
6
- require 'json-schema'
7
-
8
- class Endpoint
9
- def initialize(route)
10
- @route = route
11
- @config = {
12
- 'develop' => { 'domain' => 'localhost', 'port' => 4567 }
13
- }
14
- end
15
-
16
- def parse(filename)
17
- instance_eval File.read(filename)
18
- end
19
-
20
- def Endpoint.run(filename)
21
- Endpoint.new('').parse(filename)
22
- end
23
-
24
- def Endpoint.define(route, &block)
25
- new(route).instance_eval(&block)
26
- end
27
-
28
- private
29
-
30
- def get(description, &block)
31
- instance_eval(&block)
32
- end
33
-
34
- def validate(schema)
35
- response = Net::HTTP.get_response(@config['develop']['domain'], @route, @config['develop']['port'])
36
- puts JSON::Validator.validate(schema, response.body)
37
- end
38
- end
39
-
40
3
  module Oncall
41
4
  module CLI
42
5
  extend self
43
6
 
44
- USAGE = <<-EOF
45
- Usage: oncall
7
+ USAGE = <<~EOF
8
+ Usage: oncall
46
9
 
47
- Options:
48
- --help Display this help message
10
+ Options:
11
+ --help Display this help message
49
12
  EOF
50
13
 
51
- PATTERN = '**{,/*/**}/*_oncall.rb'
52
-
53
14
  def invoke
54
15
  options = parse_options
55
16
 
@@ -58,7 +19,9 @@ Options:
58
19
  exit 0
59
20
  end
60
21
 
61
- run_tests
22
+ runner = Oncall::Runner.new
23
+ status = runner.run.to_i
24
+ exit(status)
62
25
  end
63
26
 
64
27
  private
@@ -75,24 +38,5 @@ Options:
75
38
  def print_usage
76
39
  puts USAGE
77
40
  end
78
-
79
- def run_tests
80
- begin
81
- config = YAML.load_file('oncall.yml')
82
- rescue
83
- puts 'Cannot load oncall.yml'
84
- exit 1
85
- end
86
-
87
- files = Dir.glob(PATTERN)
88
-
89
- process_files(files)
90
- end
91
-
92
- def process_files(files)
93
- files.each do |file|
94
- Endpoint.run(file)
95
- end
96
- end
97
41
  end
98
42
  end
@@ -0,0 +1,52 @@
1
+ module Oncall
2
+ class Request
3
+ def initialize(config, endpoint)
4
+ @config = config
5
+ @endpoint = endpoint
6
+ @headers = {}
7
+ @expectations = []
8
+ @http = nil
9
+ @response = nil
10
+ @request = nil
11
+ end
12
+
13
+ def bootstrap
14
+ @http = Net::HTTP.new(@config['domain'], @config['port'])
15
+
16
+ @request = Net::HTTP::Get.new(@endpoint)
17
+
18
+ @request['User-Agent'] = 'Oncall'
19
+
20
+ @headers.each do |key, value|
21
+ request[key] = value
22
+ end
23
+
24
+ end
25
+
26
+ def run(&block)
27
+ @response = @http.request(@request)
28
+
29
+ instance_eval(&block)
30
+ end
31
+
32
+ private
33
+
34
+ def header(header)
35
+ @headers.merge!(header)
36
+ end
37
+
38
+ def body(description, &block)
39
+ result = Oncall::BodyTest.new(@response.body, description).run(&block)
40
+ puts "Endpoint: #{@endpoint} -----"
41
+ puts " Body: #{description}: #{result}"
42
+ end
43
+
44
+ def status(description, &block)
45
+ @expectations.push(description)
46
+ end
47
+
48
+ def profiler(description, &block)
49
+ @expectations.push(description)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Oncall
4
+ class Runner
5
+ DEFAULT_PATTERN = '**{,/*/**}/*_oncall.rb'
6
+
7
+ def initialize
8
+ @config = {}
9
+ @pattern = DEFAULT_PATTERN
10
+ @test_wrapper = Oncall::TestWrapper.new
11
+ end
12
+
13
+ def run
14
+ begin
15
+ config = YAML.load_file('oncall.yml')
16
+ merge_config(config)
17
+ rescue StandardError
18
+ puts 'Cannot load oncall.yml'
19
+ exit 1
20
+ end
21
+
22
+ files = Dir.glob(@pattern)
23
+
24
+ process_files(files)
25
+ 0
26
+ end
27
+
28
+ def process_files(files)
29
+ @test_wrapper.set_config(@config)
30
+
31
+ files.each do |file|
32
+ @test_wrapper.evaluate(file)
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def merge_config(config)
39
+ @config = config
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,24 @@
1
+ module Oncall
2
+ class TestCase
3
+
4
+ def initialize(config)
5
+ @config = config
6
+ end
7
+
8
+ def run(file)
9
+ instance_eval File.read(file)
10
+ end
11
+
12
+ def get(endpoint, &block)
13
+ test = Oncall::Request.new(@config, endpoint)
14
+ test.bootstrap
15
+ test.run(&block)
16
+ end
17
+
18
+ def post(endpoint, &block)
19
+ test = Oncall::Request.new(@config, endpoint)
20
+ test.bootstrap(&block)
21
+ test.run
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ module Oncall
2
+ class TestWrapper
3
+ def initialize
4
+ @config = nil
5
+ end
6
+
7
+ def evaluate(file)
8
+ test_case = Oncall::TestCase.new(@config)
9
+ test_case.run(file)
10
+ end
11
+
12
+ def set_config(config)
13
+ @config = config['develop']
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Oncall
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
data/lib/oncall.rb CHANGED
@@ -1,7 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'net/http'
4
+ require 'yaml'
5
+ require 'optparse'
6
+ require 'json-schema'
7
+
3
8
  # Oncall
4
9
  module Oncall
5
- require File.expand_path(File.join(File.dirname(__FILE__), 'oncall', 'version'))
10
+ require File.expand_path(File.join(File.dirname(__FILE__), 'oncall', 'body_test'))
6
11
  require File.expand_path(File.join(File.dirname(__FILE__), 'oncall', 'cli'))
12
+ require File.expand_path(File.join(File.dirname(__FILE__), 'oncall', 'request'))
13
+ require File.expand_path(File.join(File.dirname(__FILE__), 'oncall', 'test_case'))
14
+ require File.expand_path(File.join(File.dirname(__FILE__), 'oncall', 'test_wrapper'))
15
+ require File.expand_path(File.join(File.dirname(__FILE__), 'oncall', 'version'))
16
+ require File.expand_path(File.join(File.dirname(__FILE__), 'oncall', 'runner'))
7
17
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oncall
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koen Woortman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-23 00:00:00.000000000 Z
11
+ date: 2019-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: json
14
+ name: json-schema
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.2.0
19
+ version: 2.8.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.2.0
26
+ version: 2.8.1
27
27
  - !ruby/object:Gem::Dependency
28
- name: json-schema
28
+ name: json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 2.8.1
34
- type: :runtime
33
+ version: 2.2.0
34
+ type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 2.8.1
40
+ version: 2.2.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: sinatra
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -62,8 +62,12 @@ files:
62
62
  - README.md
63
63
  - bin/oncall
64
64
  - lib/oncall.rb
65
+ - lib/oncall/body_test.rb
65
66
  - lib/oncall/cli.rb
66
- - lib/oncall/oncall.rb
67
+ - lib/oncall/request.rb
68
+ - lib/oncall/runner.rb
69
+ - lib/oncall/test_case.rb
70
+ - lib/oncall/test_wrapper.rb
67
71
  - lib/oncall/version.rb
68
72
  homepage:
69
73
  licenses:
@@ -87,5 +91,5 @@ requirements: []
87
91
  rubygems_version: 3.0.3
88
92
  signing_key:
89
93
  specification_version: 4
90
- summary: oncall-0.1.0
94
+ summary: BDD for JSON API's
91
95
  test_files: []
data/lib/oncall/oncall.rb DELETED
File without changes