merb_test_unit 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README +4 -0
- data/Rakefile +49 -0
- data/TODO +5 -0
- data/lib/asserts/controller_asserts.rb +44 -0
- data/lib/asserts/hpricot_asserts.rb +48 -0
- data/lib/merb_test_unit/merbtasks.rb +20 -0
- data/lib/merb_test_unit.rb +18 -0
- data/test_unit_generators/merb_controller_test/merb_controller_test_generator.rb +47 -0
- data/test_unit_generators/merb_controller_test/templates/test/functional/%controller_full_file_path%_test.rb +17 -0
- data/test_unit_generators/merb_model_test/merb_model_test_generator.rb +34 -0
- data/test_unit_generators/merb_model_test/templates/test/unit/%model_file_name%_test.rb +9 -0
- data/test_unit_generators/merb_resource_controller_test/merb_resource_controller_test_generator.rb +31 -0
- metadata +86 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 YOUR NAME
|
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
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
|
4
|
+
PLUGIN = "merb_test_unit"
|
5
|
+
NAME = "merb_test_unit"
|
6
|
+
VERSION = "0.9.2"
|
7
|
+
AUTHOR = "Yehuda Katz"
|
8
|
+
EMAIL = "ykatz@engineyard.com"
|
9
|
+
HOMEPAGE = "http://merb-plugins.rubyforge.org/merb-test_unit/"
|
10
|
+
SUMMARY = "Merb plugin that provides Test::Unit support"
|
11
|
+
|
12
|
+
spec = Gem::Specification.new do |s|
|
13
|
+
s.name = NAME
|
14
|
+
s.version = VERSION
|
15
|
+
s.platform = Gem::Platform::RUBY
|
16
|
+
s.has_rdoc = true
|
17
|
+
s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
|
18
|
+
s.summary = SUMMARY
|
19
|
+
s.description = s.summary
|
20
|
+
s.author = AUTHOR
|
21
|
+
s.email = EMAIL
|
22
|
+
s.homepage = HOMEPAGE
|
23
|
+
s.add_dependency('merb-core', '>= 0.9.2')
|
24
|
+
s.require_path = 'lib'
|
25
|
+
s.autorequire = PLUGIN
|
26
|
+
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,test_unit_generators}/**/*")
|
27
|
+
end
|
28
|
+
|
29
|
+
windows = (PLATFORM =~ /win32|cygwin/) rescue nil
|
30
|
+
|
31
|
+
SUDO = windows ? "" : "sudo"
|
32
|
+
|
33
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
34
|
+
pkg.gem_spec = spec
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Install merb_test_unit"
|
38
|
+
task :install => [:package] do
|
39
|
+
sh %{#{SUDO} gem install pkg/#{NAME}-#{VERSION} --no-rdoc --no-ri --no-update-sources}
|
40
|
+
end
|
41
|
+
|
42
|
+
namespace :jruby do
|
43
|
+
|
44
|
+
desc "Run :package and install the resulting .gem with jruby"
|
45
|
+
task :install => :package do
|
46
|
+
sh %{#{SUDO} jruby -S gem install pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
data/TODO
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Merb::Test::Unit::ControllerAsserts
|
2
|
+
include Test::Unit::Assertions
|
3
|
+
include Merb::Test::ControllerHelper
|
4
|
+
|
5
|
+
def assert_redirect(target)
|
6
|
+
assert [307, *(300..305)].include?(target.respond_to?(:status) ? target.status : target), redirect_failure_message(target)
|
7
|
+
end
|
8
|
+
|
9
|
+
def assert_redirect_to(expected, target)
|
10
|
+
location = target.headers['Location']
|
11
|
+
|
12
|
+
assert_redirect(target)
|
13
|
+
assert_equal expected, location, redirect_to_failure_message(expected, location)
|
14
|
+
end
|
15
|
+
|
16
|
+
def assert_success(target)
|
17
|
+
assert (200..207).include?(target.respond_to?(:status) ? target.status : target), success_failure_message(target)
|
18
|
+
end
|
19
|
+
|
20
|
+
def assert_missing(target)
|
21
|
+
assert (400..417).include?(target.respond_to?(:status) ? target.status : target), missing_failure_message(target)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def redirect_failure_message(target)
|
26
|
+
"expected#{target_message(target)} to redirect"
|
27
|
+
end
|
28
|
+
|
29
|
+
def redirect_to_failure_message(expected, location)
|
30
|
+
"expected a redirect to <#{expected}>, but found one to #{location}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def success_failure_message(target)
|
34
|
+
"expected#{target_message(target)} to be successful"
|
35
|
+
end
|
36
|
+
|
37
|
+
def missing_failure_message(target)
|
38
|
+
"expected#{target_message(target)} to be missing"
|
39
|
+
end
|
40
|
+
|
41
|
+
def target_message(target)
|
42
|
+
" #{@target.inspect}" if target.respond_to?(:status)
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# http://yehudakatz.com/2007/01/27/a-better-assert_select-assert_elements/
|
2
|
+
# based on assert_elements
|
3
|
+
# Author: Yehuda Katz
|
4
|
+
# Email: wycats @nospam@ gmail.com
|
5
|
+
# Web: http://www.yehudakatz.com
|
6
|
+
#
|
7
|
+
# which was based on HpricotTestHelper
|
8
|
+
# Author: Luke Redpath
|
9
|
+
# Email: contact @nospam@ lukeredpath.co.uk
|
10
|
+
# Web: www.lukeredpath.co.uk / opensource.agileevolved.com
|
11
|
+
|
12
|
+
module Merb::Test::Unit::HpricotAsserts
|
13
|
+
include Test::Unit::Assertions
|
14
|
+
# include Merb::Test::HpricotHelper
|
15
|
+
|
16
|
+
def assert_elements(css_query, output = nil, equality = {}, &block)
|
17
|
+
message = equality.delete(:message) if equality.is_a?(Hash)
|
18
|
+
|
19
|
+
case equality
|
20
|
+
when Numeric then equality = {:count => equality}
|
21
|
+
when Range then equality = {:minimum => equality.to_a.first, :maximum => equality.to_a.last }
|
22
|
+
else equality ||= {}
|
23
|
+
end
|
24
|
+
|
25
|
+
equality.merge!({:minimum => 1}) if (equality.keys & [:minimum, :maximum, :count]).empty?
|
26
|
+
|
27
|
+
els = get_elements(css_query, equality[:text], output)
|
28
|
+
|
29
|
+
ret = equality.keys.include?(:minimum) ? (els.size >= equality[:minimum]) : true
|
30
|
+
ret &&= (els.size <= equality[:maximum]) if equality.keys.include?(:maximum)
|
31
|
+
ret &&= (els.size == equality[:count]) if equality.keys.include?(:count)
|
32
|
+
|
33
|
+
if block && !els.empty?
|
34
|
+
ret &&= self.dup.instance_eval do
|
35
|
+
@output = HpricotTestHelper::DocumentOutput.new(els.inner_html)
|
36
|
+
@block = true
|
37
|
+
instance_eval(&block)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
if(equality[:count] != 0)
|
42
|
+
assert ret, "#{ message } \"#{ css_query }\" with \"#{ equality.inspect }\" was not found."
|
43
|
+
else
|
44
|
+
assert ret, "#{ message } \"#{ css_query }\" with \"#{ equality.reject{|k,v| k == :count}.inspect }\" was found, but you specified :count => 0."
|
45
|
+
end
|
46
|
+
ret
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
desc 'Run unit tests'
|
2
|
+
Rake::TestTask.new('test_unit') do |t|
|
3
|
+
t.libs << 'test'
|
4
|
+
t.pattern = 'test/unit/*_test.rb'
|
5
|
+
t.verbose = true
|
6
|
+
end
|
7
|
+
|
8
|
+
desc 'Run functional tests'
|
9
|
+
Rake::TestTask.new('test_functional') do |t|
|
10
|
+
t.libs << 'test'
|
11
|
+
t.pattern = 'test/functional/*_test.rb'
|
12
|
+
t.verbose = true
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Run all tests'
|
16
|
+
Rake::TestTask.new('test') do |t|
|
17
|
+
t.libs << 'test'
|
18
|
+
t.pattern = 'test/**/*_test.rb'
|
19
|
+
t.verbose = true
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
if defined?(Merb::Plugins)
|
2
|
+
Merb::Plugins.add_rakefiles "merb_test_unit" / "merbtasks"
|
3
|
+
end
|
4
|
+
|
5
|
+
#Don't include anything for Test::Unit if we're not
|
6
|
+
if Merb.environment == "test"
|
7
|
+
require 'hpricot'
|
8
|
+
|
9
|
+
require 'test/unit'
|
10
|
+
require 'merb-core/test/test_ext/hpricot'
|
11
|
+
require 'merb-core/test/test_ext/object'
|
12
|
+
|
13
|
+
module Merb::Test::Unit
|
14
|
+
end
|
15
|
+
|
16
|
+
require File.join(File.dirname(__FILE__) / 'asserts' / 'hpricot_asserts')
|
17
|
+
require File.join(File.dirname(__FILE__) / 'asserts' / 'controller_asserts')
|
18
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class MerbControllerTestGenerator < Merb::GeneratorBase
|
2
|
+
attr_reader :controller_modules,
|
3
|
+
:controller_class_name,
|
4
|
+
:controller_file_name,
|
5
|
+
:controller_base_path,
|
6
|
+
:full_controller_const
|
7
|
+
|
8
|
+
def initialize(args, runtime_args = {})
|
9
|
+
@base = File.dirname(__FILE__)
|
10
|
+
super
|
11
|
+
@controller_modules = runtime_args[:controller_modules]
|
12
|
+
@controller_class_name = runtime_args[:controller_class_name]
|
13
|
+
@controller_file_name = runtime_args[:controller_file_name]
|
14
|
+
@controller_base_path = runtime_args[:controller_base_path]
|
15
|
+
@full_controller_const = runtime_args[:full_controller_const]
|
16
|
+
end
|
17
|
+
|
18
|
+
def manifest
|
19
|
+
record do |m|
|
20
|
+
@m = m
|
21
|
+
|
22
|
+
@assigns = {
|
23
|
+
:controller_modules => controller_modules,
|
24
|
+
:controller_class_name => controller_class_name,
|
25
|
+
:controller_full_file_path => controller_file_name,
|
26
|
+
:controller_file_name => controller_file_name.split("/").last,
|
27
|
+
:controller_base_path => controller_base_path,
|
28
|
+
:full_controller_const => full_controller_const
|
29
|
+
}
|
30
|
+
|
31
|
+
# make sure the directory is availalbe
|
32
|
+
m.directory File.join("test", "functional", "#{controller_base_path}")
|
33
|
+
|
34
|
+
copy_dirs
|
35
|
+
copy_files
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
def banner
|
41
|
+
<<-EOS.split("\n").map{|x| x.strip}.join("\n")
|
42
|
+
Creates a basic Test::Unit Functional test stub.
|
43
|
+
|
44
|
+
USAGE: #{spec.name}"
|
45
|
+
EOS
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "<%= Array.new((controller_modules.size + 1),'..').join("/") %>",'test_helper')
|
2
|
+
|
3
|
+
# Re-raise errors caught by the controller.
|
4
|
+
class <%= full_controller_const %>; def rescue_action(e) raise e end; end
|
5
|
+
|
6
|
+
class <%= full_controller_const %>Test < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@controller = <%= full_controller_const %>.build(fake_request)
|
10
|
+
@controller.dispatch('index')
|
11
|
+
end
|
12
|
+
|
13
|
+
# Replace this with your real tests.
|
14
|
+
def test_should_be_setup
|
15
|
+
assert false
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class MerbModelTestGenerator < Merb::GeneratorBase
|
2
|
+
attr_reader :model_attributes, :model_class_name, :model_file_name
|
3
|
+
|
4
|
+
def initialize(args, runtime_args = {})
|
5
|
+
@base = File.dirname(__FILE__)
|
6
|
+
super
|
7
|
+
@model_file_name = runtime_args[:model_file_name]
|
8
|
+
@model_attributes = runtime_args[:model_attributes]
|
9
|
+
@model_class_name = runtime_args[:model_class_name]
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
def manifest
|
14
|
+
record do |m|
|
15
|
+
@m = m
|
16
|
+
|
17
|
+
@assigns = { :model_file_name => model_file_name,
|
18
|
+
:model_attributes => model_attributes,
|
19
|
+
:model_class_name => model_class_name
|
20
|
+
}
|
21
|
+
copy_dirs
|
22
|
+
copy_files
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
def banner
|
28
|
+
<<-EOS.split("\n").map{|x| x.strip}.join("\n")
|
29
|
+
Creates a basic Test::Unit unit test stub.
|
30
|
+
|
31
|
+
USAGE: #{spec.name}"
|
32
|
+
EOS
|
33
|
+
end
|
34
|
+
end
|
data/test_unit_generators/merb_resource_controller_test/merb_resource_controller_test_generator.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
class MerbControllerTestGenerator < Merb::GeneratorBase
|
2
|
+
attr_reader :controller_modules,
|
3
|
+
:controller_class_name,
|
4
|
+
:controller_file_name,
|
5
|
+
:controller_base_path,
|
6
|
+
:full_controller_const
|
7
|
+
|
8
|
+
def initialize(args, runtime_args = {})
|
9
|
+
@base = File.dirname(__FILE__)
|
10
|
+
super
|
11
|
+
@args = args
|
12
|
+
@runtime_args = runtime_args
|
13
|
+
end
|
14
|
+
|
15
|
+
def manifest
|
16
|
+
record do |m|
|
17
|
+
@m = m
|
18
|
+
|
19
|
+
m.dependency "merb_controller_test", @args, @runtime_args
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
def banner
|
25
|
+
<<-EOS.split("\n").map{|x| x.strip}.join("\n")
|
26
|
+
Creates a basic Test::Unit Functional test stub.
|
27
|
+
|
28
|
+
USAGE: #{spec.name}"
|
29
|
+
EOS
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: merb_test_unit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yehuda Katz
|
8
|
+
autorequire: merb_test_unit
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-03-24 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: merb-core
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.9.2
|
23
|
+
version:
|
24
|
+
description: Merb plugin that provides Test::Unit support
|
25
|
+
email: ykatz@engineyard.com
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- README
|
32
|
+
- LICENSE
|
33
|
+
- TODO
|
34
|
+
files:
|
35
|
+
- LICENSE
|
36
|
+
- README
|
37
|
+
- Rakefile
|
38
|
+
- TODO
|
39
|
+
- lib/asserts
|
40
|
+
- lib/asserts/controller_asserts.rb
|
41
|
+
- lib/asserts/hpricot_asserts.rb
|
42
|
+
- lib/merb_test_unit
|
43
|
+
- lib/merb_test_unit/merbtasks.rb
|
44
|
+
- lib/merb_test_unit.rb
|
45
|
+
- test_unit_generators/merb_controller_test
|
46
|
+
- test_unit_generators/merb_controller_test/merb_controller_test_generator.rb
|
47
|
+
- test_unit_generators/merb_controller_test/templates
|
48
|
+
- test_unit_generators/merb_controller_test/templates/test
|
49
|
+
- test_unit_generators/merb_controller_test/templates/test/functional
|
50
|
+
- test_unit_generators/merb_controller_test/templates/test/functional/%controller_full_file_path%_test.rb
|
51
|
+
- test_unit_generators/merb_model_test
|
52
|
+
- test_unit_generators/merb_model_test/merb_model_test_generator.rb
|
53
|
+
- test_unit_generators/merb_model_test/templates
|
54
|
+
- test_unit_generators/merb_model_test/templates/test
|
55
|
+
- test_unit_generators/merb_model_test/templates/test/unit
|
56
|
+
- test_unit_generators/merb_model_test/templates/test/unit/%model_file_name%_test.rb
|
57
|
+
- test_unit_generators/merb_resource_controller_test
|
58
|
+
- test_unit_generators/merb_resource_controller_test/merb_resource_controller_test_generator.rb
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: http://merb-plugins.rubyforge.org/merb-test_unit/
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
version:
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.0.1
|
82
|
+
signing_key:
|
83
|
+
specification_version: 2
|
84
|
+
summary: Merb plugin that provides Test::Unit support
|
85
|
+
test_files: []
|
86
|
+
|