messiah 0.1.0 → 0.9.0
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 +4 -1
- data/README.rdoc +39 -8
- data/Rakefile +4 -0
- data/TODO +1 -0
- data/VERSION +1 -1
- data/bin/messiah-generator +5 -0
- data/lib/messiah.rb +54 -11
- data/lib/messiah/config.rb +1 -1
- data/lib/messiah/configurator.rb +57 -0
- data/lib/messiah/generator.rb +21 -0
- data/lib/messiah/generator/application.rb +19 -0
- data/lib/messiah/generator/cucumber.rb +2 -0
- data/lib/messiah/generator/options.rb +38 -0
- data/lib/messiah/generator/rspec.rb +12 -0
- data/lib/messiah/generator/test_unit.rb +2 -0
- data/lib/messiah/rack.rb +3 -0
- data/lib/messiah/{rack_cgi_app.rb → rack/cgi.rb} +6 -5
- data/lib/messiah/supports/code_igniter.php +8 -0
- data/lib/messiah/supports/code_igniter.rb +33 -0
- data/lib/messiah/{common.rb → supports/common.rb} +3 -3
- data/lib/messiah/supports/cucumber.rb +5 -0
- data/lib/messiah/supports/rspec.rb +17 -0
- data/lib/messiah/supports/test_unit.rb +5 -0
- data/lib/messiah/templates/cucumber/features/messiah.feature +9 -0
- data/lib/messiah/templates/cucumber/features/step_definitions/web_steps.rb +243 -0
- data/lib/messiah/templates/cucumber/features/support/env.rb +19 -0
- data/lib/messiah/templates/cucumber/features/support/paths.rb +13 -0
- data/lib/messiah/templates/rspec/spec/spec_helper.rbt +14 -0
- data/spec/fixtures/www/env.php +7 -0
- data/spec/messiah_spec.rb +37 -10
- data/spec/spec.opts +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +102 -23
- data/lib/messiah/rspec.rb +0 -7
- data/lib/messiah/test_unit.rb +0 -7
data/.gitignore
CHANGED
data/README.rdoc
CHANGED
@@ -10,16 +10,47 @@ Messiah enables using Ruby testing tools for integration testing with platforms
|
|
10
10
|
|
11
11
|
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.
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
Messiah.configure do
|
14
|
+
root File.join(File.dirname(__FILE__), 'fixtures', 'www')
|
15
|
+
command 'php-cgi -d cgi.force_redirect=0'
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
Spec::Runner.configure do |config|
|
19
|
+
Messiah.rspec(config)
|
20
|
+
end
|
21
|
+
|
22
|
+
== Configuration: Cucumber
|
23
|
+
|
24
|
+
You configure Messiah in the env.rb file.
|
25
|
+
|
26
|
+
Messiah.configure do
|
27
|
+
root File.join(File.dirname(__FILE__), '..', '..', 'spec', 'fixtures', 'www')
|
28
|
+
command 'php-cgi -d cgi.force_redirect=0'
|
29
|
+
end
|
30
|
+
|
31
|
+
Messiah.cucumber(self)
|
32
|
+
|
33
|
+
== Other Configuration Options
|
34
|
+
|
35
|
+
+test_root+ is the directory containing the test suite being run. This is passed to your application through an HTTP header. This can be used to source mocks from the fixtures directory.
|
36
|
+
+app_root+ is the directory that actually contains your application.
|
37
|
+
+host+ is the hostname that should be used in the requests.
|
38
|
+
+script+ is the name of the script all requests should be sent through. This is useful if your app uses PATH_INFO
|
39
|
+
+database+ is a hash containing the ActiveRecord connection parameters
|
40
|
+
|
41
|
+
Any of the options may be set simply:
|
42
|
+
|
43
|
+
Messiah.host = 'ahost.example.local'
|
44
|
+
|
45
|
+
The configuration values are automatically reset back to their original configured state prior to every test. This is useful if you need to test different hosts individually.
|
46
|
+
|
47
|
+
== Database Support and a Warning
|
48
|
+
|
49
|
+
Messiah will, by default, delete all data in the configured test database. Don't point it at your development database. This is to be sure the database is always starting with a known blank slate.
|
50
|
+
|
51
|
+
The database support is functional but still has rough edges. It uses Dr. Nic's Magic Models gem for generating ActiveRecord models from your schema at runtime. factory_girl is the factory library used. Additional documentation is coming on the database support.
|
21
52
|
|
22
53
|
== Copyright
|
23
54
|
|
24
|
-
Copyright (c)
|
55
|
+
Copyright (c) 2010 Rich Cavanaugh. See LICENSE for details.
|
25
56
|
|
data/Rakefile
CHANGED
@@ -12,6 +12,10 @@ begin
|
|
12
12
|
gemspec.add_dependency('webrat')
|
13
13
|
gemspec.add_dependency('rack')
|
14
14
|
gemspec.add_dependency('rack-test')
|
15
|
+
gemspec.add_dependency('activerecord')
|
16
|
+
gemspec.add_dependency('factory_girl')
|
17
|
+
gemspec.add_dependency('dr_nic_magic_models')
|
18
|
+
gemspec.add_dependency('database_cleaner')
|
15
19
|
end
|
16
20
|
|
17
21
|
Jeweler::GemcutterTasks.new
|
data/TODO
CHANGED
@@ -3,3 +3,4 @@
|
|
3
3
|
properly integrate magic_models so it doesn't always load with messiah itself
|
4
4
|
integrate the database handling callbacks and factory_girl
|
5
5
|
integrate rubigen for getting an app working with messiah
|
6
|
+
look at using the database_cleaner gem http://github.com/bmabey/database_cleaner/
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.9.0
|
data/lib/messiah.rb
CHANGED
@@ -4,27 +4,70 @@ require 'rack/response'
|
|
4
4
|
require "rack/test"
|
5
5
|
require 'open3'
|
6
6
|
|
7
|
+
unless defined?(RAILS_DEFAULT_LOGGER)
|
8
|
+
RAILS_DEFAULT_LOGGER = Logger.new(StringIO.new)
|
9
|
+
end
|
10
|
+
|
7
11
|
module Messiah
|
8
|
-
autoload :
|
9
|
-
autoload :
|
10
|
-
autoload :
|
11
|
-
autoload :
|
12
|
-
autoload :
|
12
|
+
autoload :Rack, 'messiah/rack'
|
13
|
+
autoload :Common, 'messiah/common'
|
14
|
+
autoload :Config, 'messiah/config'
|
15
|
+
autoload :Configurator, 'messiah/configurator'
|
16
|
+
autoload :Generator, 'messiah/generator'
|
17
|
+
|
18
|
+
module Supports
|
19
|
+
autoload :Common, 'messiah/supports/common'
|
20
|
+
autoload :RSpec, 'messiah/supports/rspec'
|
21
|
+
autoload :Cucumber, 'messiah/supports/cucumber'
|
22
|
+
autoload :TestUnit, 'messiah/supports/test_unit'
|
23
|
+
autoload :CodeIgniter,'messiah/supports/code_igniter'
|
24
|
+
end
|
25
|
+
|
26
|
+
VERSION = File.read(File.join(File.dirname(__FILE__), '..', 'VERSION'))
|
13
27
|
|
14
28
|
class << self
|
15
|
-
attr_accessor :config
|
29
|
+
attr_accessor :config, :frozen_config
|
16
30
|
|
17
31
|
def configure(&block)
|
18
32
|
@config ||= Config.new
|
19
33
|
@config.instance_eval(&block)
|
34
|
+
|
35
|
+
Configurator.configure!(@config)
|
20
36
|
end
|
21
|
-
|
37
|
+
|
22
38
|
def method_missing(key, *args, &block)
|
23
39
|
@config.send(key, *args, &block)
|
24
40
|
end
|
41
|
+
|
42
|
+
def freeze_config!
|
43
|
+
@frozen_config = @config.values.clone
|
44
|
+
end
|
45
|
+
|
46
|
+
def reset_config!
|
47
|
+
@config.values = @frozen_config.clone
|
48
|
+
end
|
49
|
+
|
50
|
+
def rspec(config)
|
51
|
+
config.before(:suite, &Messiah.method(:before_suite))
|
52
|
+
config.before(:each, &Messiah.method(:before_test))
|
53
|
+
config.after(:each, &Messiah.method(:after_test))
|
54
|
+
end
|
55
|
+
|
56
|
+
def cucumber(world)
|
57
|
+
world.AfterConfiguration(&Messiah.method(:before_suite))
|
58
|
+
world.Before(&Messiah.method(:before_test))
|
59
|
+
end
|
60
|
+
|
61
|
+
def before_suite(*args)
|
62
|
+
Messiah.freeze_config!
|
63
|
+
end
|
64
|
+
|
65
|
+
def before_test(*args)
|
66
|
+
Messiah.reset_config!
|
67
|
+
DatabaseCleaner.clean if Messiah.database
|
68
|
+
end
|
69
|
+
|
70
|
+
def after_test(*args)
|
71
|
+
end
|
25
72
|
end
|
26
73
|
end
|
27
|
-
|
28
|
-
Webrat.configure do |config|
|
29
|
-
config.mode = :rack
|
30
|
-
end
|
data/lib/messiah/config.rb
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
class Messiah::Configurator
|
2
|
+
def initialize(config)
|
3
|
+
@config = config
|
4
|
+
configure_framework
|
5
|
+
configure_world
|
6
|
+
configure_webrat
|
7
|
+
configure_database if @config.database
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.configure!(config)
|
11
|
+
new(config)
|
12
|
+
end
|
13
|
+
|
14
|
+
def configure_framework
|
15
|
+
@framwork = case @config.framework
|
16
|
+
when :code_igniter
|
17
|
+
Messiah::Supports::CodeIgniter.new(@config)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def configure_webrat
|
22
|
+
Webrat.configure do |config|
|
23
|
+
config.mode = :rack
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def configure_world
|
28
|
+
Spec::Example::ExampleGroup.send(:include, Messiah::Supports::RSpec) if rspec?
|
29
|
+
Object.send(:include, Messiah::Supports::Cucumber) if cucumber?
|
30
|
+
Object.send(:include, Messiah::Supports::TestUnit) if test_unit?
|
31
|
+
end
|
32
|
+
|
33
|
+
def configure_database
|
34
|
+
require 'active_record'
|
35
|
+
ActiveRecord::Base.establish_connection(@config.database)
|
36
|
+
|
37
|
+
require 'dr_nic_magic_models'
|
38
|
+
DrNicMagicModels.extend_module_class!
|
39
|
+
DrNicMagicModels::Schema.new(Object).load_schema
|
40
|
+
|
41
|
+
require 'factory_girl'
|
42
|
+
require 'database_cleaner'
|
43
|
+
DatabaseCleaner.strategy = :truncation
|
44
|
+
end
|
45
|
+
|
46
|
+
def rspec?
|
47
|
+
defined?(Spec::Example::ExampleGroup)
|
48
|
+
end
|
49
|
+
|
50
|
+
def cucumber?
|
51
|
+
defined?(Cucumber)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_unit?
|
55
|
+
defined?(Test::Unit)
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'templater'
|
2
|
+
|
3
|
+
module Messiah::Generator
|
4
|
+
extend Templater::Manifold
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def template_path
|
8
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
autoload :Cucumber, 'messiah/generator/cucumber'
|
13
|
+
autoload :RSpec, 'messiah/generator/rspec'
|
14
|
+
autoload :TestUnit, 'messiah/generator/test_unit'
|
15
|
+
|
16
|
+
add :cucumber, Cucumber
|
17
|
+
add :rspec, RSpec
|
18
|
+
add :test_unit, TestUnit
|
19
|
+
|
20
|
+
desc "Setup a testing framework supported by Messiah in the current directory."
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Messiah::Generator::Application
|
2
|
+
def self.run!(*args)
|
3
|
+
options = Messiah::Generator::Options.new(args)
|
4
|
+
|
5
|
+
if options[:invalid_argument]
|
6
|
+
$stderr.puts options[:invalid_argument]
|
7
|
+
options[:show_help] = true
|
8
|
+
end
|
9
|
+
|
10
|
+
if options[:show_help]
|
11
|
+
$stderr.puts options.opts
|
12
|
+
return 1
|
13
|
+
end
|
14
|
+
|
15
|
+
generator = Messiah::Generator.new(options)
|
16
|
+
generator.run!
|
17
|
+
return 0
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
class Messiah::Generator::Options < Hash
|
4
|
+
attr_reader :opts
|
5
|
+
|
6
|
+
def initialize(args)
|
7
|
+
super()
|
8
|
+
|
9
|
+
@opts = OptionParser.new do |o|
|
10
|
+
o.banner = "Usage: #{File.basename($0)} options\ne.g. #{File.basename($0)} --rspec --cucumber"
|
11
|
+
|
12
|
+
o.on('--rspec', 'generate rspec support files') do
|
13
|
+
self[:rspec] = true
|
14
|
+
end
|
15
|
+
|
16
|
+
o.on('--cucumber', 'generate cucumber support files') do
|
17
|
+
self[:cucumber] = true
|
18
|
+
end
|
19
|
+
|
20
|
+
o.on('--testunit', 'generate testunit support files') do
|
21
|
+
self[:testunit] = true
|
22
|
+
end
|
23
|
+
|
24
|
+
o.separator ""
|
25
|
+
|
26
|
+
o.on_tail('-h', '--help', 'display this help and exit') do
|
27
|
+
self[:show_help] = true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
begin
|
32
|
+
@opts.parse!(args)
|
33
|
+
self[:directory] = args.shift || Dir.pwd
|
34
|
+
rescue OptionParser::InvalidOption => e
|
35
|
+
self[:invalid_argument] = e.message
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Messiah::Generator::RSpec < Templater::Generator
|
2
|
+
def self.source_root
|
3
|
+
File.join(Messiah::Generator.template_path, 'rspec')
|
4
|
+
end
|
5
|
+
|
6
|
+
first_argument :root, :default => '.'
|
7
|
+
second_argument :command, :default => 'php-cgi -d cgi.force_redirect=0'
|
8
|
+
third_argument :script
|
9
|
+
|
10
|
+
empty_directory :models, File.join('spec/fixtures/models')
|
11
|
+
template :spec_helper, 'spec/spec_helper.rb'
|
12
|
+
end
|
data/lib/messiah/rack.rb
ADDED
@@ -1,4 +1,4 @@
|
|
1
|
-
class Messiah::
|
1
|
+
class Messiah::Rack::CGI
|
2
2
|
def call(env)
|
3
3
|
add_to_environment!(env)
|
4
4
|
header_string, body = call_cgi(env)
|
@@ -7,10 +7,12 @@ class Messiah::RackCGIApp
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def add_to_environment!(env)
|
10
|
-
env['HTTP_HOST'] = Messiah.host
|
10
|
+
env['SERVER_NAME'] = env['HTTP_HOST'] = Messiah.host
|
11
11
|
env['DOCUMENT_ROOT'] = File.expand_path Messiah.root
|
12
12
|
env['SCRIPT_NAME'] = (Messiah.script || env['PATH_INFO']).gsub(/^\//, '')
|
13
13
|
env['SCRIPT_FILENAME'] = env['PATH_TRANSLATED'] = File.join(env['DOCUMENT_ROOT'], env['SCRIPT_NAME'])
|
14
|
+
env[Messiah.environment_key || 'APP_ENV'] = Messiah.environment_name || 'test'
|
15
|
+
env[Messiah.test_root_key || 'X-TEST-ROOT'] = Messiah.test_root
|
14
16
|
end
|
15
17
|
|
16
18
|
def build_environment_string(env)
|
@@ -22,7 +24,6 @@ class Messiah::RackCGIApp
|
|
22
24
|
|
23
25
|
def call_cgi(env)
|
24
26
|
env_string = build_environment_string(env)
|
25
|
-
|
26
27
|
stdin, stdout, stderr = Open3.popen3("env #{env_string} #{Messiah.command}")
|
27
28
|
stdin.write env['rack.input'].read if env['REQUEST_METHOD'] == 'POST'
|
28
29
|
stdin.close
|
@@ -32,12 +33,12 @@ class Messiah::RackCGIApp
|
|
32
33
|
|
33
34
|
def parse_headers(header)
|
34
35
|
headers = header.split("\n").inject({}) do |h, line|
|
35
|
-
key, val = line.split(':').map(&:strip)
|
36
|
+
key, val = line.split(':', 2).map(&:strip)
|
36
37
|
h[key] = val
|
37
38
|
h
|
38
39
|
end
|
39
40
|
status = headers.delete('Status') || 200
|
40
41
|
|
41
|
-
[headers, status]
|
42
|
+
[headers, status.to_i]
|
42
43
|
end
|
43
44
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
class Messiah::Supports::CodeIgniter
|
4
|
+
attr_accessor :config
|
5
|
+
|
6
|
+
def initialize(config)
|
7
|
+
@config = config
|
8
|
+
configure!
|
9
|
+
configure_database!
|
10
|
+
end
|
11
|
+
|
12
|
+
def configure!
|
13
|
+
config.script 'index.php'
|
14
|
+
config.database_file File.join(config.app_root, 'config', 'database.php')
|
15
|
+
end
|
16
|
+
|
17
|
+
def configure_database!
|
18
|
+
reader = File.join(File.dirname(__FILE__), 'code_igniter.php')
|
19
|
+
json = %x|php #{reader} #{config.database_file}|
|
20
|
+
ci_hash = JSON.load(json)
|
21
|
+
|
22
|
+
config.database = {
|
23
|
+
:adapter => ci_hash['dbdriver'],
|
24
|
+
:host => ci_hash['hostname'],
|
25
|
+
:database => ci_hash['database'],
|
26
|
+
:port => ci_hash['port'] && ci_hash['port'].to_i,
|
27
|
+
:username => ci_hash['username'],
|
28
|
+
:password => ci_hash['password']
|
29
|
+
}
|
30
|
+
rescue
|
31
|
+
# swallow everything, leave the database unconfigured
|
32
|
+
end
|
33
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module Messiah::Common
|
1
|
+
module Messiah::Supports::Common
|
2
2
|
def self.included(base)
|
3
3
|
base.send(:include, Webrat::Methods)
|
4
4
|
base.send(:include, Rack::Test::Methods)
|
@@ -7,7 +7,7 @@ module Messiah::Common
|
|
7
7
|
|
8
8
|
def app
|
9
9
|
Rack::Builder.new {
|
10
|
-
run Messiah::
|
10
|
+
run Messiah::Rack::CGI.new
|
11
11
|
}
|
12
12
|
end
|
13
|
-
end
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Messiah::Supports::RSpec
|
2
|
+
def self.included(base)
|
3
|
+
base.send(:include, Messiah::Supports::Common)
|
4
|
+
base.send(:include, ExampleGroup)
|
5
|
+
end
|
6
|
+
|
7
|
+
module ExampleGroup
|
8
|
+
def visit(url)
|
9
|
+
u = url =~ /^\// ? url : "/#{url}"
|
10
|
+
super(u)
|
11
|
+
end
|
12
|
+
|
13
|
+
def host(val)
|
14
|
+
Messiah.config.host val
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,243 @@
|
|
1
|
+
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
|
2
|
+
# It is recommended to regenerate this file in the future when you upgrade to a
|
3
|
+
# newer version of cucumber-rails. Consider adding your own code to a new file
|
4
|
+
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
|
5
|
+
# files.
|
6
|
+
|
7
|
+
|
8
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
|
9
|
+
|
10
|
+
# Commonly used webrat steps
|
11
|
+
# http://github.com/brynary/webrat
|
12
|
+
|
13
|
+
Given /^(?:|I )am on (.+)$/ do |page_name|
|
14
|
+
visit path_to(page_name)
|
15
|
+
end
|
16
|
+
|
17
|
+
When /^(?:|I )go to (.+)$/ do |page_name|
|
18
|
+
visit path_to(page_name)
|
19
|
+
end
|
20
|
+
|
21
|
+
When /^(?:|I )press "([^\"]*)"$/ do |button|
|
22
|
+
click_button(button)
|
23
|
+
end
|
24
|
+
|
25
|
+
When /^(?:|I )follow "([^\"]*)"$/ do |link|
|
26
|
+
click_link(link)
|
27
|
+
end
|
28
|
+
|
29
|
+
When /^(?:|I )follow "([^\"]*)" within "([^\"]*)"$/ do |link, parent|
|
30
|
+
click_link_within(parent, link)
|
31
|
+
end
|
32
|
+
|
33
|
+
When /^(?:|I )fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
|
34
|
+
fill_in(field, :with => value)
|
35
|
+
end
|
36
|
+
|
37
|
+
When /^(?:|I )fill in "([^\"]*)" for "([^\"]*)"$/ do |value, field|
|
38
|
+
fill_in(field, :with => value)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Use this to fill in an entire form with data from a table. Example:
|
42
|
+
#
|
43
|
+
# When I fill in the following:
|
44
|
+
# | Account Number | 5002 |
|
45
|
+
# | Expiry date | 2009-11-01 |
|
46
|
+
# | Note | Nice guy |
|
47
|
+
# | Wants Email? | |
|
48
|
+
#
|
49
|
+
# TODO: Add support for checkbox, select og option
|
50
|
+
# based on naming conventions.
|
51
|
+
#
|
52
|
+
When /^(?:|I )fill in the following:$/ do |fields|
|
53
|
+
fields.rows_hash.each do |name, value|
|
54
|
+
When %{I fill in "#{name}" with "#{value}"}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
When /^(?:|I )select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
|
59
|
+
select(value, :from => field)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Use this step in conjunction with Rail's datetime_select helper. For example:
|
63
|
+
# When I select "December 25, 2008 10:00" as the date and time
|
64
|
+
When /^(?:|I )select "([^\"]*)" as the date and time$/ do |time|
|
65
|
+
select_datetime(time)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Use this step when using multiple datetime_select helpers on a page or
|
69
|
+
# you want to specify which datetime to select. Given the following view:
|
70
|
+
# <%= f.label :preferred %><br />
|
71
|
+
# <%= f.datetime_select :preferred %>
|
72
|
+
# <%= f.label :alternative %><br />
|
73
|
+
# <%= f.datetime_select :alternative %>
|
74
|
+
# The following steps would fill out the form:
|
75
|
+
# When I select "November 23, 2004 11:20" as the "Preferred" date and time
|
76
|
+
# And I select "November 25, 2004 10:30" as the "Alternative" date and time
|
77
|
+
When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, datetime_label|
|
78
|
+
select_datetime(datetime, :from => datetime_label)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Use this step in conjunction with Rail's time_select helper. For example:
|
82
|
+
# When I select "2:20PM" as the time
|
83
|
+
# Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
|
84
|
+
# will convert the 2:20PM to 14:20 and then select it.
|
85
|
+
When /^(?:|I )select "([^\"]*)" as the time$/ do |time|
|
86
|
+
select_time(time)
|
87
|
+
end
|
88
|
+
|
89
|
+
# Use this step when using multiple time_select helpers on a page or you want to
|
90
|
+
# specify the name of the time on the form. For example:
|
91
|
+
# When I select "7:30AM" as the "Gym" time
|
92
|
+
When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label|
|
93
|
+
select_time(time, :from => time_label)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Use this step in conjunction with Rail's date_select helper. For example:
|
97
|
+
# When I select "February 20, 1981" as the date
|
98
|
+
When /^(?:|I )select "([^\"]*)" as the date$/ do |date|
|
99
|
+
select_date(date)
|
100
|
+
end
|
101
|
+
|
102
|
+
# Use this step when using multiple date_select helpers on one page or
|
103
|
+
# you want to specify the name of the date on the form. For example:
|
104
|
+
# When I select "April 26, 1982" as the "Date of Birth" date
|
105
|
+
When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label|
|
106
|
+
select_date(date, :from => date_label)
|
107
|
+
end
|
108
|
+
|
109
|
+
When /^(?:|I )check "([^\"]*)"$/ do |field|
|
110
|
+
check(field)
|
111
|
+
end
|
112
|
+
|
113
|
+
When /^(?:|I )uncheck "([^\"]*)"$/ do |field|
|
114
|
+
uncheck(field)
|
115
|
+
end
|
116
|
+
|
117
|
+
When /^(?:|I )choose "([^\"]*)"$/ do |field|
|
118
|
+
choose(field)
|
119
|
+
end
|
120
|
+
|
121
|
+
# Adds support for validates_attachment_content_type. Without the mime-type getting
|
122
|
+
# passed to attach_file() you will get a "Photo file is not one of the allowed file types."
|
123
|
+
# error message
|
124
|
+
When /^(?:|I )attach the file "([^\"]*)" to "([^\"]*)"$/ do |path, field|
|
125
|
+
type = path.split(".")[1]
|
126
|
+
|
127
|
+
case type
|
128
|
+
when "jpg"
|
129
|
+
type = "image/jpg"
|
130
|
+
when "jpeg"
|
131
|
+
type = "image/jpeg"
|
132
|
+
when "png"
|
133
|
+
type = "image/png"
|
134
|
+
when "gif"
|
135
|
+
type = "image/gif"
|
136
|
+
end
|
137
|
+
|
138
|
+
attach_file(field, path, type)
|
139
|
+
end
|
140
|
+
|
141
|
+
Then /^(?:|I )should see "([^\"]*)"$/ do |text|
|
142
|
+
last_response.should contain(text)
|
143
|
+
end
|
144
|
+
|
145
|
+
Then /^(?:|I )should see "([^\"]*)" within "([^\"]*)"$/ do |text, selector|
|
146
|
+
within(selector) do |content|
|
147
|
+
if defined?(Spec::Rails::Matchers)
|
148
|
+
content.should contain(text)
|
149
|
+
else
|
150
|
+
assert content.include?(text)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
|
156
|
+
regexp = Regexp.new(regexp)
|
157
|
+
last_response.should contain(regexp)
|
158
|
+
end
|
159
|
+
|
160
|
+
Then /^(?:|I )should see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector|
|
161
|
+
within(selector) do |content|
|
162
|
+
regexp = Regexp.new(regexp)
|
163
|
+
if defined?(Spec::Rails::Matchers)
|
164
|
+
content.should contain(regexp)
|
165
|
+
else
|
166
|
+
assert content =~ regexp
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
Then /^(?:|I )should not see "([^\"]*)"$/ do |text|
|
172
|
+
last_response.should_not contain(text)
|
173
|
+
end
|
174
|
+
|
175
|
+
Then /^(?:|I )should not see "([^\"]*)" within "([^\"]*)"$/ do |text, selector|
|
176
|
+
within(selector) do |content|
|
177
|
+
if defined?(Spec::Rails::Matchers)
|
178
|
+
content.should_not contain(text)
|
179
|
+
else
|
180
|
+
assert !content.include?(text)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
|
186
|
+
regexp = Regexp.new(regexp)
|
187
|
+
last_response.should_not contain(regexp)
|
188
|
+
end
|
189
|
+
|
190
|
+
Then /^(?:|I )should not see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector|
|
191
|
+
within(selector) do |content|
|
192
|
+
regexp = Regexp.new(regexp)
|
193
|
+
if defined?(Spec::Rails::Matchers)
|
194
|
+
content.should_not contain(regexp)
|
195
|
+
else
|
196
|
+
assert content !~ regexp
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value|
|
202
|
+
if defined?(Spec::Rails::Matchers)
|
203
|
+
field_labeled(field).value.should =~ /#{value}/
|
204
|
+
else
|
205
|
+
assert_match(/#{value}/, field_labeled(field).value)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
Then /^the "([^\"]*)" field should not contain "([^\"]*)"$/ do |field, value|
|
210
|
+
if defined?(Spec::Rails::Matchers)
|
211
|
+
field_labeled(field).value.should_not =~ /#{value}/
|
212
|
+
else
|
213
|
+
assert_no_match(/#{value}/, field_labeled(field).value)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
Then /^the "([^\"]*)" checkbox should be checked$/ do |label|
|
218
|
+
if defined?(Spec::Rails::Matchers)
|
219
|
+
field_labeled(label).should be_checked
|
220
|
+
else
|
221
|
+
assert field_labeled(label).checked?
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
Then /^the "([^\"]*)" checkbox should not be checked$/ do |label|
|
226
|
+
if defined?(Spec::Rails::Matchers)
|
227
|
+
field_labeled(label).should_not be_checked
|
228
|
+
else
|
229
|
+
assert !field_labeled(label).checked?
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
Then /^(?:|I )should be on (.+)$/ do |page_name|
|
234
|
+
if defined?(Spec::Rails::Matchers)
|
235
|
+
URI.parse(current_url).path.should == path_to(page_name)
|
236
|
+
else
|
237
|
+
assert_equal path_to(page_name), URI.parse(current_url).path
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
Then /^show me the page$/ do
|
242
|
+
save_and_open_page
|
243
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
|
2
|
+
require 'active_record'
|
3
|
+
require 'cucumber/web/tableish'
|
4
|
+
|
5
|
+
require 'webrat'
|
6
|
+
require 'webrat/core/matchers'
|
7
|
+
|
8
|
+
require 'messiah'
|
9
|
+
|
10
|
+
Messiah.configure do
|
11
|
+
root File.join(File.dirname(__FILE__), '..', '..', 'spec', 'fixtures', 'www')
|
12
|
+
command 'php-cgi -d cgi.force_redirect=0'
|
13
|
+
end
|
14
|
+
|
15
|
+
# How to clean your database when transactions are turned off. See
|
16
|
+
# http://github.com/bmabey/database_cleaner for more info.
|
17
|
+
require 'database_cleaner'
|
18
|
+
DatabaseCleaner.strategy = :truncation
|
19
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec'
|
2
|
+
require 'spec/autorun'
|
3
|
+
require 'messiah'
|
4
|
+
|
5
|
+
Messiah.configure do
|
6
|
+
root File.join(File.dirname(__FILE__), '..', '<%= root %>')
|
7
|
+
command '<%= command %>'
|
8
|
+
<%- if script -%>
|
9
|
+
script '<%= script %>'
|
10
|
+
<%- end -%>
|
11
|
+
end
|
12
|
+
|
13
|
+
Spec::Runner.configure do |config|
|
14
|
+
end
|
data/spec/messiah_spec.rb
CHANGED
@@ -2,16 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
|
3
3
|
describe "Messiah" do
|
4
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
|
-
|
5
|
+
|
15
6
|
before(:each) do
|
16
7
|
host "example.dev"
|
17
8
|
end
|
@@ -77,10 +68,46 @@ describe "Messiah" do
|
|
77
68
|
body.should contain "[uploaded_file]"
|
78
69
|
end
|
79
70
|
|
71
|
+
it "passes the application environment using the default key" do
|
72
|
+
visit 'env.php?key=APP_ENV'
|
73
|
+
body.should contain 'The key APP_ENV exists and is test'
|
74
|
+
end
|
75
|
+
|
76
|
+
it "passes the application environment using a custom key" do
|
77
|
+
Messiah.environment_key 'X-APP-ENV'
|
78
|
+
visit 'env.php?key=X-APP-ENV'
|
79
|
+
body.should contain 'The key X-APP-ENV exists and is test'
|
80
|
+
end
|
81
|
+
|
82
|
+
it "passes the test root using the default key" do
|
83
|
+
Messiah.test_root 'WOOHOO'
|
84
|
+
visit 'env.php?key=X-TEST-ROOT'
|
85
|
+
body.should contain 'The key X-TEST-ROOT exists and is WOOHOO'
|
86
|
+
end
|
87
|
+
|
80
88
|
it "handles environments that drive every request through one script" do
|
81
89
|
Messiah.script 'path_info.php'
|
82
90
|
visit '/hello/there'
|
83
91
|
body.should contain '/hello/there'
|
84
92
|
end
|
93
|
+
|
94
|
+
it "passes the test root using a custom key" do
|
95
|
+
Messiah.test_root 'WOOHOOCUSTOM'
|
96
|
+
Messiah.test_root_key 'MYHAPPYTESTROOT'
|
97
|
+
visit 'env.php?key=MYHAPPYTESTROOT'
|
98
|
+
body.should contain 'The key MYHAPPYTESTROOT exists and is WOOHOOCUSTOM'
|
99
|
+
end
|
100
|
+
|
101
|
+
it "passes the application environment using a custom key" do
|
102
|
+
Messiah.environment_key 'X-APP-ENV'
|
103
|
+
visit 'env.php?key=X-APP-ENV'
|
104
|
+
body.should contain 'The key X-APP-ENV exists and is test'
|
105
|
+
end
|
106
|
+
|
107
|
+
it "resets the configuration to the frozen state" do
|
108
|
+
Messiah.script 'path_info.php'
|
109
|
+
Messiah.reset_config!
|
110
|
+
Messiah.script.should be_nil
|
111
|
+
end
|
85
112
|
end
|
86
113
|
|
data/spec/spec.opts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
-fs -c
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: messiah
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 9
|
8
|
+
- 0
|
9
|
+
version: 0.9.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Rich Cavanaugh
|
@@ -9,43 +14,97 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
13
|
-
default_executable:
|
17
|
+
date: 2010-02-23 00:00:00 -05:00
|
18
|
+
default_executable: messiah-generator
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: webrat
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
23
29
|
version: "0"
|
24
|
-
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
25
32
|
- !ruby/object:Gem::Dependency
|
26
33
|
name: rack
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - ">="
|
32
38
|
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
33
41
|
version: "0"
|
34
|
-
|
42
|
+
type: :runtime
|
43
|
+
version_requirements: *id002
|
35
44
|
- !ruby/object:Gem::Dependency
|
36
45
|
name: rack-test
|
46
|
+
prerelease: false
|
47
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
37
54
|
type: :runtime
|
38
|
-
|
39
|
-
|
55
|
+
version_requirements: *id003
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: activerecord
|
58
|
+
prerelease: false
|
59
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
type: :runtime
|
67
|
+
version_requirements: *id004
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: factory_girl
|
70
|
+
prerelease: false
|
71
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
40
72
|
requirements:
|
41
73
|
- - ">="
|
42
74
|
- !ruby/object:Gem::Version
|
75
|
+
segments:
|
76
|
+
- 0
|
43
77
|
version: "0"
|
44
|
-
|
78
|
+
type: :runtime
|
79
|
+
version_requirements: *id005
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: dr_nic_magic_models
|
82
|
+
prerelease: false
|
83
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
type: :runtime
|
91
|
+
version_requirements: *id006
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: database_cleaner
|
94
|
+
prerelease: false
|
95
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
version: "0"
|
102
|
+
type: :runtime
|
103
|
+
version_requirements: *id007
|
45
104
|
description: Messiah enables using Ruby testing tools for integration testing with platforms that support CGI. Notably, PHP.
|
46
105
|
email: rich@withoutscope.com
|
47
|
-
executables:
|
48
|
-
|
106
|
+
executables:
|
107
|
+
- messiah-generator
|
49
108
|
extensions: []
|
50
109
|
|
51
110
|
extra_rdoc_files:
|
@@ -59,14 +118,32 @@ files:
|
|
59
118
|
- Rakefile
|
60
119
|
- TODO
|
61
120
|
- VERSION
|
121
|
+
- bin/messiah-generator
|
62
122
|
- lib/messiah.rb
|
63
|
-
- lib/messiah/common.rb
|
64
123
|
- lib/messiah/config.rb
|
65
|
-
- lib/messiah/
|
66
|
-
- lib/messiah/
|
67
|
-
- lib/messiah/
|
124
|
+
- lib/messiah/configurator.rb
|
125
|
+
- lib/messiah/generator.rb
|
126
|
+
- lib/messiah/generator/application.rb
|
127
|
+
- lib/messiah/generator/cucumber.rb
|
128
|
+
- lib/messiah/generator/options.rb
|
129
|
+
- lib/messiah/generator/rspec.rb
|
130
|
+
- lib/messiah/generator/test_unit.rb
|
131
|
+
- lib/messiah/rack.rb
|
132
|
+
- lib/messiah/rack/cgi.rb
|
133
|
+
- lib/messiah/supports/code_igniter.php
|
134
|
+
- lib/messiah/supports/code_igniter.rb
|
135
|
+
- lib/messiah/supports/common.rb
|
136
|
+
- lib/messiah/supports/cucumber.rb
|
137
|
+
- lib/messiah/supports/rspec.rb
|
138
|
+
- lib/messiah/supports/test_unit.rb
|
139
|
+
- lib/messiah/templates/cucumber/features/messiah.feature
|
140
|
+
- lib/messiah/templates/cucumber/features/step_definitions/web_steps.rb
|
141
|
+
- lib/messiah/templates/cucumber/features/support/env.rb
|
142
|
+
- lib/messiah/templates/cucumber/features/support/paths.rb
|
143
|
+
- lib/messiah/templates/rspec/spec/spec_helper.rbt
|
68
144
|
- spec/fixtures/www/another.php
|
69
145
|
- spec/fixtures/www/destination.php
|
146
|
+
- spec/fixtures/www/env.php
|
70
147
|
- spec/fixtures/www/form.php
|
71
148
|
- spec/fixtures/www/get_vars.php
|
72
149
|
- spec/fixtures/www/index.php
|
@@ -92,18 +169,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
169
|
requirements:
|
93
170
|
- - ">="
|
94
171
|
- !ruby/object:Gem::Version
|
172
|
+
segments:
|
173
|
+
- 0
|
95
174
|
version: "0"
|
96
|
-
version:
|
97
175
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
176
|
requirements:
|
99
177
|
- - ">="
|
100
178
|
- !ruby/object:Gem::Version
|
179
|
+
segments:
|
180
|
+
- 0
|
101
181
|
version: "0"
|
102
|
-
version:
|
103
182
|
requirements: []
|
104
183
|
|
105
184
|
rubyforge_project:
|
106
|
-
rubygems_version: 1.3.
|
185
|
+
rubygems_version: 1.3.6
|
107
186
|
signing_key:
|
108
187
|
specification_version: 3
|
109
188
|
summary: The beauty of Ruby integration tests for PHP
|
data/lib/messiah/rspec.rb
DELETED