hobby-test 0.0.3 → 0.0.4
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 +4 -4
- data/hobby-test.gemspec +1 -1
- data/lib/hobby/test.rb +3 -1
- data/lib/hobby/test/env.rb +17 -0
- data/lib/hobby/test/exchange.rb +7 -5
- data/lib/hobby/test/exchange/assert.rb +9 -10
- data/lib/hobby/test/exchange/request.rb +25 -5
- data/lib/hobby/test/exchange/response.rb +16 -0
- data/lib/hobby/test/template.rb +15 -0
- data/readme.adoc +8 -0
- data/spec/apps/main.rb +7 -0
- data/spec/yml/passing/access_last_response.yml +11 -0
- data/spec/yml/passing/referring_to_json_body.yml +9 -0
- metadata +8 -6
- data/spec/http/basic.yml +0 -14
- data/spec/http/event.yml +0 -11
- data/spec/http/reverse.yml +0 -24
- data/useful_links +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61cd3a457c60be67607b061852aef03d00d6fcd7
|
4
|
+
data.tar.gz: e9fae2b5ebbc5a727032b715a784323ec3e817c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 256a68e3c67766a20b0719e2a23a39d966938bf460f3619e3251755a208d867ba0f1f566f9bb94e04ca614a96b5e42d078757c939357fe929417e3c893cb2494
|
7
|
+
data.tar.gz: 7e0eacc4fb1cbf4a702ab5b0615a44f97e5df84115290ec3f3cab7bf9cf718d165b73930893b370246ec4a6b84dda6cc85c9f38c420855b135a36ea5b9446b84
|
data/hobby-test.gemspec
CHANGED
data/lib/hobby/test.rb
CHANGED
@@ -8,6 +8,7 @@ require 'ostruct'
|
|
8
8
|
|
9
9
|
require 'hobby/test/exchange'
|
10
10
|
require 'hobby/test/report'
|
11
|
+
require 'hobby/test/env'
|
11
12
|
|
12
13
|
module Hobby
|
13
14
|
class Test
|
@@ -29,8 +30,9 @@ module Hobby
|
|
29
30
|
else
|
30
31
|
Excon.new 'unix:///', socket: address
|
31
32
|
end
|
33
|
+
env = Env.new connection
|
32
34
|
|
33
|
-
Report.new @exchanges.map &[
|
35
|
+
Report.new @exchanges.map &[env]
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
data/lib/hobby/test/exchange.rb
CHANGED
@@ -9,8 +9,8 @@ module Hobby
|
|
9
9
|
end
|
10
10
|
attr_reader :request, :asserts
|
11
11
|
|
12
|
-
def []
|
13
|
-
dup.
|
12
|
+
def [] env
|
13
|
+
dup.perform_in env
|
14
14
|
end
|
15
15
|
|
16
16
|
def ok?
|
@@ -18,9 +18,9 @@ module Hobby
|
|
18
18
|
end
|
19
19
|
|
20
20
|
protected
|
21
|
-
def
|
22
|
-
|
23
|
-
@asserts = asserts.map &[
|
21
|
+
def perform_in env
|
22
|
+
request.perform_in env
|
23
|
+
@asserts = asserts.map &[env.last_response]
|
24
24
|
self
|
25
25
|
end
|
26
26
|
end
|
@@ -28,4 +28,6 @@ module Hobby
|
|
28
28
|
end
|
29
29
|
|
30
30
|
require 'hobby/test/exchange/request'
|
31
|
+
require 'hobby/test/exchange/response'
|
31
32
|
require 'hobby/test/exchange/assert'
|
33
|
+
require 'hobby/test/template'
|
@@ -26,33 +26,34 @@ class Hobby::Test::Exchange
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
def assert response
|
30
|
+
@actual_value = response.public_send key
|
31
|
+
compare
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
29
35
|
attr_reader :actual_value, :specified_value, :chain, :key
|
30
36
|
|
31
37
|
class Status
|
32
38
|
include Assert
|
33
39
|
|
34
|
-
def
|
35
|
-
@actual_value = response.public_send key
|
40
|
+
def compare
|
36
41
|
@ok = actual_value == specified_value
|
37
|
-
self
|
38
42
|
end
|
39
43
|
end
|
40
44
|
|
41
45
|
class Headers
|
42
46
|
include Assert
|
43
47
|
|
44
|
-
def
|
45
|
-
@actual_value = response.public_send key
|
48
|
+
def compare
|
46
49
|
@ok = chain.empty? ? actual_value == specified_value : compare_chain
|
47
|
-
self
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
51
53
|
class Body
|
52
54
|
include Assert
|
53
55
|
|
54
|
-
def
|
55
|
-
@actual_value = response.public_send key
|
56
|
+
def compare
|
56
57
|
@actual_value = begin
|
57
58
|
JSON.parse actual_value
|
58
59
|
rescue JSON::ParserError
|
@@ -64,8 +65,6 @@ class Hobby::Test::Exchange
|
|
64
65
|
else
|
65
66
|
compare_chain
|
66
67
|
end
|
67
|
-
|
68
|
-
self
|
69
68
|
end
|
70
69
|
end
|
71
70
|
end
|
@@ -1,16 +1,36 @@
|
|
1
1
|
class Hobby::Test::Exchange
|
2
2
|
class Request < OpenStruct
|
3
3
|
VERBS = %w[delete get head options patch post put]
|
4
|
-
def initialize
|
5
|
-
@verb =
|
6
|
-
|
4
|
+
def initialize pair
|
5
|
+
@verb, hash = pair
|
6
|
+
|
7
|
+
template_fields, regular_fields = hash.partition do |key, _|
|
8
|
+
key.start_with? 'template.'
|
9
|
+
end
|
10
|
+
@templates = template_fields.map &Hobby::Test::Template
|
11
|
+
|
12
|
+
super regular_fields.to_h
|
7
13
|
end
|
8
14
|
attr_reader :verb
|
9
15
|
|
10
|
-
def
|
16
|
+
def regular_fields body_serializer:
|
11
17
|
hash = to_h
|
12
|
-
|
18
|
+
|
19
|
+
if body && body_serializer
|
20
|
+
hash[:body] = body_serializer.dump body
|
21
|
+
end
|
22
|
+
|
13
23
|
hash
|
14
24
|
end
|
25
|
+
|
26
|
+
def perform_in env
|
27
|
+
body_serializer = JSON if body.is_a? Hash
|
28
|
+
params = regular_fields(body_serializer: body_serializer)
|
29
|
+
.merge @templates.map(&[env]).to_h
|
30
|
+
|
31
|
+
excon_response = env.connection.public_send verb, **params
|
32
|
+
response = Response.new excon_response, body_serializer: body_serializer
|
33
|
+
env.responses << response
|
34
|
+
end
|
15
35
|
end
|
16
36
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Hobby::Test::Exchange
|
2
|
+
class Response
|
3
|
+
def initialize excon_response, body_serializer:
|
4
|
+
@excon_response, @body_serializer = excon_response, body_serializer
|
5
|
+
end
|
6
|
+
attr_reader :body_serializer
|
7
|
+
|
8
|
+
def [] key
|
9
|
+
@serialized ||= JSON.load body
|
10
|
+
@serialized[key]
|
11
|
+
end
|
12
|
+
|
13
|
+
extend Forwardable
|
14
|
+
delegate [:status, :headers, :body] => :@excon_response
|
15
|
+
end
|
16
|
+
end
|
data/readme.adoc
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
= hobby-test
|
2
|
+
|
3
|
+
:uri-for-rack-test: https://github.com/brynary/rack-test
|
4
|
+
|
5
|
+
A way to test HTTP exchanges via YAML specifications. In contrast to {uri-for-rack-test}[rack-test], it works via real HTTP requests, which makes it applicable to HTTP services written in any language, not only Ruby.
|
6
|
+
|
7
|
+
== How it works
|
8
|
+
I'll write it later. For now, I just want to see how Github renders it.
|
data/spec/apps/main.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hobby-test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anatoly Chernow
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|
@@ -49,28 +49,30 @@ files:
|
|
49
49
|
- debug.rb
|
50
50
|
- hobby-test.gemspec
|
51
51
|
- lib/hobby/test.rb
|
52
|
+
- lib/hobby/test/env.rb
|
52
53
|
- lib/hobby/test/exchange.rb
|
53
54
|
- lib/hobby/test/exchange/assert.rb
|
54
55
|
- lib/hobby/test/exchange/request.rb
|
56
|
+
- lib/hobby/test/exchange/response.rb
|
55
57
|
- lib/hobby/test/report.rb
|
58
|
+
- lib/hobby/test/template.rb
|
59
|
+
- readme.adoc
|
56
60
|
- spec/apps/main.rb
|
57
61
|
- spec/auto_spec.rb
|
58
62
|
- spec/helper.rb
|
59
|
-
- spec/http/basic.yml
|
60
|
-
- spec/http/event.yml
|
61
|
-
- spec/http/reverse.yml
|
62
63
|
- spec/run_mutant.rb
|
63
64
|
- spec/setup/mutant.rb
|
64
65
|
- spec/setup/power_assert.rb
|
65
66
|
- spec/tcp_spec.rb
|
66
67
|
- spec/yml/failing/0.yml
|
67
68
|
- spec/yml/passing/0.yml
|
69
|
+
- spec/yml/passing/access_last_response.yml
|
68
70
|
- spec/yml/passing/chain_assertions.yml
|
69
71
|
- spec/yml/passing/counter.yml
|
70
72
|
- spec/yml/passing/echo.yml
|
71
73
|
- spec/yml/passing/headers.yml
|
72
74
|
- spec/yml/passing/query.yml
|
73
|
-
-
|
75
|
+
- spec/yml/passing/referring_to_json_body.yml
|
74
76
|
homepage:
|
75
77
|
licenses: []
|
76
78
|
metadata: {}
|
data/spec/http/basic.yml
DELETED
data/spec/http/event.yml
DELETED
data/spec/http/reverse.yml
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
- default:
|
2
|
-
verb: post
|
3
|
-
path: /event
|
4
|
-
format: json
|
5
|
-
|
6
|
-
- request:
|
7
|
-
body:
|
8
|
-
text: text
|
9
|
-
|
10
|
-
response:
|
11
|
-
status: 201
|
12
|
-
body:
|
13
|
-
name: ReverseApp
|
14
|
-
text: txet
|
15
|
-
|
16
|
-
- request:
|
17
|
-
body:
|
18
|
-
text: reverse
|
19
|
-
|
20
|
-
response:
|
21
|
-
status: 201
|
22
|
-
body:
|
23
|
-
name: ReverseApp
|
24
|
-
text: something entirely else
|
data/useful_links
DELETED