riot-gear 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/riot/gear/middleware/riotparty.rb +21 -8
- data/riot-gear.gemspec +9 -3
- data/test/helpers/cookie_values_test.rb +25 -0
- data/test/riotparty_proxy_methods_test.rb +102 -0
- data/test/setting_up_gear_context_test.rb +30 -0
- data/test/teststrap.rb +4 -1
- metadata +9 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -27,8 +27,12 @@ module Riot
|
|
27
27
|
context.helper(:response) { @smoke_response }
|
28
28
|
end # setup_faux_class
|
29
29
|
|
30
|
+
def action_methods
|
31
|
+
%w[get post put delete head options]
|
32
|
+
end
|
33
|
+
|
30
34
|
def proxy_methods
|
31
|
-
HTTParty::ClassMethods.instance_methods -
|
35
|
+
HTTParty::ClassMethods.instance_methods - action_methods - ["default_options"]
|
32
36
|
end
|
33
37
|
|
34
38
|
# Basically, we're just passing standard HTTParty setup methods onto situation via hookups. Except
|
@@ -56,12 +60,13 @@ module Riot
|
|
56
60
|
#
|
57
61
|
# json_path(json_object, "a.b.c.d")
|
58
62
|
# => "foo"
|
59
|
-
# json_path(json_object, "a['b'].c[
|
63
|
+
# json_path(json_object, "a['b'].c[d]")
|
60
64
|
# => "foo"
|
61
65
|
#
|
62
|
-
# You can even work with array indexes
|
66
|
+
# You can even work with array indexes
|
67
|
+
#
|
63
68
|
# json_object = {"a" => {"b" => "c" => ["foo", {"d" => "bar"}]}}
|
64
|
-
# json_path(json_object, "a
|
69
|
+
# json_path(json_object, "a[b].c[1].d")
|
65
70
|
# => "bar"
|
66
71
|
def helper_json_path(context)
|
67
72
|
context.helper(:json_path) do |dictionary, path|
|
@@ -72,12 +77,20 @@ module Riot
|
|
72
77
|
end
|
73
78
|
end
|
74
79
|
|
80
|
+
# Splits up the cookies found in the Set-Cookie header. I'm sure I could use HTTParty for this somehow,
|
81
|
+
# but this seemed just as straightforward. You will get back a hash of the
|
82
|
+
# {cookie-name => cookie-bits} pairs
|
83
|
+
#
|
84
|
+
# {
|
85
|
+
# "session_cookie" => {"value => "fooberries", "path" => "/", ...},
|
86
|
+
# "stupid_marketing_tricks" => {"value" => "personal-information", ...},
|
87
|
+
# ...
|
88
|
+
# }
|
75
89
|
def helper_cookie_value(context)
|
76
90
|
context.helper(:cookie_values) do
|
77
|
-
response.header["set-cookie"].split(
|
78
|
-
|
79
|
-
|
80
|
-
hash
|
91
|
+
response.header["set-cookie"].split("\n").inject({}) do |jar, cookie_str|
|
92
|
+
(name, value), *bits = cookie_str.split(/; ?/).map { |bit| bit.split('=') }
|
93
|
+
jar.merge!(name => bits.inject({"value" => value}) { |h, (k,v)| h.merge!(k => v) })
|
81
94
|
end
|
82
95
|
end
|
83
96
|
end
|
data/riot-gear.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{riot-gear}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Justin 'Gus' Knowlden"]
|
12
|
-
s.date = %q{2010-06
|
12
|
+
s.date = %q{2010-07-06}
|
13
13
|
s.description = %q{Riot + HTTParty smoke testing framework. You'd use it for integration testing with real HTTP requests and responses}
|
14
14
|
s.email = %q{gus@gusg.us}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -29,7 +29,10 @@ Gem::Specification.new do |s|
|
|
29
29
|
"lib/riot/gear/middleware.rb",
|
30
30
|
"lib/riot/gear/middleware/riotparty.rb",
|
31
31
|
"riot-gear.gemspec",
|
32
|
+
"test/helpers/cookie_values_test.rb",
|
32
33
|
"test/helpers/json_path_test.rb",
|
34
|
+
"test/riotparty_proxy_methods_test.rb",
|
35
|
+
"test/setting_up_gear_context_test.rb",
|
33
36
|
"test/teststrap.rb"
|
34
37
|
]
|
35
38
|
s.homepage = %q{http://github.com/thumblemonks/riot-gear}
|
@@ -38,7 +41,10 @@ Gem::Specification.new do |s|
|
|
38
41
|
s.rubygems_version = %q{1.3.6}
|
39
42
|
s.summary = %q{Riot + HTTParty smoke testing framework}
|
40
43
|
s.test_files = [
|
41
|
-
"test/helpers/
|
44
|
+
"test/helpers/cookie_values_test.rb",
|
45
|
+
"test/helpers/json_path_test.rb",
|
46
|
+
"test/riotparty_proxy_methods_test.rb",
|
47
|
+
"test/setting_up_gear_context_test.rb",
|
42
48
|
"test/teststrap.rb"
|
43
49
|
]
|
44
50
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'teststrap'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
context "The cookie_values helper" do
|
5
|
+
helper(:build_response) do |cookie_parts|
|
6
|
+
OpenStruct.new( {:header => {"set-cookie" => cookie_parts.join("\n")}} )
|
7
|
+
end
|
8
|
+
|
9
|
+
hookup do
|
10
|
+
@smoke_response = build_response([
|
11
|
+
"foo=12345; path=/; expires=never-ever;",
|
12
|
+
"goo=jam; path=/blue; expires=sometime-soon;",
|
13
|
+
])
|
14
|
+
end
|
15
|
+
|
16
|
+
asserts("non-existent bar cookie") { cookie_values["bar"] }.nil
|
17
|
+
|
18
|
+
asserts("existing foo cookie") do
|
19
|
+
cookie_values["foo"]
|
20
|
+
end.equals({"value" => "12345", "path" => "/", "expires" => "never-ever"})
|
21
|
+
|
22
|
+
asserts("existing goo cookie") do
|
23
|
+
cookie_values["goo"]
|
24
|
+
end.equals({"value" => "jam", "path" => "/blue", "expires" => "sometime-soon"})
|
25
|
+
end # The cookie_values helper
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'teststrap'
|
2
|
+
|
3
|
+
context "A Riot Gear context" do
|
4
|
+
# The magic to this whole thing is that if you modify RiotPartyMiddleware#proxy_httparty_hookups
|
5
|
+
# to not either not setup hookups for these HTTParty method calls or simply not define HTTParty methods
|
6
|
+
# on the context, these assertions will fail
|
7
|
+
|
8
|
+
%w[
|
9
|
+
base_uri headers cookies basic_auth digest_auth http_proxy format debug_output pem
|
10
|
+
default_timeout default_params no_follow maintain_method_across_redirects
|
11
|
+
].each do |http_party_method|
|
12
|
+
asserts_topic.responds_to(http_party_method)
|
13
|
+
end
|
14
|
+
|
15
|
+
base_uri "http://example.com"
|
16
|
+
asserts("default options for base_uri") do
|
17
|
+
topic.default_options[:base_uri]
|
18
|
+
end.equals("http://example.com")
|
19
|
+
|
20
|
+
headers({"Content-Type" => "gus/stuff"})
|
21
|
+
asserts("default options headers") do
|
22
|
+
topic.default_options[:headers]
|
23
|
+
end.equals({"Content-Type" => "gus/stuff"})
|
24
|
+
|
25
|
+
cookies({"foo" => "bar"})
|
26
|
+
asserts("default cookies") { topic.default_cookies }.equals({"foo" => "bar"})
|
27
|
+
|
28
|
+
basic_auth "user", "pass"
|
29
|
+
asserts("default options for basic_auth") do
|
30
|
+
topic.default_options[:basic_auth]
|
31
|
+
end.equals({:username => "user", :password => "pass"})
|
32
|
+
|
33
|
+
digest_auth "user", "pass"
|
34
|
+
asserts("default options for digest_auth") do
|
35
|
+
topic.default_options[:digest_auth]
|
36
|
+
end.equals({:username => "user", :password => "pass"})
|
37
|
+
|
38
|
+
http_proxy "http://foo.bar", 10101
|
39
|
+
asserts("default options for http_proxyaddr") do
|
40
|
+
topic.default_options[:http_proxyaddr]
|
41
|
+
end.equals("http://foo.bar")
|
42
|
+
|
43
|
+
asserts("default options for http_proxyport") do
|
44
|
+
topic.default_options[:http_proxyport]
|
45
|
+
end.equals(10101)
|
46
|
+
|
47
|
+
format :json
|
48
|
+
asserts("default options for format") do
|
49
|
+
topic.default_options[:format]
|
50
|
+
end.equals(:json)
|
51
|
+
|
52
|
+
asserts("providing an invalid format") do
|
53
|
+
topic.format :boogers
|
54
|
+
end.raises(HTTParty::UnsupportedFormat, "':boogers' Must be one of: html, json, plain, xml, yaml")
|
55
|
+
|
56
|
+
debug_output StringIO.new
|
57
|
+
asserts("default options for debug_output") do
|
58
|
+
topic.default_options[:debug_output]
|
59
|
+
end.kind_of(StringIO)
|
60
|
+
|
61
|
+
pem "I like cheese"
|
62
|
+
asserts("default options for pem") do
|
63
|
+
topic.default_options[:pem]
|
64
|
+
end.equals("I like cheese")
|
65
|
+
|
66
|
+
asserts("setting custom parser that does not support a provided format") do
|
67
|
+
topic.default_options[:format] = :json
|
68
|
+
topic.parser(
|
69
|
+
Class.new do
|
70
|
+
def supports_format?(fmt) false; end
|
71
|
+
def supported_formats; [:nothing]; end
|
72
|
+
end.new
|
73
|
+
)
|
74
|
+
end.raises(HTTParty::UnsupportedFormat, "':json' Must be one of: nothing")
|
75
|
+
|
76
|
+
context "with a custom parser that supports a provided format" do
|
77
|
+
parser(OpenStruct.new(:supports_format? => true))
|
78
|
+
|
79
|
+
setup { topic.default_options[:parser] }
|
80
|
+
asserts_topic.kind_of(OpenStruct)
|
81
|
+
end # with a custom parser that supports a provided format
|
82
|
+
|
83
|
+
default_timeout 100000
|
84
|
+
asserts("default options for timeout") do
|
85
|
+
topic.default_options[:timeout]
|
86
|
+
end.equals(100000)
|
87
|
+
|
88
|
+
default_params({"foo" => "bar"})
|
89
|
+
asserts("default options for params") do
|
90
|
+
topic.default_options[:default_params]
|
91
|
+
end.equals({"foo" => "bar"})
|
92
|
+
|
93
|
+
no_follow
|
94
|
+
asserts("default options for no_follow") do
|
95
|
+
topic.default_options[:no_follow]
|
96
|
+
end.equals(false)
|
97
|
+
|
98
|
+
maintain_method_across_redirects
|
99
|
+
asserts("default options for maintain_method_across_redirects") do
|
100
|
+
topic.default_options[:maintain_method_across_redirects]
|
101
|
+
end.equals(true)
|
102
|
+
end # A Riot Gear context --- such as this very one :)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'teststrap'
|
2
|
+
|
3
|
+
context "Two distinct gear contexts" do
|
4
|
+
helper(:gear_up) do
|
5
|
+
situation = Riot::Situation.new
|
6
|
+
Riot::Context.new("A") {}.local_run(Riot::SilentReporter.new, situation)
|
7
|
+
situation
|
8
|
+
end
|
9
|
+
|
10
|
+
setup { gear_up.topic }
|
11
|
+
asserts_topic.kind_of(Class)
|
12
|
+
asserts("equivalence of the topic for similar contexts") { topic == gear_up.topic }.not!
|
13
|
+
end # Setting up a gear context
|
14
|
+
|
15
|
+
context "Gear context and its inner context" do
|
16
|
+
helper(:local_run) do |ctx|
|
17
|
+
situation = Riot::Situation.new
|
18
|
+
ctx.local_run(Riot::SilentReporter.new, situation)
|
19
|
+
situation
|
20
|
+
end
|
21
|
+
|
22
|
+
setup { Riot::Context.new("A") {} }
|
23
|
+
|
24
|
+
asserts("equivalence of the topic for similar contexts") do
|
25
|
+
parent_topic = local_run(topic).topic
|
26
|
+
child_topic = local_run(topic.context("B") {}).topic
|
27
|
+
|
28
|
+
parent_topic == child_topic
|
29
|
+
end.not!
|
30
|
+
end # Setting up a gear context
|
data/test/teststrap.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Justin 'Gus' Knowlden
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-06
|
17
|
+
date: 2010-07-06 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -75,7 +75,10 @@ files:
|
|
75
75
|
- lib/riot/gear/middleware.rb
|
76
76
|
- lib/riot/gear/middleware/riotparty.rb
|
77
77
|
- riot-gear.gemspec
|
78
|
+
- test/helpers/cookie_values_test.rb
|
78
79
|
- test/helpers/json_path_test.rb
|
80
|
+
- test/riotparty_proxy_methods_test.rb
|
81
|
+
- test/setting_up_gear_context_test.rb
|
79
82
|
- test/teststrap.rb
|
80
83
|
has_rdoc: true
|
81
84
|
homepage: http://github.com/thumblemonks/riot-gear
|
@@ -108,5 +111,8 @@ signing_key:
|
|
108
111
|
specification_version: 3
|
109
112
|
summary: Riot + HTTParty smoke testing framework
|
110
113
|
test_files:
|
114
|
+
- test/helpers/cookie_values_test.rb
|
111
115
|
- test/helpers/json_path_test.rb
|
116
|
+
- test/riotparty_proxy_methods_test.rb
|
117
|
+
- test/setting_up_gear_context_test.rb
|
112
118
|
- test/teststrap.rb
|