riot-gear 0.0.13 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -0
- data/lib/riot/gear/context/asserts_json.rb +30 -0
- data/lib/riot/gear/middleware/riotparty.rb +2 -3
- data/lib/riot/gear/version.rb +1 -1
- data/test/actions/patch_test.rb +58 -0
- data/test/assertions/denies_json_test.rb +18 -0
- metadata +24 -14
- checksums.yaml +0 -7
data/CHANGELOG
CHANGED
@@ -34,6 +34,36 @@ module Riot
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
# Generates an denies that based on the value returned from passing the JSON path to the json_path
|
38
|
+
# helper. If a handler block is provided, that block will be called with the value and the response
|
39
|
+
# from the block will be used as the actual in the denies test.
|
40
|
+
#
|
41
|
+
# context "testing a hash" do
|
42
|
+
# setup do
|
43
|
+
# {"a" => {"b" => {"c" => {"d" => "foo"}}}}
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# denies_json("a.b.c.d").equals("bar")
|
47
|
+
# denies_json("a['b'].c['d']").equals("bar")
|
48
|
+
#
|
49
|
+
# denies_json("a.b") do |value|
|
50
|
+
# value["c"]
|
51
|
+
# end.equals({"d" => "bar"})
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# This is useful for testing actual JSON responses from some service that are converted to a hash by
|
55
|
+
# HTTParty.
|
56
|
+
#
|
57
|
+
# @param [String] json_string a JSON looking path
|
58
|
+
# @param [lambda] &handler an optional block for filtering the actual value
|
59
|
+
# @return [Riot::Assertion] an denies block that macros can be applied to
|
60
|
+
def denies_json(json_string, &handler)
|
61
|
+
denies("value from body as json:#{json_string}") do
|
62
|
+
value = json_path(response, json_string)
|
63
|
+
handler ? handler.call(value) : value
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
37
67
|
end # AssertsJson
|
38
68
|
end # Gear
|
39
69
|
end # Riot
|
@@ -1,10 +1,9 @@
|
|
1
1
|
require 'httparty'
|
2
|
-
|
3
2
|
# Here we prepare a {Riot::Context} to have HTTParty bound to it. Basically, this means that you can
|
4
3
|
# use HTTParty within a context the same way you would inside any class or you would normally use it in.
|
5
4
|
# Anything you can do with HTTParty, you can do within a context ... and then you can test it :)
|
6
5
|
#
|
7
|
-
# Great pains are made to ensure that the HTTParty setup bound to one context does not interfere setup
|
6
|
+
# Great pains are made to ensure that the HTTParty setup bound to one context does not interfere setup
|
8
7
|
# bound to another context.
|
9
8
|
class Riot::Gear::RiotPartyMiddleware < ::Riot::ContextMiddleware
|
10
9
|
register
|
@@ -45,7 +44,7 @@ private
|
|
45
44
|
# Returns the list of methods that do something; like make a network call.
|
46
45
|
#
|
47
46
|
# @return [Array<Symbol>]
|
48
|
-
def actionable_methods; [:get, :post, :put, :delete, :head, :options]; end
|
47
|
+
def actionable_methods; [:get, :post, :put, :patch, :delete, :head, :options]; end
|
49
48
|
|
50
49
|
# Returns the list of methods that configure actionable HTTParty methods. The
|
51
50
|
# {HTTParty.default_options} method is explicitly excluded from this list
|
data/lib/riot/gear/version.rb
CHANGED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'teststrap'
|
2
|
+
|
3
|
+
context "Sending a PATCH request with a base uri" do
|
4
|
+
|
5
|
+
context "without params" do
|
6
|
+
hookup do
|
7
|
+
stub_request(:patch, 'http://test.local/foo')
|
8
|
+
.with(:body => {"foo" => "bar"}.to_json)
|
9
|
+
.to_return(:body => "Foo", :status => 200)
|
10
|
+
end
|
11
|
+
|
12
|
+
base_uri "http://test.local"
|
13
|
+
patch "/foo", :body => {"foo" => "bar"}.to_json
|
14
|
+
|
15
|
+
asserts("status code") { response.code }.equals(200)
|
16
|
+
asserts("response body") { response.body }.equals("Foo")
|
17
|
+
end # without params
|
18
|
+
|
19
|
+
context "with params" do
|
20
|
+
hookup do
|
21
|
+
stub_request(:patch, 'http://test.local/foo?bar=baz').
|
22
|
+
with(:body => {"goo" => "car"}.to_json).
|
23
|
+
to_return(:body => "", :status => 203)
|
24
|
+
end
|
25
|
+
|
26
|
+
context "through default_params" do
|
27
|
+
base_uri "http://test.local"
|
28
|
+
default_params({"bar" => "baz"})
|
29
|
+
patch "/foo", :body => {"goo" => "car"}.to_json
|
30
|
+
|
31
|
+
asserts("status code") { response.code }.equals(203)
|
32
|
+
end # through default_params
|
33
|
+
|
34
|
+
context "through query string" do
|
35
|
+
base_uri "http://test.local"
|
36
|
+
patch "/foo?bar=baz", :body => {"goo" => "car"}.to_json
|
37
|
+
|
38
|
+
asserts("status code") { response.code }.equals(203)
|
39
|
+
end # through query string
|
40
|
+
end # with params
|
41
|
+
|
42
|
+
context "while processing options from a block" do
|
43
|
+
hookup do
|
44
|
+
stub_request(:patch, 'http://test.local/foo/bar').
|
45
|
+
with(:body => {"s" => "things"}.to_json).
|
46
|
+
to_return(:body => "", :status => 299)
|
47
|
+
end
|
48
|
+
|
49
|
+
base_uri "http://test.local"
|
50
|
+
|
51
|
+
patch do
|
52
|
+
{ :path => "/foo/bar", :body => {"s" => "things"}.to_json }
|
53
|
+
end
|
54
|
+
|
55
|
+
asserts("status code") { response.code }.equals(299)
|
56
|
+
end # while processing options from a block
|
57
|
+
|
58
|
+
end # Sending a PUT request with a base uri
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'teststrap'
|
2
|
+
|
3
|
+
context "The denies_json macro" do
|
4
|
+
|
5
|
+
helper(:response) do
|
6
|
+
{
|
7
|
+
"a" => {"b" => "foo"},
|
8
|
+
"c" => [["foo", 1], ["bar", 2]]
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
denies_json("a.b").equals("FOO")
|
13
|
+
|
14
|
+
denies_json("c") do |value|
|
15
|
+
value.map { |string, number| number }
|
16
|
+
end.equals([0,1])
|
17
|
+
|
18
|
+
end # The denies_json macro
|
metadata
CHANGED
@@ -1,41 +1,46 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riot-gear
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.15
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Justin 'Gus' Knowlden
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2015-10-06 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: riot
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
|
-
- -
|
19
|
+
- - ! '>='
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: 0.12.6
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
|
-
- -
|
27
|
+
- - ! '>='
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: 0.12.6
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: httparty
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
|
-
- -
|
35
|
+
- - ! '>='
|
32
36
|
- !ruby/object:Gem::Version
|
33
37
|
version: 0.12.0
|
34
38
|
type: :runtime
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
|
-
- -
|
43
|
+
- - ! '>='
|
39
44
|
- !ruby/object:Gem::Version
|
40
45
|
version: 0.12.0
|
41
46
|
description: Riot + HTTParty smoke testing framework. You'd use it for integration
|
@@ -45,9 +50,9 @@ executables: []
|
|
45
50
|
extensions: []
|
46
51
|
extra_rdoc_files: []
|
47
52
|
files:
|
48
|
-
-
|
49
|
-
-
|
50
|
-
-
|
53
|
+
- .gitignore
|
54
|
+
- .travis.yml
|
55
|
+
- .yardopts
|
51
56
|
- CHANGELOG
|
52
57
|
- Gemfile
|
53
58
|
- MIT-LICENSE
|
@@ -67,9 +72,11 @@ files:
|
|
67
72
|
- test/actions/delete_test.rb
|
68
73
|
- test/actions/get_test.rb
|
69
74
|
- test/actions/options_test.rb
|
75
|
+
- test/actions/patch_test.rb
|
70
76
|
- test/actions/post_test.rb
|
71
77
|
- test/actions/put_test.rb
|
72
78
|
- test/assertions/asserts_json_test.rb
|
79
|
+
- test/assertions/denies_json_test.rb
|
73
80
|
- test/helpers/cookie_values_test.rb
|
74
81
|
- test/helpers/json_path_test.rb
|
75
82
|
- test/once_block_test.rb
|
@@ -78,34 +85,37 @@ files:
|
|
78
85
|
- test/teststrap.rb
|
79
86
|
homepage: http://github.com/thumblemonks/riot-gear
|
80
87
|
licenses: []
|
81
|
-
metadata: {}
|
82
88
|
post_install_message:
|
83
89
|
rdoc_options: []
|
84
90
|
require_paths:
|
85
91
|
- lib
|
86
92
|
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
87
94
|
requirements:
|
88
|
-
- -
|
95
|
+
- - ! '>='
|
89
96
|
- !ruby/object:Gem::Version
|
90
97
|
version: '0'
|
91
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
92
100
|
requirements:
|
93
|
-
- -
|
101
|
+
- - ! '>='
|
94
102
|
- !ruby/object:Gem::Version
|
95
103
|
version: '0'
|
96
104
|
requirements: []
|
97
105
|
rubyforge_project:
|
98
|
-
rubygems_version:
|
106
|
+
rubygems_version: 1.8.25
|
99
107
|
signing_key:
|
100
|
-
specification_version:
|
108
|
+
specification_version: 3
|
101
109
|
summary: Riot + HTTParty smoke testing framework.
|
102
110
|
test_files:
|
103
111
|
- test/actions/delete_test.rb
|
104
112
|
- test/actions/get_test.rb
|
105
113
|
- test/actions/options_test.rb
|
114
|
+
- test/actions/patch_test.rb
|
106
115
|
- test/actions/post_test.rb
|
107
116
|
- test/actions/put_test.rb
|
108
117
|
- test/assertions/asserts_json_test.rb
|
118
|
+
- test/assertions/denies_json_test.rb
|
109
119
|
- test/helpers/cookie_values_test.rb
|
110
120
|
- test/helpers/json_path_test.rb
|
111
121
|
- test/once_block_test.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: a85e9ec0d3bde6eb410beb4ff3f8fe1f31c067e5
|
4
|
-
data.tar.gz: 1b7443dcc8fdfee8b956d13795826e86651a72c6
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 7a0aa096744cd1c1014bcc7c228382bed0c7886d5fea91166eb2b01fa02b5bc8e6ee16c5bc2b020d7ff795bc4b00f85b6657e543bace3d2431509bb7246a1922
|
7
|
-
data.tar.gz: 58c3ccd3998c398c89f83d170e92e1dcdc54fbb655f285fd61c3ccccc374513bc61d8d933bdc032f1773965bba823f041f9b6e1cba26ed807b791302a5d121e0
|