barthes 0.0.4 → 0.0.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.
- data/TODO.md +8 -4
- data/barthes.gemspec +4 -1
- data/lib/barthes/action.rb +4 -5
- data/lib/barthes/cache.rb +1 -26
- data/lib/barthes/cli.rb +21 -11
- data/lib/barthes/config.rb +3 -0
- data/lib/barthes/reporter.rb +8 -7
- data/lib/barthes/reporter/default.rb +12 -12
- data/lib/barthes/reporter/junit_xml.rb +43 -6
- data/lib/barthes/runner.rb +24 -21
- data/lib/barthes/version.rb +1 -1
- metadata +54 -5
data/TODO.md
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
+
* json schema
|
1
2
|
* embed strftime format or date command format datetime to json
|
3
|
+
--------------------------------------------
|
2
4
|
* embed or in json expectations
|
3
|
-
*
|
4
|
-
*
|
5
|
-
*
|
6
|
-
|
5
|
+
* あらかじめ番号を最後まで数えるようにする
|
6
|
+
* action status
|
7
|
+
* make 'to' option work
|
8
|
+
* load libraries
|
9
|
+
* テストサマリー表示
|
7
10
|
--------------------------
|
8
11
|
compare -> method, feature, scenario, action
|
9
12
|
xpath change (describe security groups)
|
13
|
+
|
data/barthes.gemspec
CHANGED
@@ -21,7 +21,10 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.6"
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
|
24
|
-
spec.add_dependency "thor"
|
25
24
|
spec.add_dependency "json"
|
26
25
|
spec.add_dependency "erubis"
|
26
|
+
spec.add_dependency "slop"
|
27
|
+
spec.add_dependency "term-ansicolor"
|
28
|
+
spec.add_dependency "activesupport"
|
29
|
+
spec.add_dependency "nokogiri"
|
27
30
|
end
|
data/lib/barthes/action.rb
CHANGED
@@ -2,8 +2,7 @@ require 'barthes/cache'
|
|
2
2
|
|
3
3
|
module Barthes
|
4
4
|
class Action
|
5
|
-
def initialize(env
|
6
|
-
@options = options
|
5
|
+
def initialize(env)
|
7
6
|
@env = env.dup
|
8
7
|
client_class = Object.const_get(@env['client_class'])
|
9
8
|
@client = client_class.new(env)
|
@@ -14,7 +13,7 @@ module Barthes
|
|
14
13
|
end
|
15
14
|
|
16
15
|
def action(action)
|
17
|
-
@env.update(action['
|
16
|
+
@env.update(action['env']) if action['env']
|
18
17
|
params = evaluate_params(action['params'])
|
19
18
|
|
20
19
|
if action['expectations']
|
@@ -49,7 +48,7 @@ module Barthes
|
|
49
48
|
if cache_config = action['cache']
|
50
49
|
value = @client.extract(cache_config, response)
|
51
50
|
action['cache']['value'] = value
|
52
|
-
Barthes::Cache
|
51
|
+
Barthes::Cache[cache_config['key']] = value
|
53
52
|
end
|
54
53
|
action
|
55
54
|
end
|
@@ -59,7 +58,7 @@ module Barthes
|
|
59
58
|
params.each do |k, v|
|
60
59
|
if v.class == String
|
61
60
|
new_v = v.gsub(/\$\{(.+?)\}/) { @env[$1] }
|
62
|
-
new_v = new_v.gsub(/\@\{(.+?)\}/) { p $1; Barthes::Cache
|
61
|
+
new_v = new_v.gsub(/\@\{(.+?)\}/) { p $1; Barthes::Cache[$1] }
|
63
62
|
else
|
64
63
|
new_v = v
|
65
64
|
end
|
data/lib/barthes/cache.rb
CHANGED
@@ -1,28 +1,3 @@
|
|
1
|
-
|
2
1
|
module Barthes
|
3
|
-
|
4
|
-
@cache = {}
|
5
|
-
|
6
|
-
class << self
|
7
|
-
def load(cache)
|
8
|
-
@cache = cache
|
9
|
-
end
|
10
|
-
|
11
|
-
def reset
|
12
|
-
@cache = {}
|
13
|
-
end
|
14
|
-
|
15
|
-
def get(key)
|
16
|
-
@cache[key]
|
17
|
-
end
|
18
|
-
|
19
|
-
def set(key, value)
|
20
|
-
@cache[key] = value
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_hash
|
24
|
-
@cache
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
2
|
+
Cache = {}
|
28
3
|
end
|
data/lib/barthes/cli.rb
CHANGED
@@ -2,19 +2,29 @@ require 'barthes/runner'
|
|
2
2
|
require 'barthes/reporter/default'
|
3
3
|
require 'json'
|
4
4
|
require 'thor'
|
5
|
+
require 'slop'
|
5
6
|
|
6
7
|
module Barthes
|
7
|
-
class CLI
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
8
|
+
class CLI
|
9
|
+
def self.parse_options
|
10
|
+
@opt = Slop.parse!(help: true) do
|
11
|
+
banner 'Usage: barthes [options] /path/to/some_spec.json'
|
12
|
+
on 'e', 'env', 'environment file paths', argument: :optional, as: Array
|
13
|
+
on 'q', 'quiet', 'not show test details', argument: :optional, as: :count
|
14
|
+
on 'f', 'from', 'test number to start from', argument: :optional, as: Integer, default: 1
|
15
|
+
on 't', 'to', 'test number to stop to', argument: :optional
|
16
|
+
on 'l', 'load', 'An optional password', argument: :optional
|
17
|
+
on 'd', 'dryrun', 'not run test but show just structure', argument: :optional, as: :count
|
18
|
+
on 'c', 'cache', 'cache path', argument: :optional, default: './barthes-cache.json'
|
19
|
+
on 'r', 'reporters', 'reporters to use', argument: :optional, as: Array
|
20
|
+
end
|
21
|
+
@opt.to_hash
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.start
|
25
|
+
options = parse_options
|
26
|
+
abort @opt.help if ARGV.empty?
|
27
|
+
Runner.new(options).run(ARGV)
|
18
28
|
end
|
19
29
|
end
|
20
30
|
end
|
data/lib/barthes/reporter.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
|
+
require 'barthes/reporter/default'
|
2
|
+
require 'barthes/reporter/junit_xml'
|
3
|
+
require 'active_support/inflector'
|
1
4
|
|
2
5
|
module Barthes
|
3
6
|
class Reporter
|
4
|
-
def initialize
|
7
|
+
def initialize
|
5
8
|
@reporters = []
|
6
|
-
if
|
7
|
-
|
8
|
-
|
9
|
-
klass = Object.get_const(klass_name)
|
9
|
+
if Barthes::Config[:reporters]
|
10
|
+
Barthes::Config[:reporters].each do |klass_name|
|
11
|
+
klass = klass_name.constantize
|
10
12
|
@reporters << klass.new
|
11
13
|
end
|
12
14
|
else
|
13
|
-
@reporters = [Reporter::Default.new
|
15
|
+
@reporters = [Reporter::Default.new]
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
@@ -24,7 +26,6 @@ module Barthes
|
|
24
26
|
|
25
27
|
@reporters.each do |r|
|
26
28
|
m = :"after_#{event.to_s}"
|
27
|
-
args << result
|
28
29
|
r.send(m, *args) if r.respond_to?(m)
|
29
30
|
end
|
30
31
|
end
|
@@ -1,10 +1,9 @@
|
|
1
|
+
require 'term/ansicolor'
|
1
2
|
|
2
3
|
module Barthes
|
3
4
|
class Reporter
|
4
5
|
class Default
|
5
|
-
|
6
|
-
@options = options
|
7
|
-
end
|
6
|
+
include Term::ANSIColor
|
8
7
|
|
9
8
|
def before_feature(num, name)
|
10
9
|
puts "#{name} (##{num})"
|
@@ -15,18 +14,17 @@ module Barthes
|
|
15
14
|
end
|
16
15
|
|
17
16
|
def before_action(num, name, action, scenarios)
|
18
|
-
|
17
|
+
puts ("\t" * scenarios.size) + "#{name} (##{num})"
|
19
18
|
end
|
20
19
|
|
21
|
-
def after_action(num, name, action, scenarios
|
22
|
-
if
|
23
|
-
puts
|
20
|
+
def after_action(num, name, action, scenarios)
|
21
|
+
if Barthes::Config[:quiet] == 0 && Barthes::Config[:dryrun] == 0
|
24
22
|
puts indent scenarios.size + 1, "request:"
|
25
23
|
puts indent scenarios.size + 2, JSON.pretty_generate(action['request'])
|
26
24
|
puts indent scenarios.size + 1, "response:"
|
27
25
|
puts indent scenarios.size + 2, JSON.pretty_generate(action['response'])
|
28
26
|
end
|
29
|
-
expectations =
|
27
|
+
expectations = action['expectations']
|
30
28
|
expectations.each do |expectation|
|
31
29
|
if expectation['result'] == false
|
32
30
|
puts indent scenarios.size + 1, "failed expectation:"
|
@@ -34,12 +32,14 @@ module Barthes
|
|
34
32
|
end
|
35
33
|
end
|
36
34
|
flag = ''
|
37
|
-
if
|
38
|
-
flag = '
|
35
|
+
if Barthes::Config[:dryrun] > 0
|
36
|
+
flag = 'skipped'
|
37
|
+
elsif expectations.empty? || expectations.all? {|r| r['result'] == true }
|
38
|
+
flag = green {'success'}
|
39
39
|
else
|
40
|
-
flag = 'failure'
|
40
|
+
flag = red {'failure'}
|
41
41
|
end
|
42
|
-
puts indent(scenarios.size, "
|
42
|
+
puts indent(scenarios.size + 1, "result: #{flag}")
|
43
43
|
end
|
44
44
|
|
45
45
|
def indent(num, string)
|
@@ -1,21 +1,58 @@
|
|
1
|
+
require 'builder'
|
2
|
+
require 'nokogiri'
|
1
3
|
|
2
4
|
module Barthes
|
3
5
|
class Reporter
|
4
6
|
class JunitXml
|
7
|
+
def initialize
|
8
|
+
@xml = Builder::XmlMarkup.new
|
9
|
+
@xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
|
10
|
+
end
|
11
|
+
|
5
12
|
def after_run(features)
|
6
|
-
|
13
|
+
result = @xml.testsuites do |xml|
|
14
|
+
features.each do |feature|
|
15
|
+
walk_json(feature)
|
16
|
+
end
|
7
17
|
end
|
18
|
+
puts Nokogiri::XML(result).to_xml(indent: 2)
|
8
19
|
end
|
9
20
|
|
10
|
-
def
|
21
|
+
def walk_json(json)
|
22
|
+
case json.first
|
23
|
+
when 'feature', 'scenario'
|
24
|
+
if json.last.class == Array
|
25
|
+
@xml.testsuite(name: json[1], tests: json.last.size) do
|
26
|
+
json.last.each do |child|
|
27
|
+
walk_json(child)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
when 'action'
|
32
|
+
@xml.testsuite(name: json[1], tests: 1) do
|
33
|
+
@xml.testcase(name: json[1]) do
|
34
|
+
case json.last['status']
|
35
|
+
when 'skipped'
|
36
|
+
@xml.skipped
|
37
|
+
when 'failure'
|
38
|
+
when 'error'
|
39
|
+
end
|
40
|
+
if json.last['status'] != 'skipped' && json.last['request'] && json.last['response']
|
41
|
+
stdout = "request:\n"
|
42
|
+
stdout += "#{JSON.pretty_generate(json.last['request'])}\n"
|
43
|
+
stdout += "response:\n"
|
44
|
+
stdout += "#{JSON.pretty_generate(json.last['response'])}\n"
|
45
|
+
@xml.tag!(:'system-out', stdout)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
else
|
50
|
+
puts json
|
51
|
+
end
|
11
52
|
end
|
12
53
|
|
13
54
|
def render_testcase(xml, action)
|
14
55
|
xml.testcase do
|
15
|
-
xml.stdout
|
16
|
-
xml.failure
|
17
|
-
xml.skipped
|
18
|
-
xml.error
|
19
56
|
end
|
20
57
|
end
|
21
58
|
end
|
data/lib/barthes/runner.rb
CHANGED
@@ -2,32 +2,31 @@ require 'json'
|
|
2
2
|
require 'barthes/action'
|
3
3
|
require 'barthes/reporter'
|
4
4
|
require 'barthes/cache'
|
5
|
+
require 'barthes/config'
|
5
6
|
|
6
7
|
module Barthes
|
7
8
|
class Runner
|
8
9
|
def initialize(options)
|
10
|
+
Barthes::Config.update(options)
|
9
11
|
load_cache
|
10
|
-
|
11
|
-
|
12
|
-
@reporter = Reporter.new
|
13
|
-
@options = options
|
12
|
+
load_libraries
|
13
|
+
load_envs(options[:env])
|
14
|
+
@reporter = Reporter.new
|
14
15
|
end
|
15
16
|
|
16
17
|
def load_cache
|
17
|
-
|
18
|
-
|
19
|
-
Barthes::Cache.load JSON.parse File.read(path)
|
18
|
+
if File.exists? Barthes::Config[:cache]
|
19
|
+
Barthes::Cache.update JSON.parse File.read Barthes::Config[:cache]
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
23
|
+
def load_libraries
|
24
24
|
path = Dir.pwd + '/.barthes'
|
25
25
|
load path if File.exists?(path)
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def load_envs(env_paths)
|
29
29
|
@env = {}
|
30
|
-
env_paths = environment.split(',')
|
31
30
|
env_paths.each do |path|
|
32
31
|
@env.update JSON.parse File.read(path)
|
33
32
|
end
|
@@ -51,26 +50,28 @@ module Barthes
|
|
51
50
|
|
52
51
|
def run(paths)
|
53
52
|
files = expand_paths(paths, '_spec.json')
|
54
|
-
|
53
|
+
results = []
|
54
|
+
@reporter.report(:run, results) do
|
55
55
|
@num = 1
|
56
|
-
results = []
|
57
56
|
files.each do |file|
|
58
57
|
json = JSON.parse File.read(file)
|
59
58
|
@reporter.report(:feature, @num, json[1]) do
|
60
59
|
@num += 1
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
walk_json(json.last, [file])
|
61
|
+
results << json
|
62
|
+
json
|
64
63
|
end
|
65
64
|
end
|
66
65
|
results
|
67
66
|
end
|
68
|
-
|
67
|
+
if !Barthes::Cache.empty?
|
68
|
+
File.write Barthes::Config[:cache], JSON.pretty_generate(Barthes::Cache) + "\n"
|
69
|
+
end
|
69
70
|
end
|
70
71
|
|
71
72
|
def in_range?
|
72
|
-
flag = @num >=
|
73
|
-
flag = flag && (@num >=
|
73
|
+
flag = @num >= Barthes::Config[:from]
|
74
|
+
flag = flag && (@num >= Barthes::Config[:to]) if Barthes::Config[:to]
|
74
75
|
flag
|
75
76
|
end
|
76
77
|
|
@@ -97,6 +98,7 @@ module Barthes
|
|
97
98
|
def handle_scenario(scenario, scenarios)
|
98
99
|
return if @failed
|
99
100
|
@reporter.report(:scenario, @num, scenario[1], scenario.last, scenarios) do
|
101
|
+
scenario.last
|
100
102
|
end
|
101
103
|
end
|
102
104
|
|
@@ -104,14 +106,15 @@ module Barthes
|
|
104
106
|
return if @failed
|
105
107
|
name, content = action[1], action.last
|
106
108
|
env = @env.dup
|
107
|
-
env.update(content['
|
109
|
+
env.update(content['env']) if content['env']
|
108
110
|
@reporter.report(:action, @num, name, action.last, scenarios) do
|
109
|
-
if
|
110
|
-
content = Action.new(env
|
111
|
+
if Barthes::Config[:dryrun] == 0 && !@failed
|
112
|
+
content = Action.new(env).action(content)
|
111
113
|
if content['expectations'] && content['expectations'].any? {|e| e['result'] == false }
|
112
114
|
@failed = true
|
113
115
|
end
|
114
116
|
end
|
117
|
+
content['status'] = 'skipped' if Barthes::Config[:dryrun] > 0
|
115
118
|
content
|
116
119
|
end
|
117
120
|
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.5
|
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-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: json
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
@@ -60,7 +60,7 @@ dependencies:
|
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
63
|
+
name: erubis
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
@@ -76,7 +76,55 @@ dependencies:
|
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
79
|
+
name: slop
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: term-ansicolor
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: activesupport
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: nokogiri
|
80
128
|
requirement: !ruby/object:Gem::Requirement
|
81
129
|
none: false
|
82
130
|
requirements:
|
@@ -112,6 +160,7 @@ files:
|
|
112
160
|
- lib/barthes/action.rb
|
113
161
|
- lib/barthes/cache.rb
|
114
162
|
- lib/barthes/cli.rb
|
163
|
+
- lib/barthes/config.rb
|
115
164
|
- lib/barthes/reporter.rb
|
116
165
|
- lib/barthes/reporter/default.rb
|
117
166
|
- lib/barthes/reporter/junit_xml.rb
|