barthes 0.0.13 → 0.0.14
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.
- data/barthes.gemspec +2 -0
- data/example/q3_env.json +4 -0
- data/example/q3_spec.json +66 -0
- data/lib/barthes/action.rb +5 -2
- data/lib/barthes/cli.rb +1 -1
- data/lib/barthes/client/httparty.rb +56 -0
- data/lib/barthes/reporter/default.rb +32 -7
- data/lib/barthes/runner.rb +8 -10
- data/lib/barthes/version.rb +1 -1
- metadata +37 -2
data/barthes.gemspec
CHANGED
data/example/q3_env.json
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
["feature", "Q3", [
|
2
|
+
["scenario", "CreateQueue", [
|
3
|
+
["action", "create queue with CreateQueue API", {
|
4
|
+
"params": {
|
5
|
+
"Action": "CreateQueue",
|
6
|
+
"QueueName": "takeuchitest"
|
7
|
+
},
|
8
|
+
"expectations": [
|
9
|
+
{
|
10
|
+
"type": "response_code",
|
11
|
+
"value": 200
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"type": "xpath_value",
|
15
|
+
"xpath": "//CreateQueueResponse/CreateQueueResult/QueueUrl",
|
16
|
+
"value": "http://q3-global.herokuapp.com/*/takeuchitest"
|
17
|
+
}
|
18
|
+
]
|
19
|
+
}],
|
20
|
+
["action", "check if that queue is created with ListQueues API", {
|
21
|
+
"params": {
|
22
|
+
"Action": "ListQueues"
|
23
|
+
},
|
24
|
+
"expectations": [
|
25
|
+
{
|
26
|
+
"type": "response_code",
|
27
|
+
"value": 200
|
28
|
+
},
|
29
|
+
{
|
30
|
+
"type": "xpath_value",
|
31
|
+
"xpath": "ListQueuesResponse/ListQueuesResult/QueueUrl[1]",
|
32
|
+
"value": "http://q3-global.herokuapp.com/*/takeuchitest"
|
33
|
+
}
|
34
|
+
]
|
35
|
+
}],
|
36
|
+
["action", "send message to that queue with SendMessage API", {
|
37
|
+
"params": {
|
38
|
+
"Action": "SendMessage",
|
39
|
+
"MessageBody": "hello barthes"
|
40
|
+
},
|
41
|
+
"env": {
|
42
|
+
"path": "/*/takeuchitest"
|
43
|
+
},
|
44
|
+
"expectations": [
|
45
|
+
{
|
46
|
+
"type": "response_code",
|
47
|
+
"value": 200
|
48
|
+
}
|
49
|
+
]
|
50
|
+
}],
|
51
|
+
["action", "receive message from that queue with ReceiveMessage API", {
|
52
|
+
"params": {
|
53
|
+
"Action": "ReceiveMessage"
|
54
|
+
},
|
55
|
+
"env": {
|
56
|
+
"path": "/*/takeuchitest"
|
57
|
+
},
|
58
|
+
"expectations": [
|
59
|
+
{
|
60
|
+
"type": "response_code",
|
61
|
+
"value": 200
|
62
|
+
}
|
63
|
+
]
|
64
|
+
}]
|
65
|
+
]]
|
66
|
+
]]
|
data/lib/barthes/action.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'barthes/cache'
|
2
|
+
require 'barthes/client/httparty'
|
3
|
+
require 'chronic'
|
2
4
|
|
3
5
|
module Barthes
|
4
6
|
class Action
|
5
7
|
def initialize(env)
|
6
8
|
@env = env.dup
|
7
|
-
client_class =
|
9
|
+
client_class = @env['client_class'] ? @env['client_class'].constantize : Barthes::Client::HTTParty
|
8
10
|
@client = client_class.new(env)
|
9
11
|
end
|
10
12
|
|
@@ -73,7 +75,8 @@ module Barthes
|
|
73
75
|
new_params = {}
|
74
76
|
params.each do |k, v|
|
75
77
|
if v.class == String
|
76
|
-
new_v = v.gsub(/\$\{(.+?)\}/) {
|
78
|
+
new_v = v.gsub(/\$\{time:(.+?):(.+?)\}/) { Chronic.parse($1).strftime($2) }
|
79
|
+
new_v = new_v.gsub(/\$\{(.+?)\}/) { @env[$1] }
|
77
80
|
new_v = new_v.gsub(/\@\{(.+?)\}/) { Barthes::Cache[$1] }
|
78
81
|
else
|
79
82
|
new_v = v
|
data/lib/barthes/cli.rb
CHANGED
@@ -11,7 +11,7 @@ module Barthes
|
|
11
11
|
on 'e', 'env', 'environment file paths', argument: :optional, as: Array
|
12
12
|
on 'q', 'quiet', 'not show test details', argument: :optional, as: :count
|
13
13
|
on 'f', 'from', 'test number to start from', argument: :optional, as: Integer, default: 1
|
14
|
-
on 't', 'to', 'test number to stop to', argument: :optional
|
14
|
+
on 't', 'to', 'test number to stop to', argument: :optional, as: Integer
|
15
15
|
on 'l', 'load', 'An optional password', argument: :optional
|
16
16
|
on 'd', 'dryrun', 'not run test but show just structure', argument: :optional, as: :count
|
17
17
|
on 'c', 'cache', 'cache path', argument: :optional, default: './barthes-cache.json'
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
module Barthes
|
5
|
+
module Client
|
6
|
+
class HTTParty
|
7
|
+
include ::HTTParty
|
8
|
+
|
9
|
+
def initialize(env)
|
10
|
+
@env = env
|
11
|
+
end
|
12
|
+
|
13
|
+
def action(params)
|
14
|
+
url = @env['path'] ? @env['endpoint'] + @env['path'] : @env['endpoint']
|
15
|
+
self.class.post(url, query: params)
|
16
|
+
end
|
17
|
+
|
18
|
+
def compare(response, expectation)
|
19
|
+
result = nil
|
20
|
+
case expectation['type']
|
21
|
+
when 'response_code'
|
22
|
+
result = response.code == expectation['value']
|
23
|
+
{'result' => result, 'returned' => response.code, 'expected' => expectation['value']}
|
24
|
+
when 'xpath_value'
|
25
|
+
text = xpath(response, expectation['xpath']).text
|
26
|
+
if expectation['method'].nil? || expectation['method'] == 'eq'
|
27
|
+
result = (text == expectation['value'])
|
28
|
+
elsif expectation['method'] == 'regexp'
|
29
|
+
result = !(text.match Regexp.new(expectation['value'])).nil?
|
30
|
+
elsif expectation['method'] == 'ne'
|
31
|
+
result = (text != expectation['value'])
|
32
|
+
end
|
33
|
+
{'result' => result, 'returned' => text, 'expected' => expectation['value']}
|
34
|
+
when 'xpath_size'
|
35
|
+
size = xpath(response, expectation['xpath']).size
|
36
|
+
if expectation['method'].nil? || expectation['method'] == 'eq'
|
37
|
+
result = (size == expectation['value'])
|
38
|
+
elsif expectation['method'] == 'gt'
|
39
|
+
result = (size > expectation['value'])
|
40
|
+
end
|
41
|
+
{'result' => result, 'returned' => size, 'expected' => expectation['value']}
|
42
|
+
else
|
43
|
+
{'result' => true}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def extract(config, response)
|
48
|
+
end
|
49
|
+
|
50
|
+
def xpath(response, xpath)
|
51
|
+
doc = Nokogiri::XML response.body.gsub(/xmlns="(.+?)"/, '')
|
52
|
+
doc.xpath(xpath)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -9,19 +9,19 @@ module Barthes
|
|
9
9
|
@opts = opts
|
10
10
|
end
|
11
11
|
|
12
|
-
def before_feature(
|
13
|
-
puts
|
12
|
+
def before_feature(name)
|
13
|
+
puts name
|
14
14
|
end
|
15
15
|
|
16
|
-
def before_scenario(
|
17
|
-
puts ("\t" * scenarios.size) +
|
16
|
+
def before_scenario(name, scenario, scenarios)
|
17
|
+
puts ("\t" * scenarios.size) + name
|
18
18
|
end
|
19
19
|
|
20
|
-
def before_action(
|
21
|
-
puts ("\t" * scenarios.size) + "
|
20
|
+
def before_action(name, action, scenarios)
|
21
|
+
puts ("\t" * scenarios.size) + "##{action['number']} #{name}"
|
22
22
|
end
|
23
23
|
|
24
|
-
def after_action(
|
24
|
+
def after_action(name, action, scenarios)
|
25
25
|
if Barthes::Config[:quiet] == 0 && Barthes::Config[:dryrun] == 0
|
26
26
|
puts indent scenarios.size + 1, "request:"
|
27
27
|
puts indent scenarios.size + 2, JSON.pretty_generate(action['request'])
|
@@ -59,6 +59,31 @@ module Barthes
|
|
59
59
|
("\t" * num) + line
|
60
60
|
end.join("\n")
|
61
61
|
end
|
62
|
+
|
63
|
+
def after_run(features)
|
64
|
+
@count = Hash.new(0)
|
65
|
+
walk_json(features)
|
66
|
+
puts '-' * 80
|
67
|
+
puts [
|
68
|
+
"all: #{@count['all'].to_s }",
|
69
|
+
"success: #{@count['success'] > 0 ? green { @count['success'].to_s } : @count['success'].to_s }",
|
70
|
+
"failure: #{@count['failure'] > 0 ? red { @count['failure'].to_s } : @count['failure'].to_s }",
|
71
|
+
"error: #{@count['error'] > 0 ? red { @count['error'].to_s } : @count['error'].to_s }",
|
72
|
+
"skipped: #{@count['skipped'].to_s }"
|
73
|
+
].join(", ")
|
74
|
+
end
|
75
|
+
|
76
|
+
def walk_json(obj)
|
77
|
+
case obj.first
|
78
|
+
when 'feature', 'scenario'
|
79
|
+
walk_json(obj.last)
|
80
|
+
when 'action'
|
81
|
+
@count['all'] += 1
|
82
|
+
@count[obj.last['status']] += 1
|
83
|
+
else
|
84
|
+
obj.each {|obj2| walk_json(obj2) }
|
85
|
+
end
|
86
|
+
end
|
62
87
|
end
|
63
88
|
end
|
64
89
|
end
|
data/lib/barthes/runner.rb
CHANGED
@@ -10,7 +10,8 @@ module Barthes
|
|
10
10
|
Barthes::Config.update(options)
|
11
11
|
load_cache
|
12
12
|
load_libraries
|
13
|
-
|
13
|
+
@env = {}
|
14
|
+
load_envs(options[:env]) if options[:env]
|
14
15
|
@reporter = Reporter.new
|
15
16
|
end
|
16
17
|
|
@@ -26,7 +27,6 @@ module Barthes
|
|
26
27
|
end
|
27
28
|
|
28
29
|
def load_envs(env_paths)
|
29
|
-
@env = {}
|
30
30
|
env_paths.each do |path|
|
31
31
|
@env.update JSON.parse File.read(path)
|
32
32
|
end
|
@@ -55,8 +55,7 @@ module Barthes
|
|
55
55
|
@num = 1
|
56
56
|
files.each do |file|
|
57
57
|
json = JSON.parse File.read(file)
|
58
|
-
@reporter.report(:feature,
|
59
|
-
@num += 1
|
58
|
+
@reporter.report(:feature, json[1]) do
|
60
59
|
walk_json(json.last, [file])
|
61
60
|
results << json
|
62
61
|
json
|
@@ -71,7 +70,7 @@ module Barthes
|
|
71
70
|
|
72
71
|
def in_range?
|
73
72
|
flag = @num >= Barthes::Config[:from]
|
74
|
-
flag = flag && (@num
|
73
|
+
flag = flag && (@num <= Barthes::Config[:to]) if Barthes::Config[:to]
|
75
74
|
flag
|
76
75
|
end
|
77
76
|
|
@@ -80,11 +79,12 @@ module Barthes
|
|
80
79
|
case json.first
|
81
80
|
when 'scenario'
|
82
81
|
handle_scenario(json, scenarios)
|
83
|
-
@num += 1
|
84
82
|
scenarios.push(json.first)
|
85
83
|
walk_json(json.last, scenarios)
|
86
84
|
scenarios.pop
|
87
85
|
when 'action'
|
86
|
+
json.last['status'] = 'skipped' if Barthes::Config[:dryrun] > 0
|
87
|
+
json.last['number'] = @num
|
88
88
|
handle_action(json, scenarios) if in_range?
|
89
89
|
@num += 1
|
90
90
|
else
|
@@ -97,7 +97,7 @@ module Barthes
|
|
97
97
|
|
98
98
|
def handle_scenario(scenario, scenarios)
|
99
99
|
return if @failed
|
100
|
-
@reporter.report(:scenario,
|
100
|
+
@reporter.report(:scenario, scenario[1], scenario.last, scenarios) do
|
101
101
|
scenario.last
|
102
102
|
end
|
103
103
|
end
|
@@ -107,13 +107,11 @@ module Barthes
|
|
107
107
|
name, content = action[1], action.last
|
108
108
|
env = @env.dup
|
109
109
|
env.update(content['env']) if content['env']
|
110
|
-
@reporter.report(:action,
|
111
|
-
content['number'] = @num
|
110
|
+
@reporter.report(:action, name, action.last, scenarios) do
|
112
111
|
if Barthes::Config[:dryrun] == 0 && !@failed
|
113
112
|
content = Action.new(env).action(content)
|
114
113
|
@failed = true if %w(failure error).include?(content['status'])
|
115
114
|
end
|
116
|
-
content['status'] = 'skipped' if Barthes::Config[:dryrun] > 0
|
117
115
|
content
|
118
116
|
end
|
119
117
|
end
|
data/lib/barthes/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barthes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-11-
|
12
|
+
date: 2014-11-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -139,6 +139,38 @@ dependencies:
|
|
139
139
|
- - ! '>='
|
140
140
|
- !ruby/object:Gem::Version
|
141
141
|
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: chronic
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
type: :runtime
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: httparty
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ! '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
type: :runtime
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
142
174
|
description: lightweight scenario test framework
|
143
175
|
email:
|
144
176
|
- tily05@gmail.com
|
@@ -155,10 +187,13 @@ files:
|
|
155
187
|
- Rakefile
|
156
188
|
- barthes.gemspec
|
157
189
|
- bin/barthes
|
190
|
+
- example/q3_env.json
|
191
|
+
- example/q3_spec.json
|
158
192
|
- lib/barthes.rb
|
159
193
|
- lib/barthes/action.rb
|
160
194
|
- lib/barthes/cache.rb
|
161
195
|
- lib/barthes/cli.rb
|
196
|
+
- lib/barthes/client/httparty.rb
|
162
197
|
- lib/barthes/config.rb
|
163
198
|
- lib/barthes/reporter.rb
|
164
199
|
- lib/barthes/reporter/default.rb
|