Skip to content
Browse files

Touched ... for the very first time

  • Loading branch information...
0 parents commit b13513de8dd15127c836987c2ace30e78b987683 @gus gus committed Jun 23, 2010
4 .gitignore
@@ -0,0 +1,4 @@
+.DS_Store
+.bundle/*
+*.tmproj
+pkg/*
15 README.md
@@ -0,0 +1,15 @@
+# Riot Gear
+
+Real HTTP-based smoke testing with a real testing framework; [Riot](http://thumblemonks.github.com/riot) + [HTTParty]().
+
+ require 'testsrap'
+
+ context "Logging into Example.com as foo" do
+ base_uri "http://example.com"
+ post "/session/new", :body => {:username => "foo", :password => "password"}
+
+ asserts_status.equals(200)
+ asserts_header("Content-Type").equals("application/json;charset=utf-8")
+ end # Logging into BrightTag as bgrande
+
+Lots lots more to come soon.
22 Rakefile
@@ -0,0 +1,22 @@
+require 'rubygems'
+require 'rake'
+
+#
+# Some monks like diamonds. I like gems.
+
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gem|
+ gem.name = "riot-gear"
+ gem.summary = "Riot + HTTParty smoke testing framework"
+ gem.description = "Riot + HTTParty smoke testing framework. You'd use it for integration testing with real HTTP requests and responses"
+ gem.email = "gus@gusg.us"
+ gem.homepage = "http://github.com/thumblemonks/riot-gear"
+ gem.authors = ["Justin 'Gus' Knowlden"]
+ gem.add_dependency 'riot'
+ gem.add_dependency 'httparty'
+ end
+ Jeweler::GemcutterTasks.new
+rescue LoadError
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
+end
1 VERSION
@@ -0,0 +1 @@
+0.0.1.pre
2 lib/riot/gear.rb
@@ -0,0 +1,2 @@
+require 'riot/gear/context'
+require 'riot/gear/middleware'
4 lib/riot/gear/context.rb
@@ -0,0 +1,4 @@
+require 'riot/gear/context/http'
+require 'riot/gear/context/asserts_status'
+require 'riot/gear/context/asserts_header'
+require 'riot/gear/context/asserts_json'
15 lib/riot/gear/context/asserts_header.rb
@@ -0,0 +1,15 @@
+require 'open-uri'
+
+module SmokeMonster
+ module Riot
+ module AssertsHeader
+
+ def asserts_header(header_key)
+ asserts("header variable #{header_key}") { response.headers[header_key] }
+ end
+
+ end # Context
+ end # Riot
+end # SmokeMonster
+
+Riot::Context.instance_eval { include SmokeMonster::Riot::AssertsHeader }
16 lib/riot/gear/context/asserts_json.rb
@@ -0,0 +1,16 @@
+require 'open-uri'
+
+module SmokeMonster
+ module Riot
+ module AssertsJson
+
+ def asserts_json(json_path)
+ asserts("value from body as json:#{json_path}") do
+ json_path(response, json_path)
+ end
+ end
+ end # Context
+ end # Riot
+end # SmokeMonster
+
+Riot::Context.instance_eval { include SmokeMonster::Riot::AssertsJson }
15 lib/riot/gear/context/asserts_status.rb
@@ -0,0 +1,15 @@
+require 'open-uri'
+
+module SmokeMonster
+ module Riot
+ module AssertsStatus
+
+ def asserts_status
+ asserts("status code") { response.code }
+ end
+
+ end # Context
+ end # Riot
+end # SmokeMonster
+
+Riot::Context.instance_eval { include SmokeMonster::Riot::AssertsStatus }
22 lib/riot/gear/context/http.rb
@@ -0,0 +1,22 @@
+require 'open-uri'
+require 'httparty'
+
+module SmokeMonster
+ module Riot
+ module Http
+
+ # Setup the scenario via a GET requst to the provided path. Feel free to include a query string
+ def get(*args)
+ hookup { @smoke_response = topic.get(*args) }
+ end
+
+ def persist_cookie(cookie_name)
+ hookup do
+ topic.cookies({cookie_name => cookie_values[cookie_name]})
+ end
+ end
+ end # Context
+ end # Riot
+end # SmokeMonster
+
+Riot::Context.instance_eval { include SmokeMonster::Riot::Http }
1 lib/riot/gear/middleware.rb
@@ -0,0 +1 @@
+require 'riot/gear/middleware/riotparty'
86 lib/riot/gear/middleware/riotparty.rb
@@ -0,0 +1,86 @@
+require 'httparty'
+
+module Riot
+ module Gear
+ class RiotPartyMiddleware < ::Riot::ContextMiddleware
+ register
+
+ def call(context)
+ setup_faux_class(context)
+ setup_helpers(context)
+ proxy_httparty_hookups(context)
+ middleware.call(context)
+ end
+
+ private
+
+ # Only cluttering anonymous classes with HTTParty stuff. Keeps each context safe from collision ... in
+ # theory
+ def setup_faux_class(context)
+ context.setup(true) do
+ Class.new do
+ include HTTParty
+ # debug_output $stderr
+ end
+ end
+
+ context.helper(:response) { @smoke_response }
+ end # setup_faux_class
+
+ def proxy_methods
+ HTTParty::ClassMethods.instance_methods - %w[get post put delete head options]
+ end
+
+ # Basically, we're just passing standard HTTParty setup methods onto situation via hookups. Except
+ # for the important action methods.
+ def proxy_httparty_hookups(context)
+ proxy_methods.each do |httparty_method|
+ (class << context; self; end).__send__(:define_method, httparty_method) do |*args|
+ hookup do
+ topic.__send__(httparty_method, *args)
+ end
+ end
+ end # proxy_methods.each
+ end # proxy_httparty_hookups
+
+ def setup_helpers(context)
+ helper_json_path(context)
+ helper_cookie_value(context)
+ end
+
+ # Maps a JSON string to a Hash tree. For instance, give this hash:
+ #
+ # json_object = {"a" => {"b" => "c" => {"d" => "foo"}}}
+ #
+ # You could retrieve the value of 'd' via JSON notation in any of the following ways:
+ #
+ # json_path(json_object, "a.b.c.d")
+ # => "foo"
+ # json_path(json_object, "a['b'].c['d']")
+ # => "foo"
+ #
+ # You can even work with array indexes.
+ # json_object = {"a" => {"b" => "c" => ["foo", {"d" => "bar"}]}}
+ # json_path(json_object, "a.b.c[1].d")
+ # => "bar"
+ def helper_json_path(context)
+ context.helper(:json_path) do |dictionary, path|
+ path.scan(/\w+|\d+/).inject(dictionary) do |dict,key|
+ dict[key =~ /^\d+$/ ? key.to_i : key]
+ end
+ end
+ end
+
+ def helper_cookie_value(context)
+ context.helper(:cookie_values) do
+ response.header["set-cookie"].split(';').inject({}) do |hash, key_val|
+ key, val = key_val.strip.split('=')
+ hash[key] = val
+ hash
+ end
+ end
+ end
+
+ end # Middleware
+ end # Gear
+end # Riot
40 riot-gear.gemspec
@@ -0,0 +1,40 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{riot-gear}
+ s.version = "0.0.1.pre"
+
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Justin 'Gus' Knowlden"]
+ s.date = %q{2010-06-23}
+ s.description = %q{Riot + HTTParty smoke testing framework. You'd use it for integration testing with real HTTP requests and responses}
+ s.email = %q{gus@gusg.us}
+ s.extra_rdoc_files = [
+ "README.md"
+ ]
+ s.homepage = %q{http://github.com/thumblemonks/riot-gear}
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.3.6}
+ s.summary = %q{Riot + HTTParty smoke testing framework}
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ s.add_runtime_dependency(%q<riot>, [">= 0"])
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
+ else
+ s.add_dependency(%q<riot>, [">= 0"])
+ s.add_dependency(%q<httparty>, [">= 0"])
+ end
+ else
+ s.add_dependency(%q<riot>, [">= 0"])
+ s.add_dependency(%q<httparty>, [">= 0"])
+ end
+end
+

0 comments on commit b13513d

Please sign in to comment.
Something went wrong with that request. Please try again.