messiah 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.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.log
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Rich Cavanaugh
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,21 @@
1
+ = Messiah
2
+
3
+ Messiah enables using Ruby testing tools for integration testing with platforms that support CGI. Notably, PHP.
4
+
5
+ == Configuration: RSpec
6
+
7
+ In the spec_helper.rb file, configure Messiah. Specifically, the app root and the command used to execute your app via CGI. Once the app is configured, include Messiah into RSpec.
8
+
9
+ Messiah.configure do
10
+ root File.join(File.dirname(__FILE__), 'fixtures', 'www')
11
+ command 'php-cgi -d cgi.force_redirect=0'
12
+ end
13
+
14
+ Spec::Runner.configure do |config|
15
+ include Messiah::RSpec
16
+ end
17
+
18
+ == Copyright
19
+
20
+ Copyright (c) 2009 Rich Cavanaugh. See LICENSE for details.
21
+
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ begin
2
+ require 'jeweler'
3
+
4
+ Jeweler::Tasks.new do |gemspec|
5
+ gemspec.name = "messiah"
6
+ gemspec.summary = "The beauty of Ruby integration tests for PHP"
7
+ gemspec.description = "Messiah enables using Ruby testing tools for integration testing with platforms that support CGI. Notably, PHP."
8
+ gemspec.email = "rich@withoutscope.com"
9
+ gemspec.homepage = "http://github.com/rich/messiah"
10
+ gemspec.authors = ["Rich Cavanaugh"]
11
+
12
+ gemspec.add_dependency('webrat')
13
+ gemspec.add_dependency('rack')
14
+ gemspec.add_dependency('rack-test')
15
+ end
16
+
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler not available. Install it with: sudo gem install jeweler"
20
+ end
data/TODO ADDED
@@ -0,0 +1,5 @@
1
+ documentation
2
+
3
+ properly integrate magic_models so it doesn't always load with messiah itself
4
+ integrate the database handling callbacks and factory_girl
5
+ integrate rubigen for getting an app working with messiah
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,13 @@
1
+ module Messiah::Common
2
+ def self.included(base)
3
+ base.send(:include, Webrat::Methods)
4
+ base.send(:include, Rack::Test::Methods)
5
+ base.send(:include, Webrat::Matchers)
6
+ end
7
+
8
+ def app
9
+ Rack::Builder.new {
10
+ run Messiah::RackCGIApp.new
11
+ }
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ class Messiah::Config
2
+ attr_accessor :values
3
+
4
+ def respond_to?(key)
5
+ true
6
+ end
7
+
8
+ def method_missing(key, *val, &block)
9
+ @values ||= {}
10
+ if val.first || block
11
+ @values[key.to_s.gsub(/=/, '')] = val.first || block
12
+ else
13
+ @values[key.to_s]
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,43 @@
1
+ class Messiah::RackCGIApp
2
+ def call(env)
3
+ add_to_environment!(env)
4
+ header_string, body = call_cgi(env)
5
+ headers, status = parse_headers(header_string)
6
+ [status, headers, [body]]
7
+ end
8
+
9
+ def add_to_environment!(env)
10
+ env['HTTP_HOST'] = Messiah.host
11
+ env['DOCUMENT_ROOT'] = Messiah.root
12
+ env['SCRIPT_NAME'] = (Messiah.script || env['PATH_INFO']).gsub(/^\//, '')
13
+ env['SCRIPT_FILENAME'] = env['PATH_TRANSLATED'] = File.join(env['DOCUMENT_ROOT'], env['SCRIPT_NAME'])
14
+ end
15
+
16
+ def build_environment_string(env)
17
+ env.inject([]) do |a, item|
18
+ a << "#{item.first}=\"#{item.last}\""
19
+ a
20
+ end.join(' ')
21
+ end
22
+
23
+ def call_cgi(env)
24
+ env_string = build_environment_string(env)
25
+
26
+ stdin, stdout, stderr = Open3.popen3("env #{env_string} #{Messiah.command}")
27
+ stdin.write env['rack.input'].read if env['REQUEST_METHOD'] == 'POST'
28
+ stdin.close
29
+
30
+ stdout.read.split("\n\r", 2)
31
+ end
32
+
33
+ def parse_headers(header)
34
+ headers = header.split("\n").inject({}) do |h, line|
35
+ key, val = line.split(':').map(&:strip)
36
+ h[key] = val
37
+ h
38
+ end
39
+ status = headers.delete('Status') || 200
40
+
41
+ [headers, status]
42
+ end
43
+ end
@@ -0,0 +1,7 @@
1
+ require "spec"
2
+
3
+ module Messiah::RSpec
4
+ def self.included(base)
5
+ base.send(:include, Messiah::Common)
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require "test/unit/assertions"
2
+
3
+ module Messiah::TestUnit
4
+ def self.included(base)
5
+ base.send(:include, Messiah::Common)
6
+ end
7
+ end
data/lib/messiah.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'webrat'
2
+ require 'rack/request'
3
+ require 'rack/response'
4
+ require "rack/test"
5
+ require 'open3'
6
+
7
+ module Messiah
8
+ autoload :RSpec, 'messiah/rspec'
9
+ autoload :TestUnit, 'messiah/test_unit'
10
+ autoload :RackCGIApp, 'messiah/rack_cgi_app'
11
+ autoload :Common, 'messiah/common'
12
+ autoload :Config, 'messiah/config'
13
+
14
+ class << self
15
+ attr_accessor :config
16
+
17
+ def configure(&block)
18
+ @config ||= Config.new
19
+ @config.instance_eval(&block)
20
+ end
21
+
22
+ def method_missing(key, *args, &block)
23
+ @config.send(key, *args, &block)
24
+ end
25
+ end
26
+ end
27
+
28
+ Webrat.configure do |config|
29
+ config.mode = :rack
30
+ end
@@ -0,0 +1,4 @@
1
+ <?php
2
+ echo "another page";
3
+ echo "Hello " . $_COOKIE['a-cookie'];
4
+ ?>
@@ -0,0 +1 @@
1
+ arrived
@@ -0,0 +1,4 @@
1
+ <form action="/process.php" method="POST">
2
+ <input type="text" name="name">
3
+ <input type="submit" name="Submit" value="Submit">
4
+ </form>
@@ -0,0 +1 @@
1
+ <?php echo "Your name is " . $_GET['first_name'] . ' ' . $_GET['last_name']; ?>
@@ -0,0 +1,7 @@
1
+ <?php
2
+ echo $_SERVER['HTTP_NOPE'];
3
+ setcookie('a-cookie', 'thing');
4
+ echo "Hello";
5
+ echo "Host is " . $_SERVER['HTTP_HOST'];
6
+ ?>
7
+ <a href="/another.php">Click Me</a>
@@ -0,0 +1,3 @@
1
+ <?php
2
+ echo "Your name is " . $_POST['name'];
3
+ ?>
@@ -0,0 +1,3 @@
1
+ <?php
2
+ header("Location: /destination.php");
3
+ ?>
@@ -0,0 +1 @@
1
+ <?php print_r($_FILES); ?>
@@ -0,0 +1,6 @@
1
+ <form action="/uploaded.php" method="post">
2
+ <label>
3
+ File <input type="file" name="uploaded_file" />
4
+ </label>
5
+ <input type="submit" value="Upload">
6
+ </form>
@@ -0,0 +1,28 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Messiah::Config do
4
+ let(:config) {Messiah::Config.new}
5
+
6
+ it "responds to any method name" do
7
+ config.should respond_to(:foo)
8
+ end
9
+
10
+ it "accepts setters by any name" do
11
+ lambda {config.foo = 10}.should_not raise_error
12
+ end
13
+
14
+ it "remembers values for any of it's previous assignments" do
15
+ config.foo 10
16
+ config.foo.should == 10
17
+ end
18
+
19
+ it "removes equal signs from the keys of setters" do
20
+ config.foo = 10
21
+ config.foo.should == 10
22
+ end
23
+
24
+ it "accepts blocks as values" do
25
+ config.foo {10}
26
+ config.foo.call.should == 10
27
+ end
28
+ end
@@ -0,0 +1,81 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Messiah" do
4
+ let(:body) {last_response.body}
5
+
6
+ def visit(url)
7
+ u = url =~ /^\// ? url : "/#{url}"
8
+ super(u)
9
+ end
10
+
11
+ def host(val)
12
+ Messiah.config.host val
13
+ end
14
+
15
+ before(:each) do
16
+ host "example.dev"
17
+ end
18
+
19
+ it "should accept headers" do
20
+ header "NOPE", "woohoo"
21
+ visit "index.php"
22
+ body.should contain("woohoo")
23
+ end
24
+
25
+ it "visits the page" do
26
+ request("index.php").should be_ok
27
+ end
28
+
29
+ it "doesn't respond positively to unknown files" do
30
+ request("nope.php").should_not be_ok
31
+ end
32
+
33
+ it "clicks a link" do
34
+ visit "index.php"
35
+ click_link "Click Me"
36
+ body.should contain "another page"
37
+ end
38
+
39
+ it "handles cookies properly" do
40
+ visit "index.php"
41
+ click_link "Click Me"
42
+ body.should contain "Hello thing"
43
+ end
44
+
45
+ it "handles redirects" do
46
+ visit "redirector.php"
47
+ body.should contain "arrived"
48
+ end
49
+
50
+ it "sets the host dynamically" do
51
+ host "example-two.dev"
52
+ visit "index.php"
53
+ body.should contain "Host is example-two.dev"
54
+ end
55
+
56
+ it "sets the host statically" do
57
+ visit "index.php"
58
+ body.should contain "Host is example.dev"
59
+ end
60
+
61
+ it "handles post variables" do
62
+ visit "form.php"
63
+ fill_in "name", :with => 'Rich'
64
+ click_button "Submit"
65
+ body.should contain "Your name is Rich"
66
+ end
67
+
68
+ it "handles get variables" do
69
+ visit "get_vars.php?first_name=Rich&last_name=Cavanaugh"
70
+ body.should contain "Your name is Rich Cavanaugh"
71
+ end
72
+
73
+ it "handles file uploads" do
74
+ visit "uploader.php"
75
+ attach_file "File", __FILE__, "text/ruby"
76
+ click_button "Upload"
77
+ body.should contain "[uploaded_file]"
78
+ end
79
+
80
+ end
81
+
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'messiah'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Messiah.configure do
8
+ root File.join(File.dirname(__FILE__), 'fixtures', 'www')
9
+ command 'php-cgi -d cgi.force_redirect=0'
10
+ end
11
+
12
+ Spec::Runner.configure do |config|
13
+ include Messiah::RSpec
14
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: messiah
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rich Cavanaugh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-10 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: webrat
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rack
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rack-test
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ description: Messiah enables using Ruby testing tools for integration testing with platforms that support CGI. Notably, PHP.
46
+ email: rich@withoutscope.com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - LICENSE
53
+ - README.rdoc
54
+ - TODO
55
+ files:
56
+ - .gitignore
57
+ - LICENSE
58
+ - README.rdoc
59
+ - Rakefile
60
+ - TODO
61
+ - VERSION
62
+ - lib/messiah.rb
63
+ - lib/messiah/common.rb
64
+ - lib/messiah/config.rb
65
+ - lib/messiah/rack_cgi_app.rb
66
+ - lib/messiah/rspec.rb
67
+ - lib/messiah/test_unit.rb
68
+ - spec/fixtures/www/another.php
69
+ - spec/fixtures/www/destination.php
70
+ - spec/fixtures/www/form.php
71
+ - spec/fixtures/www/get_vars.php
72
+ - spec/fixtures/www/index.php
73
+ - spec/fixtures/www/process.php
74
+ - spec/fixtures/www/redirector.php
75
+ - spec/fixtures/www/uploaded.php
76
+ - spec/fixtures/www/uploader.php
77
+ - spec/messiah_config_spec.rb
78
+ - spec/messiah_spec.rb
79
+ - spec/spec.opts
80
+ - spec/spec_helper.rb
81
+ has_rdoc: true
82
+ homepage: http://github.com/rich/messiah
83
+ licenses: []
84
+
85
+ post_install_message:
86
+ rdoc_options:
87
+ - --charset=UTF-8
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ version:
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: "0"
101
+ version:
102
+ requirements: []
103
+
104
+ rubyforge_project:
105
+ rubygems_version: 1.3.5
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: The beauty of Ruby integration tests for PHP
109
+ test_files:
110
+ - spec/messiah_config_spec.rb
111
+ - spec/messiah_spec.rb
112
+ - spec/spec_helper.rb