testdependencies 0.1.0 → 0.2.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/README.rdoc +3 -2
- data/VERSION +1 -1
- data/lib/adapters/plain.rb +18 -0
- data/lib/adapters/shoulda.rb +18 -0
- data/lib/testdependencies.rb +14 -21
- data/test/helper.rb +4 -17
- data/test/plain_test.rb +39 -0
- data/test/shoulda_test.rb +54 -0
- data/testdependencies.gemspec +58 -0
- metadata +10 -5
- data/test/test_testdependencies.rb +0 -21
data/README.rdoc
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
= testdependencies
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
Testdependencies adds explicit dependency declarations to
|
4
|
+
Rails #test method and Shouldas' toplevel #should method (Not working inside contexts).
|
5
|
+
more about dependency declarative testing: http://www.iam.unibe.ch/~scg/Research/JExample/
|
5
6
|
|
6
7
|
test "A test that depends on" => "dependency" do |value_of_dependency|
|
7
8
|
assert something
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -0,0 +1,18 @@
|
|
1
|
+
ActiveSupport::TestCase.module_eval do
|
2
|
+
class<<self
|
3
|
+
alias old_test test
|
4
|
+
def test(decl, &block)
|
5
|
+
unless String === decl
|
6
|
+
old_test decl.keys.first do
|
7
|
+
dep = decl.values.first
|
8
|
+
dep = "test_#{dep.gsub(/\s+/,'_')}".to_sym if String === dep
|
9
|
+
raise "Dependency undefined: #{dep}" unless respond_to?(dep)
|
10
|
+
result = send(dep) rescue false
|
11
|
+
instance_exec(*result, &block) if result
|
12
|
+
end
|
13
|
+
else
|
14
|
+
old_test decl, &block
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
ActiveSupport::TestCase.module_eval do
|
2
|
+
class<<self
|
3
|
+
alias old_should should
|
4
|
+
def should(decl, &block)
|
5
|
+
unless String === decl
|
6
|
+
old_should decl.keys.first do
|
7
|
+
dep = decl.values.first
|
8
|
+
dep = "test: #{self.class.to_s.gsub('Test', '')} should #{dep}. ".to_sym if String === dep
|
9
|
+
raise "Dependency undefined: #{dep}" unless respond_to?(dep)
|
10
|
+
result = send(dep) rescue false
|
11
|
+
instance_exec(*result, &block) if result
|
12
|
+
end
|
13
|
+
else
|
14
|
+
old_should decl, &block
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/testdependencies.rb
CHANGED
@@ -1,22 +1,15 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
1
3
|
|
2
|
-
ActiveSupport
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
result = send(dep) rescue false
|
15
|
-
instance_exec(*result, &block) if result
|
16
|
-
end
|
17
|
-
else
|
18
|
-
old_test decl, &block
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
4
|
+
unless defined?(ActiveSupport)
|
5
|
+
raise "testdependencies must be required *after* rails/activesupport has been loaded"
|
6
|
+
end
|
7
|
+
|
8
|
+
if defined?(Shoulda::Helpers) && Test::Unit::TestCase.ancestors.include?(Shoulda::Helpers)
|
9
|
+
require "adapters/shoulda"
|
10
|
+
else
|
11
|
+
require "adapters/plain"
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
|
data/test/helper.rb
CHANGED
@@ -1,25 +1,12 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'test/unit'
|
3
|
+
require 'rails/all'
|
4
|
+
if defined?(SHOULDA_TEST)
|
5
|
+
require 'shoulda'
|
6
|
+
end
|
3
7
|
|
4
8
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
9
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
10
|
|
7
|
-
require 'rails/all'
|
8
|
-
|
9
|
-
class ActiveSupport::TestCase < Test::Unit::TestCase
|
10
|
-
# this is rail's way of declaring tests
|
11
|
-
def test(name, &block)
|
12
|
-
test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
|
13
|
-
defined = instance_method(test_name) rescue false
|
14
|
-
raise "#{test_name} is already defined in #{self}" if defined
|
15
|
-
if block_given?
|
16
|
-
define_method(test_name, &block)
|
17
|
-
else
|
18
|
-
define_method(test_name) do
|
19
|
-
flunk "No implementation provided for #{name}"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
11
|
|
25
12
|
require 'testdependencies'
|
data/test/plain_test.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class RegressionTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def new_user
|
6
|
+
user = Object.new
|
7
|
+
def user.name
|
8
|
+
"Horst"
|
9
|
+
end
|
10
|
+
user
|
11
|
+
end
|
12
|
+
|
13
|
+
test "User has a name" => :new_user do |user|
|
14
|
+
assert_respond_to user, :name
|
15
|
+
user.name
|
16
|
+
end
|
17
|
+
|
18
|
+
test "User name is Horst" => "User has a name" do |name|
|
19
|
+
assert_equal "Horst", name
|
20
|
+
end
|
21
|
+
|
22
|
+
test "multiple return values" do
|
23
|
+
a, b, c, d = 1,2,3,4
|
24
|
+
end
|
25
|
+
|
26
|
+
test "Consume separately" => "multiple return values" do |a,b,c,d|
|
27
|
+
assert_equal 1, a
|
28
|
+
assert_equal 2, b
|
29
|
+
assert_equal 3, c
|
30
|
+
assert_equal 4, d
|
31
|
+
end
|
32
|
+
|
33
|
+
test "Consume altogether" => "multiple return values" do |*arr|
|
34
|
+
assert_equal 1, arr[0]
|
35
|
+
assert_equal 2, arr[1]
|
36
|
+
assert_equal 3, arr[2]
|
37
|
+
assert_equal 4, arr[3]
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
SHOULDA_TEST = true
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
|
5
|
+
class RegressionTest < ActiveSupport::TestCase
|
6
|
+
|
7
|
+
def new_user
|
8
|
+
user = Object.new
|
9
|
+
def user.name
|
10
|
+
"Horst"
|
11
|
+
end
|
12
|
+
user
|
13
|
+
end
|
14
|
+
|
15
|
+
should "User has a name" => :new_user do |user|
|
16
|
+
assert_respond_to user, :name
|
17
|
+
user.name
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
should "User name is Horst" => "User has a name" do |name|
|
22
|
+
assert_equal "Horst", name
|
23
|
+
end
|
24
|
+
|
25
|
+
context "Declarative and classic style mixed together" do
|
26
|
+
setup do
|
27
|
+
@var = 1
|
28
|
+
end
|
29
|
+
|
30
|
+
context "still working" do
|
31
|
+
should "get vat from setup" do
|
32
|
+
assert_equal 1, @var
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
should "multiple return values" do
|
38
|
+
a, b, c, d = 1,2,3,4
|
39
|
+
end
|
40
|
+
|
41
|
+
should "Consume separately" => "multiple return values" do |a,b,c,d|
|
42
|
+
assert_equal 1, a
|
43
|
+
assert_equal 2, b
|
44
|
+
assert_equal 3, c
|
45
|
+
assert_equal 4, d
|
46
|
+
end
|
47
|
+
|
48
|
+
should "Consume altogether" => "multiple return values" do |*arr|
|
49
|
+
assert_equal 1, arr[0]
|
50
|
+
assert_equal 2, arr[1]
|
51
|
+
assert_equal 3, arr[2]
|
52
|
+
assert_equal 4, arr[3]
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,58 @@
|
|
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{testdependencies}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Matthias Hennemeyer"]
|
12
|
+
s.date = %q{2010-04-20}
|
13
|
+
s.description = %q{Add explicit dependencies to your Rails tests.}
|
14
|
+
s.email = %q{mhennemeyer@me.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/adapters/plain.rb",
|
27
|
+
"lib/adapters/shoulda.rb",
|
28
|
+
"lib/testdependencies.rb",
|
29
|
+
"test/helper.rb",
|
30
|
+
"test/plain_test.rb",
|
31
|
+
"test/shoulda_test.rb",
|
32
|
+
"testdependencies.gemspec"
|
33
|
+
]
|
34
|
+
s.homepage = %q{http://github.com/mhennemeyer/testdependencies}
|
35
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = %q{1.3.6}
|
38
|
+
s.summary = %q{Add explicit dependencies to your Rails tests.}
|
39
|
+
s.test_files = [
|
40
|
+
"test/helper.rb",
|
41
|
+
"test/plain_test.rb",
|
42
|
+
"test/shoulda_test.rb"
|
43
|
+
]
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
53
|
+
end
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Matthias Hennemeyer
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-20 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -45,9 +45,13 @@ files:
|
|
45
45
|
- README.rdoc
|
46
46
|
- Rakefile
|
47
47
|
- VERSION
|
48
|
+
- lib/adapters/plain.rb
|
49
|
+
- lib/adapters/shoulda.rb
|
48
50
|
- lib/testdependencies.rb
|
49
51
|
- test/helper.rb
|
50
|
-
- test/
|
52
|
+
- test/plain_test.rb
|
53
|
+
- test/shoulda_test.rb
|
54
|
+
- testdependencies.gemspec
|
51
55
|
has_rdoc: true
|
52
56
|
homepage: http://github.com/mhennemeyer/testdependencies
|
53
57
|
licenses: []
|
@@ -80,4 +84,5 @@ specification_version: 3
|
|
80
84
|
summary: Add explicit dependencies to your Rails tests.
|
81
85
|
test_files:
|
82
86
|
- test/helper.rb
|
83
|
-
- test/
|
87
|
+
- test/plain_test.rb
|
88
|
+
- test/shoulda_test.rb
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class RegressionTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
def new_user
|
6
|
-
user = Object.new
|
7
|
-
def user.name
|
8
|
-
"Horst"
|
9
|
-
end
|
10
|
-
user
|
11
|
-
end
|
12
|
-
|
13
|
-
test "User has a name" => :new_user do |user|
|
14
|
-
assert_respond_to user, :name
|
15
|
-
user.name
|
16
|
-
end
|
17
|
-
|
18
|
-
test "User name is Horst" => "User has a name" do |name|
|
19
|
-
assert_equal "Horst", name
|
20
|
-
end
|
21
|
-
end
|