riot-gear 0.0.1

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.
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ .bundle/*
3
+ *.tmproj
4
+ pkg/*
@@ -0,0 +1,15 @@
1
+ # Riot Gear
2
+
3
+ Real HTTP-based smoke testing with a real testing framework; [Riot](http://thumblemonks.github.com/riot) + [HTTParty]().
4
+
5
+ require 'testsrap'
6
+
7
+ context "Logging into Example.com as foo" do
8
+ base_uri "http://example.com"
9
+ post "/session/new", :body => {:username => "foo", :password => "password"}
10
+
11
+ asserts_status.equals(200)
12
+ asserts_header("Content-Type").equals("application/json;charset=utf-8")
13
+ end # Logging into BrightTag as bgrande
14
+
15
+ Lots lots more to come soon.
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ #
5
+ # Some monks like diamonds. I like gems.
6
+
7
+ begin
8
+ require 'jeweler'
9
+ Jeweler::Tasks.new do |gem|
10
+ gem.name = "riot-gear"
11
+ gem.summary = "Riot + HTTParty smoke testing framework"
12
+ gem.description = "Riot + HTTParty smoke testing framework. You'd use it for integration testing with real HTTP requests and responses"
13
+ gem.email = "gus@gusg.us"
14
+ gem.homepage = "http://github.com/thumblemonks/riot-gear"
15
+ gem.authors = ["Justin 'Gus' Knowlden"]
16
+ gem.add_dependency 'riot'
17
+ gem.add_dependency 'httparty'
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
22
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,3 @@
1
+ require 'riot'
2
+ require 'riot/gear/context'
3
+ require 'riot/gear/middleware'
@@ -0,0 +1,4 @@
1
+ require 'riot/gear/context/http'
2
+ require 'riot/gear/context/asserts_status'
3
+ require 'riot/gear/context/asserts_header'
4
+ require 'riot/gear/context/asserts_json'
@@ -0,0 +1,15 @@
1
+ require 'open-uri'
2
+
3
+ module SmokeMonster
4
+ module Riot
5
+ module AssertsHeader
6
+
7
+ def asserts_header(header_key)
8
+ asserts("header variable #{header_key}") { response.headers[header_key] }
9
+ end
10
+
11
+ end # Context
12
+ end # Riot
13
+ end # SmokeMonster
14
+
15
+ Riot::Context.instance_eval { include SmokeMonster::Riot::AssertsHeader }
@@ -0,0 +1,16 @@
1
+ require 'open-uri'
2
+
3
+ module SmokeMonster
4
+ module Riot
5
+ module AssertsJson
6
+
7
+ def asserts_json(json_path)
8
+ asserts("value from body as json:#{json_path}") do
9
+ json_path(response, json_path)
10
+ end
11
+ end
12
+ end # Context
13
+ end # Riot
14
+ end # SmokeMonster
15
+
16
+ Riot::Context.instance_eval { include SmokeMonster::Riot::AssertsJson }
@@ -0,0 +1,15 @@
1
+ require 'open-uri'
2
+
3
+ module SmokeMonster
4
+ module Riot
5
+ module AssertsStatus
6
+
7
+ def asserts_status
8
+ asserts("status code") { response.code }
9
+ end
10
+
11
+ end # Context
12
+ end # Riot
13
+ end # SmokeMonster
14
+
15
+ Riot::Context.instance_eval { include SmokeMonster::Riot::AssertsStatus }
@@ -0,0 +1,22 @@
1
+ require 'open-uri'
2
+ require 'httparty'
3
+
4
+ module SmokeMonster
5
+ module Riot
6
+ module Http
7
+
8
+ # Setup the scenario via a GET requst to the provided path. Feel free to include a query string
9
+ def get(*args)
10
+ hookup { @smoke_response = topic.get(*args) }
11
+ end
12
+
13
+ def persist_cookie(cookie_name)
14
+ hookup do
15
+ topic.cookies({cookie_name => cookie_values[cookie_name]})
16
+ end
17
+ end
18
+ end # Context
19
+ end # Riot
20
+ end # SmokeMonster
21
+
22
+ Riot::Context.instance_eval { include SmokeMonster::Riot::Http }
@@ -0,0 +1 @@
1
+ require 'riot/gear/middleware/riotparty'
@@ -0,0 +1,86 @@
1
+ require 'httparty'
2
+
3
+ module Riot
4
+ module Gear
5
+ class RiotPartyMiddleware < ::Riot::ContextMiddleware
6
+ register
7
+
8
+ def call(context)
9
+ setup_faux_class(context)
10
+ setup_helpers(context)
11
+ proxy_httparty_hookups(context)
12
+ middleware.call(context)
13
+ end
14
+
15
+ private
16
+
17
+ # Only cluttering anonymous classes with HTTParty stuff. Keeps each context safe from collision ... in
18
+ # theory
19
+ def setup_faux_class(context)
20
+ context.setup(true) do
21
+ Class.new do
22
+ include HTTParty
23
+ # debug_output $stderr
24
+ end
25
+ end
26
+
27
+ context.helper(:response) { @smoke_response }
28
+ end # setup_faux_class
29
+
30
+ def proxy_methods
31
+ HTTParty::ClassMethods.instance_methods - %w[get post put delete head options]
32
+ end
33
+
34
+ # Basically, we're just passing standard HTTParty setup methods onto situation via hookups. Except
35
+ # for the important action methods.
36
+ def proxy_httparty_hookups(context)
37
+ proxy_methods.each do |httparty_method|
38
+ (class << context; self; end).__send__(:define_method, httparty_method) do |*args|
39
+ hookup do
40
+ topic.__send__(httparty_method, *args)
41
+ end
42
+ end
43
+ end # proxy_methods.each
44
+ end # proxy_httparty_hookups
45
+
46
+ def setup_helpers(context)
47
+ helper_json_path(context)
48
+ helper_cookie_value(context)
49
+ end
50
+
51
+ # Maps a JSON string to a Hash tree. For instance, give this hash:
52
+ #
53
+ # json_object = {"a" => {"b" => "c" => {"d" => "foo"}}}
54
+ #
55
+ # You could retrieve the value of 'd' via JSON notation in any of the following ways:
56
+ #
57
+ # json_path(json_object, "a.b.c.d")
58
+ # => "foo"
59
+ # json_path(json_object, "a['b'].c['d']")
60
+ # => "foo"
61
+ #
62
+ # You can even work with array indexes.
63
+ # json_object = {"a" => {"b" => "c" => ["foo", {"d" => "bar"}]}}
64
+ # json_path(json_object, "a.b.c[1].d")
65
+ # => "bar"
66
+ def helper_json_path(context)
67
+ context.helper(:json_path) do |dictionary, path|
68
+ path.scan(/\w+|\d+/).inject(dictionary) do |dict,key|
69
+ dict[key =~ /^\d+$/ ? key.to_i : key]
70
+ end
71
+ end
72
+ end
73
+
74
+ def helper_cookie_value(context)
75
+ context.helper(:cookie_values) do
76
+ response.header["set-cookie"].split(';').inject({}) do |hash, key_val|
77
+ key, val = key_val.strip.split('=')
78
+ hash[key] = val
79
+ hash
80
+ end
81
+ end
82
+ end
83
+
84
+ end # Middleware
85
+ end # Gear
86
+ end # Riot
@@ -0,0 +1,55 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{riot-gear}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Justin 'Gus' Knowlden"]
12
+ s.date = %q{2010-06-23}
13
+ s.description = %q{Riot + HTTParty smoke testing framework. You'd use it for integration testing with real HTTP requests and responses}
14
+ s.email = %q{gus@gusg.us}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "README.md",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "lib/riot/gear.rb",
24
+ "lib/riot/gear/context.rb",
25
+ "lib/riot/gear/context/asserts_header.rb",
26
+ "lib/riot/gear/context/asserts_json.rb",
27
+ "lib/riot/gear/context/asserts_status.rb",
28
+ "lib/riot/gear/context/http.rb",
29
+ "lib/riot/gear/middleware.rb",
30
+ "lib/riot/gear/middleware/riotparty.rb",
31
+ "riot-gear.gemspec"
32
+ ]
33
+ s.homepage = %q{http://github.com/thumblemonks/riot-gear}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.6}
37
+ s.summary = %q{Riot + HTTParty smoke testing framework}
38
+
39
+ if s.respond_to? :specification_version then
40
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<riot>, [">= 0"])
45
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
46
+ else
47
+ s.add_dependency(%q<riot>, [">= 0"])
48
+ s.add_dependency(%q<httparty>, [">= 0"])
49
+ end
50
+ else
51
+ s.add_dependency(%q<riot>, [">= 0"])
52
+ s.add_dependency(%q<httparty>, [">= 0"])
53
+ end
54
+ end
55
+
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: riot-gear
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Justin 'Gus' Knowlden
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-06-23 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: riot
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: httparty
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :runtime
43
+ version_requirements: *id002
44
+ description: Riot + HTTParty smoke testing framework. You'd use it for integration testing with real HTTP requests and responses
45
+ email: gus@gusg.us
46
+ executables: []
47
+
48
+ extensions: []
49
+
50
+ extra_rdoc_files:
51
+ - README.md
52
+ files:
53
+ - .gitignore
54
+ - README.md
55
+ - Rakefile
56
+ - VERSION
57
+ - lib/riot/gear.rb
58
+ - lib/riot/gear/context.rb
59
+ - lib/riot/gear/context/asserts_header.rb
60
+ - lib/riot/gear/context/asserts_json.rb
61
+ - lib/riot/gear/context/asserts_status.rb
62
+ - lib/riot/gear/context/http.rb
63
+ - lib/riot/gear/middleware.rb
64
+ - lib/riot/gear/middleware/riotparty.rb
65
+ - riot-gear.gemspec
66
+ has_rdoc: true
67
+ homepage: http://github.com/thumblemonks/riot-gear
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options:
72
+ - --charset=UTF-8
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.3.6
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Riot + HTTParty smoke testing framework
96
+ test_files: []
97
+