bark 0.0.2
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 +7 -0
- data/.gitignore +43 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +45 -0
- data/LICENSE.txt +4 -0
- data/README.md +96 -0
- data/Rakefile +10 -0
- data/bark.gemspec +39 -0
- data/lib/bark.rb +109 -0
- data/lib/bark/request.rb +77 -0
- data/lib/bark/request/graph_of_life.rb +76 -0
- data/lib/bark/request/studies.rb +82 -0
- data/lib/bark/request/taxonomy.rb +78 -0
- data/lib/bark/request/tnrs.rb +75 -0
- data/lib/bark/request/tree_of_life.rb +91 -0
- data/lib/bark/response.rb +51 -0
- data/lib/bark/version.rb +3 -0
- data/spec/lib/bark_spec.rb +87 -0
- data/spec/lib/request/graph_of_life_spec.rb +44 -0
- data/spec/lib/request/studies_spec.rb +74 -0
- data/spec/lib/request/taxonomy_spec.rb +44 -0
- data/spec/lib/request/tnrs_spec.rb +44 -0
- data/spec/lib/request/tree_of_life_spec.rb +44 -0
- data/spec/lib/request_spec.rb +20 -0
- data/spec/lib/response_spec.rb +22 -0
- data/spec/lib/shared_tests_spec.rb +29 -0
- data/spec/shared_tests.rb +87 -0
- data/spec/shared_tests_helper.rb +115 -0
- data/spec/spec_helper.rb +23 -0
- metadata +184 -0
data/lib/bark/version.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Bark do
|
4
|
+
|
5
|
+
# TODO: Check that shared tests were built correctly, and warn if not
|
6
|
+
|
7
|
+
context '.request_class - determing request type from method' do
|
8
|
+
specify 'for tol_' do
|
9
|
+
expect(Bark.request_class('tol_about')).to eq(Bark::Request::TreeOfLife)
|
10
|
+
expect(Bark.request_class(:tol_about)).to eq(Bark::Request::TreeOfLife)
|
11
|
+
end
|
12
|
+
|
13
|
+
specify 'for gol_' do
|
14
|
+
expect(Bark.request_class('gol_about')).to eq(Bark::Request::GraphOfLife)
|
15
|
+
expect(Bark.request_class(:gol_about)).to eq(Bark::Request::GraphOfLife)
|
16
|
+
end
|
17
|
+
|
18
|
+
specify 'for tnrs_' do
|
19
|
+
expect(Bark.request_class('tnrs_match_names')).to eq(Bark::Request::Tnrs)
|
20
|
+
expect(Bark.request_class(:tnrs_match_names)).to eq(Bark::Request::Tnrs)
|
21
|
+
end
|
22
|
+
|
23
|
+
specify 'for taxonomy_' do
|
24
|
+
expect(Bark.request_class('taxonomy_about')).to eq(Bark::Request::Taxonomy)
|
25
|
+
expect(Bark.request_class(:taxonomy_about)).to eq(Bark::Request::Taxonomy)
|
26
|
+
end
|
27
|
+
|
28
|
+
specify 'for studies_' do
|
29
|
+
expect(Bark.request_class('studies_find_studies')).to eq(Bark::Request::Studies)
|
30
|
+
expect(Bark.request_class(:studies_find_studies)).to eq(Bark::Request::Studies)
|
31
|
+
expect(Bark.request_class('get_study')).to eq(Bark::Request::Studies)
|
32
|
+
expect(Bark.request_class(:get_study)).to eq(Bark::Request::Studies)
|
33
|
+
end
|
34
|
+
|
35
|
+
specify 'for something_not_recognized' do
|
36
|
+
expect(Bark.request_class(:something_not_recognized)).to eq(false)
|
37
|
+
expect(Bark.request_class('something_not_recognized')).to eq(false)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'convience wrapping methods' do
|
42
|
+
context 'method_missing' do
|
43
|
+
specify 'methods with indeterminable requests classes raise' do
|
44
|
+
expect {Bark.foo}.to raise_error
|
45
|
+
end
|
46
|
+
|
47
|
+
specify 'methods with determinable request classes do not raise' do
|
48
|
+
expect {Bark.get_study()}.to_not raise_error
|
49
|
+
end
|
50
|
+
|
51
|
+
specify 'methods with params do not raise' do
|
52
|
+
expect { Bark.get_study(params: {'study_id' => 'px3454'})}.to_not raise_error
|
53
|
+
end
|
54
|
+
|
55
|
+
specify 'a GET example returns' do
|
56
|
+
expect( Bark.get_study(params: {:study_id => '2113'})['error']).to be_falsey
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'shared tests' do
|
63
|
+
specify 'are instantiated from a URL' do
|
64
|
+
expect(SharedTestsHelper::SHARED_TESTS.count).to be > 0
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'SharedTestsHelper::OtTest' do
|
68
|
+
let(:t) { SharedTestsHelper::OtTest.new }
|
69
|
+
|
70
|
+
specify 'have a name' do
|
71
|
+
expect(t).to respond_to(:name)
|
72
|
+
end
|
73
|
+
|
74
|
+
specify 'reference a function' do
|
75
|
+
expect(t).to respond_to(:method)
|
76
|
+
end
|
77
|
+
|
78
|
+
specify 'provide an input' do
|
79
|
+
expect(t).to respond_to(:input)
|
80
|
+
end
|
81
|
+
|
82
|
+
specify 'expect multiple tests' do
|
83
|
+
expect(t).to respond_to(:tests)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Bark::Request::GraphOfLife do
|
4
|
+
|
5
|
+
#context 'Ruby/Bark specific implementation' do
|
6
|
+
# specify 'is written for an API_VERSION' do
|
7
|
+
# expect( Bark::Request::TreeOfLife::API_VERSION).to eq('v2')
|
8
|
+
# end
|
9
|
+
|
10
|
+
# specify 'has an SEARCH_BASE' do
|
11
|
+
# expect( Bark::Request::TreeOfLife::SEARCH_BASE).to eq('http://devapi.opentreeoflife.org/v2/tree_of_life')
|
12
|
+
# end
|
13
|
+
|
14
|
+
# specify 'reference methods by ot API wrapper shared name in METHODS' do
|
15
|
+
# expect( Bark::Request::TreeOfLife::METHODS.keys.sort).to eq(%i{tol_about tol_mrca tol_subtree tol_induced_tree}.sort)
|
16
|
+
# end
|
17
|
+
|
18
|
+
# context 'building a request URI' do
|
19
|
+
# specify 'for find_tree_of_life' do
|
20
|
+
# a = Bark::Request::TreeOfLife.new(method: :tol_about)
|
21
|
+
# expect(a.uri.to_s).to eq('http://devapi.opentreeoflife.org/v2/tree_of_life/about')
|
22
|
+
# end
|
23
|
+
|
24
|
+
# specify 'for matched_tree_of_life' do
|
25
|
+
# a = Bark::Request::TreeOfLife.new(method: :tol_mrca)
|
26
|
+
# expect(a.uri.to_s).to eq('http://devapi.opentreeoflife.org/v2/tree_of_life/mrca')
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
|
30
|
+
# context 'basic use, for :about, in a response' do
|
31
|
+
# specify 'works' do
|
32
|
+
# a = Bark::Request::TreeOfLife.new(method: :tol_about, params: {})
|
33
|
+
# b = Bark::Response.new(request: a)
|
34
|
+
# expect(b.request_succeeded?).to be(true)
|
35
|
+
# expect(b.json.keys.include?('root_node_id')).to be(true)
|
36
|
+
# end
|
37
|
+
# end
|
38
|
+
|
39
|
+
context 'shared tests' do
|
40
|
+
run_tests(Bark::Request::GraphOfLife, SharedTestsHelper::SHARED_TESTS['graph_of_life'])
|
41
|
+
end
|
42
|
+
|
43
|
+
# end
|
44
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Bark::Request::Studies do
|
4
|
+
|
5
|
+
subject { Bark::Request::Studies }
|
6
|
+
|
7
|
+
context 'Ruby/Bark specific implementation' do
|
8
|
+
specify 'is written for an API_VERSION' do
|
9
|
+
expect( Bark::Request::Studies::API_VERSION).to eq('v2')
|
10
|
+
end
|
11
|
+
|
12
|
+
specify 'has an SEARCH_BASE' do
|
13
|
+
expect( Bark::Request::Studies::SEARCH_BASE).to eq('http://devapi.opentreeoflife.org/v2')
|
14
|
+
end
|
15
|
+
|
16
|
+
specify 'has an default FORMAT' do
|
17
|
+
expect( Bark::Request::Studies::FORMAT).to eq('json')
|
18
|
+
end
|
19
|
+
|
20
|
+
specify 'reference methods by ot API wrapper shared name in METHODS' do
|
21
|
+
expect( Bark::Request::Studies::METHODS.keys.sort).to eq([:studies_find_studies, :studies_find_trees, :get_study, :get_study_tree, :studies_properties].sort)
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'building a request URI' do
|
25
|
+
specify 'for find_studies' do
|
26
|
+
a = Bark::Request::Studies.new(method: :studies_find_studies)
|
27
|
+
expect(a.uri.to_s).to eq('http://devapi.opentreeoflife.org/v2/studies/find_studies')
|
28
|
+
end
|
29
|
+
|
30
|
+
specify 'for find_trees' do
|
31
|
+
a = Bark::Request::Studies.new(method: :studies_find_trees)
|
32
|
+
expect(a.uri.to_s).to eq('http://devapi.opentreeoflife.org/v2/studies/find_trees')
|
33
|
+
end
|
34
|
+
|
35
|
+
specify 'for study' do
|
36
|
+
id = 'pg_1144'
|
37
|
+
a = Bark::Request::Studies.new(method: :get_study, params: {study_id: id})
|
38
|
+
expect(a.uri.to_s).to eq("http://devapi.opentreeoflife.org/v2/study/#{id}")
|
39
|
+
end
|
40
|
+
|
41
|
+
specify 'for study_tree' do
|
42
|
+
id = 'pg_1144'
|
43
|
+
tree = 'tree2324'
|
44
|
+
a = Bark::Request::Studies.new(method: :get_study_tree, params: {study_id: id, tree_id: tree })
|
45
|
+
expect(a.uri.to_s).to eq("http://devapi.opentreeoflife.org/v2/study/#{id}/tree/#{tree}")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'payload' do
|
50
|
+
specify 'params are persisted' do
|
51
|
+
params = {value: 'Garcinia', property: 'ot:ottTaxonName'}
|
52
|
+
a = Bark::Request::Studies.new(method: :studies_find_trees, params: params )
|
53
|
+
expect(a.params).to eq(params)
|
54
|
+
expect(a.json_payload).to eq(params.to_json)
|
55
|
+
expect(a.valid?).to be(true)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'basic use, for :studies_find_trees, in a response' do
|
61
|
+
specify 'works' do
|
62
|
+
a = Bark::Request::Studies.new(method: :studies_find_trees, params: {value: 'Garcinia', property: 'ot:ottTaxonName'})
|
63
|
+
b = Bark::Response.new(request: a)
|
64
|
+
expect(b.request_succeeded?).to be(true)
|
65
|
+
expect(b.json.keys.include?('matched_studies')).to be(true)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'shared tests' do
|
70
|
+
run_tests(Bark::Request::Studies, SharedTestsHelper::SHARED_TESTS['studies'])
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Bark::Request::Taxonomy do
|
4
|
+
|
5
|
+
#context 'Ruby/Bark specific implementation' do
|
6
|
+
# specify 'is written for an API_VERSION' do
|
7
|
+
# expect( Bark::Request::TreeOfLife::API_VERSION).to eq('v2')
|
8
|
+
# end
|
9
|
+
|
10
|
+
# specify 'has an SEARCH_BASE' do
|
11
|
+
# expect( Bark::Request::TreeOfLife::SEARCH_BASE).to eq('http://devapi.opentreeoflife.org/v2/tree_of_life')
|
12
|
+
# end
|
13
|
+
|
14
|
+
# specify 'reference methods by ot API wrapper shared name in METHODS' do
|
15
|
+
# expect( Bark::Request::TreeOfLife::METHODS.keys.sort).to eq(%i{tol_about tol_mrca tol_subtree tol_induced_tree}.sort)
|
16
|
+
# end
|
17
|
+
|
18
|
+
# context 'building a request URI' do
|
19
|
+
# specify 'for find_tree_of_life' do
|
20
|
+
# a = Bark::Request::TreeOfLife.new(method: :tol_about)
|
21
|
+
# expect(a.uri.to_s).to eq('http://devapi.opentreeoflife.org/v2/tree_of_life/about')
|
22
|
+
# end
|
23
|
+
|
24
|
+
# specify 'for matched_tree_of_life' do
|
25
|
+
# a = Bark::Request::TreeOfLife.new(method: :tol_mrca)
|
26
|
+
# expect(a.uri.to_s).to eq('http://devapi.opentreeoflife.org/v2/tree_of_life/mrca')
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
|
30
|
+
# context 'basic use, for :about, in a response' do
|
31
|
+
# specify 'works' do
|
32
|
+
# a = Bark::Request::TreeOfLife.new(method: :tol_about, params: {})
|
33
|
+
# b = Bark::Response.new(request: a)
|
34
|
+
# expect(b.request_succeeded?).to be(true)
|
35
|
+
# expect(b.json.keys.include?('root_node_id')).to be(true)
|
36
|
+
# end
|
37
|
+
# end
|
38
|
+
|
39
|
+
context 'shared tests' do
|
40
|
+
run_tests(Bark::Request::Taxonomy, SharedTestsHelper::SHARED_TESTS['taxonomy'])
|
41
|
+
end
|
42
|
+
|
43
|
+
# end
|
44
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Bark::Request::Tnrs do
|
4
|
+
|
5
|
+
#context 'Ruby/Bark specific implementation' do
|
6
|
+
# specify 'is written for an API_VERSION' do
|
7
|
+
# expect( Bark::Request::TreeOfLife::API_VERSION).to eq('v2')
|
8
|
+
# end
|
9
|
+
|
10
|
+
# specify 'has an SEARCH_BASE' do
|
11
|
+
# expect( Bark::Request::TreeOfLife::SEARCH_BASE).to eq('http://devapi.opentreeoflife.org/v2/tree_of_life')
|
12
|
+
# end
|
13
|
+
|
14
|
+
# specify 'reference methods by ot API wrapper shared name in METHODS' do
|
15
|
+
# expect( Bark::Request::TreeOfLife::METHODS.keys.sort).to eq(%i{tol_about tol_mrca tol_subtree tol_induced_tree}.sort)
|
16
|
+
# end
|
17
|
+
|
18
|
+
# context 'building a request URI' do
|
19
|
+
# specify 'for find_tree_of_life' do
|
20
|
+
# a = Bark::Request::TreeOfLife.new(method: :tol_about)
|
21
|
+
# expect(a.uri.to_s).to eq('http://devapi.opentreeoflife.org/v2/tree_of_life/about')
|
22
|
+
# end
|
23
|
+
|
24
|
+
# specify 'for matched_tree_of_life' do
|
25
|
+
# a = Bark::Request::TreeOfLife.new(method: :tol_mrca)
|
26
|
+
# expect(a.uri.to_s).to eq('http://devapi.opentreeoflife.org/v2/tree_of_life/mrca')
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
|
30
|
+
# context 'basic use, for :about, in a response' do
|
31
|
+
# specify 'works' do
|
32
|
+
# a = Bark::Request::TreeOfLife.new(method: :tol_about, params: {})
|
33
|
+
# b = Bark::Response.new(request: a)
|
34
|
+
# expect(b.request_succeeded?).to be(true)
|
35
|
+
# expect(b.json.keys.include?('root_node_id')).to be(true)
|
36
|
+
# end
|
37
|
+
# end
|
38
|
+
|
39
|
+
context 'shared tests' do
|
40
|
+
run_tests(Bark::Request::Tnrs, SharedTestsHelper::SHARED_TESTS['tnrs'])
|
41
|
+
end
|
42
|
+
|
43
|
+
# end
|
44
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Bark::Request::TreeOfLife do
|
4
|
+
|
5
|
+
context 'Ruby/Bark specific implementation' do
|
6
|
+
specify 'is written for an API_VERSION' do
|
7
|
+
expect( Bark::Request::TreeOfLife::API_VERSION).to eq('v2')
|
8
|
+
end
|
9
|
+
|
10
|
+
specify 'has an SEARCH_BASE' do
|
11
|
+
expect( Bark::Request::TreeOfLife::SEARCH_BASE).to eq('http://devapi.opentreeoflife.org/v2/tree_of_life')
|
12
|
+
end
|
13
|
+
|
14
|
+
specify 'reference methods by ot API wrapper shared name in METHODS' do
|
15
|
+
expect( Bark::Request::TreeOfLife::METHODS.keys.sort).to eq(%i{tol_about tol_mrca tol_subtree tol_induced_subtree}.sort)
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'building a request URI' do
|
19
|
+
specify 'for find_tree_of_life' do
|
20
|
+
a = Bark::Request::TreeOfLife.new(method: :tol_about)
|
21
|
+
expect(a.uri.to_s).to eq('http://devapi.opentreeoflife.org/v2/tree_of_life/about')
|
22
|
+
end
|
23
|
+
|
24
|
+
specify 'for matched_tree_of_life' do
|
25
|
+
a = Bark::Request::TreeOfLife.new(method: :tol_mrca)
|
26
|
+
expect(a.uri.to_s).to eq('http://devapi.opentreeoflife.org/v2/tree_of_life/mrca')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'basic use, for :about, in a response' do
|
31
|
+
specify 'works' do
|
32
|
+
a = Bark::Request::TreeOfLife.new(method: :tol_about, params: {})
|
33
|
+
b = Bark::Response.new(request: a)
|
34
|
+
expect(b.request_succeeded?).to be(true)
|
35
|
+
expect(b.json.keys.include?('root_node_id')).to be(true)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'shared tests' do
|
40
|
+
run_tests(Bark::Request::TreeOfLife, SharedTestsHelper::SHARED_TESTS['tree_of_life'])
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Bark::Request do
|
4
|
+
|
5
|
+
let(:request) {Bark::Request.new}
|
6
|
+
|
7
|
+
context 'attributes include' do
|
8
|
+
specify '#payload' do
|
9
|
+
expect(request).to respond_to(:payload)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'constants include' do
|
14
|
+
specify 'BASE_URL' do
|
15
|
+
expect( Bark::Request::BASE_URL).to eq('http://devapi.opentreeoflife.org')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Bark::Response do
|
4
|
+
|
5
|
+
subject { Bark::Response }
|
6
|
+
|
7
|
+
let(:uri) { URI('http://devapi.opentreeoflife.org/v2/taxonomy/about') }
|
8
|
+
let(:request) {
|
9
|
+
r = instance_double('Bark::Request')
|
10
|
+
allow(r).to receive(:uri).and_return( uri )
|
11
|
+
allow(r).to receive(:valid?).and_return(true)
|
12
|
+
allow(r).to receive(:json_payload).and_return({}.to_json)
|
13
|
+
allow(r).to receive(:method).and_return(:studies_properties)
|
14
|
+
r
|
15
|
+
}
|
16
|
+
|
17
|
+
specify 'a good request returns' do
|
18
|
+
expect(Bark::Response.new(request: request)).to be_truthy
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# Meta-tests for sanity
|
4
|
+
describe SharedTestsHelper do
|
5
|
+
|
6
|
+
specify 'are instantiated from a URL' do
|
7
|
+
expect(SharedTestsHelper::SHARED_TESTS.count).to be > 0
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'SharedTestsHelper::OtTest' do
|
11
|
+
let(:t) { SharedTestsHelper::OtTest.new }
|
12
|
+
|
13
|
+
specify 'have a name' do
|
14
|
+
expect(t).to respond_to(:name)
|
15
|
+
end
|
16
|
+
|
17
|
+
specify 'reference a function' do
|
18
|
+
expect(t).to respond_to(:method)
|
19
|
+
end
|
20
|
+
|
21
|
+
specify 'provide an input' do
|
22
|
+
expect(t).to respond_to(:input)
|
23
|
+
end
|
24
|
+
|
25
|
+
specify 'expect multiple tests' do
|
26
|
+
expect(t).to respond_to(:tests)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# Methods that call shared tests.
|
2
|
+
|
3
|
+
def get_response(request)
|
4
|
+
|
5
|
+
end
|
6
|
+
|
7
|
+
def run_tests(request_class, tests)
|
8
|
+
tests.each do |t|
|
9
|
+
context t.name do
|
10
|
+
r = request_class.new(method: t.method, params: t.input)
|
11
|
+
|
12
|
+
t.tests.keys.each do |k|
|
13
|
+
|
14
|
+
# we don't need a response
|
15
|
+
if k == 'parameters_error'
|
16
|
+
specify k.to_s do
|
17
|
+
msg = t.tests[k][1]
|
18
|
+
expect(r.valid?).to eq(false), msg
|
19
|
+
# TODO: possibly extend to see raised error
|
20
|
+
end
|
21
|
+
|
22
|
+
# we do need a response
|
23
|
+
else
|
24
|
+
response = Bark::Response.new(request: r)
|
25
|
+
case k
|
26
|
+
when 'of_type'
|
27
|
+
specify k.to_s do
|
28
|
+
of_type_test(response, t, t.tests[k][1])
|
29
|
+
end
|
30
|
+
when 'equals'
|
31
|
+
t.tests[k].each_with_index do |subtest, i|
|
32
|
+
key = subtest[0][0]
|
33
|
+
value = subtest[0][1]
|
34
|
+
msg = subtest[1]
|
35
|
+
specify "#{k} #{key}: #{value} (#{i})" do
|
36
|
+
expect(response.json[key]).to eq(value), msg
|
37
|
+
end
|
38
|
+
end
|
39
|
+
when 'contains'
|
40
|
+
t.tests[k].each_with_index do |subtest, i|
|
41
|
+
key = subtest[0]
|
42
|
+
msg = subtest[1]
|
43
|
+
specify "#{k} #{key} (#{i})" do
|
44
|
+
expect(response.json[key]).to be_truthy
|
45
|
+
end
|
46
|
+
end
|
47
|
+
when 'length_greater_than'
|
48
|
+
t.tests[k].each_with_index do |subtest, i|
|
49
|
+
key = subtest[0][0]
|
50
|
+
len = subtest[0][1].to_i
|
51
|
+
msg = subtest[1]
|
52
|
+
specify "#{k} #{key}: #{len} (#{i})" do
|
53
|
+
expect(response.json[key].length > len ).to be(true), msg
|
54
|
+
end
|
55
|
+
end
|
56
|
+
when 'deep_equals'
|
57
|
+
t.tests[k].each_with_index do |subtest, i|
|
58
|
+
sub_response = response.json
|
59
|
+
# could eval a string sensu python too
|
60
|
+
subtest[0][0].each do |k|
|
61
|
+
sub_response = sub_response[k]
|
62
|
+
end
|
63
|
+
value = subtest[0][1]
|
64
|
+
msg = subtest[1]
|
65
|
+
specify "#{k} #{subtest[0][0]}: #{value} (#{i})" do
|
66
|
+
expect(sub_response).to eq(value), msg
|
67
|
+
end
|
68
|
+
end
|
69
|
+
when 'contains_error'
|
70
|
+
specify "#{k}" do
|
71
|
+
msg = t.tests[k]
|
72
|
+
expect(response.json['error']).to be_truthy, msg
|
73
|
+
end
|
74
|
+
else
|
75
|
+
pending "Test engine for [ #{k} ] not yet written."
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
def of_type_test(response, ot_test_instance, message)
|
85
|
+
expect(response.result.class).to eq(ot_test_instance.result_type), message
|
86
|
+
end
|
87
|
+
|