on-test-spec 0.2.4 → 0.2.5
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/VERSION.yml +2 -2
- data/lib/test/spec/add_allow_switch.rb +4 -4
- data/lib/test/spec/rails.rb +15 -2
- data/on-test-spec.gemspec +8 -4
- data/test/add_allow_switch_test.rb +24 -1
- data/test/rails_test.rb +16 -1
- metadata +2 -2
data/VERSION.yml
CHANGED
@@ -11,9 +11,9 @@ class Class
|
|
11
11
|
alias_method "original_#{method}", method
|
12
12
|
|
13
13
|
eval %{
|
14
|
-
def #{method}(*args)
|
14
|
+
def #{method}(*args, &block)
|
15
15
|
if allow_#{method}
|
16
|
-
original_#{method}(*args)
|
16
|
+
original_#{method}(*args, &block)
|
17
17
|
else
|
18
18
|
raise RuntimeError, "You're trying to call `#{method}' on `#{self}', which you probably don't want in a test."
|
19
19
|
end
|
@@ -40,9 +40,9 @@ class Module
|
|
40
40
|
alias_method "original_#{method}", method
|
41
41
|
|
42
42
|
eval %{
|
43
|
-
def #{method}(*args)
|
43
|
+
def #{method}(*args, &block)
|
44
44
|
if allow_#{method}
|
45
|
-
original_#{method}(*args)
|
45
|
+
original_#{method}(*args, &block)
|
46
46
|
else
|
47
47
|
raise RuntimeError, "You're trying to call `#{method}' on `#{self}', which you probably don't want in a test."
|
48
48
|
end
|
data/lib/test/spec/rails.rb
CHANGED
@@ -18,9 +18,12 @@ module Test
|
|
18
18
|
module Spec
|
19
19
|
module Rails
|
20
20
|
def self.extract_test_case_args(args)
|
21
|
-
name = args.map { |a| a.to_s }.join(' ')
|
22
21
|
class_to_test = args.find { |a| a.is_a?(Module) }
|
23
22
|
superclass = test_case_for_class(class_to_test)
|
23
|
+
|
24
|
+
args.delete(class_to_test) if superclass == class_to_test
|
25
|
+
name = args.map { |a| a.to_s }.join(' ')
|
26
|
+
|
24
27
|
[name, class_to_test, superclass]
|
25
28
|
end
|
26
29
|
|
@@ -30,6 +33,8 @@ module Test
|
|
30
33
|
ActiveRecord::TestCase
|
31
34
|
elsif klass.ancestors.include?(ActionController::Base)
|
32
35
|
ActionController::TestCase
|
36
|
+
elsif klass.ancestors.include?(ActiveSupport::TestCase)
|
37
|
+
klass
|
33
38
|
elsif !klass.is_a?(Class) && klass.to_s.ends_with?('Helper')
|
34
39
|
ActionView::TestCase
|
35
40
|
end
|
@@ -55,6 +60,10 @@ module Kernel
|
|
55
60
|
# will be used. In the latter two cases, the test case will be setup for the
|
56
61
|
# class that's to be tested.
|
57
62
|
#
|
63
|
+
# If the class inherits from ActiveSupport::TestCase, it will be used as both
|
64
|
+
# the class to be tested and as the test case superclass (this is how test-spec
|
65
|
+
# works without on-test-spec).
|
66
|
+
#
|
58
67
|
# In all other cases the test case superclass will be ActiveSupport::TestCase.
|
59
68
|
#
|
60
69
|
# Examples:
|
@@ -70,6 +79,10 @@ module Kernel
|
|
70
79
|
# describe 'The', MembersHelper, ', concerning dates' do # "The MembersHelper, concerning dates"
|
71
80
|
# ...
|
72
81
|
# end
|
82
|
+
#
|
83
|
+
# describe 'Creating an account and posting a comment', ActiveSupport::IntegrationTest do # Creating an account and posting a comment ActionController::IntegrationTest
|
84
|
+
# ...
|
85
|
+
# end
|
73
86
|
def context(*args, &block)
|
74
87
|
name, class_to_test, superclass = Test::Spec::Rails.extract_test_case_args(args)
|
75
88
|
spec = context_before_on_test_spec(name, superclass) { tests class_to_test if respond_to?(:tests) }
|
@@ -86,4 +99,4 @@ module Kernel
|
|
86
99
|
|
87
100
|
alias :describe :context
|
88
101
|
alias :xdescribe :xcontext
|
89
|
-
end
|
102
|
+
end
|
data/on-test-spec.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{on-test-spec}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Manfred Stienstra", "Eloy Duran", "Cristi Balan"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-05-27}
|
13
13
|
s.description = %q{Rails plugin to make testing Rails on test/spec easier.}
|
14
14
|
s.email = %q{eloy.de.enige@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
"lib/test/spec/rails/expectations.rb",
|
30
30
|
"lib/test/spec/rails/macros.rb",
|
31
31
|
"lib/test/spec/rails/macros/authorization.rb",
|
32
|
+
"lib/test/spec/rails/macros/response.rb",
|
32
33
|
"lib/test/spec/rails/request_helpers.rb",
|
33
34
|
"lib/test/spec/rails/response_helpers.rb",
|
34
35
|
"lib/test/spec/rails/spec_responder.rb",
|
@@ -40,6 +41,7 @@ Gem::Specification.new do |s|
|
|
40
41
|
"test/expectations_test.rb",
|
41
42
|
"test/macros/authorization_test.rb",
|
42
43
|
"test/macros/base_test.rb",
|
44
|
+
"test/macros/response_test.rb",
|
43
45
|
"test/rails_test.rb",
|
44
46
|
"test/share_test.rb",
|
45
47
|
"test/test_helper.rb",
|
@@ -56,6 +58,7 @@ Gem::Specification.new do |s|
|
|
56
58
|
"test/expectations_test.rb",
|
57
59
|
"test/macros/authorization_test.rb",
|
58
60
|
"test/macros/base_test.rb",
|
61
|
+
"test/macros/response_test.rb",
|
59
62
|
"test/rails_test.rb",
|
60
63
|
"test/share_test.rb",
|
61
64
|
"test/test_helper.rb",
|
@@ -72,3 +75,4 @@ Gem::Specification.new do |s|
|
|
72
75
|
else
|
73
76
|
end
|
74
77
|
end
|
78
|
+
|
@@ -5,8 +5,13 @@ module Factory
|
|
5
5
|
def self.run
|
6
6
|
true
|
7
7
|
end
|
8
|
+
|
9
|
+
def self.ran(name, &block)
|
10
|
+
block.call("#{name} was run")
|
11
|
+
end
|
8
12
|
end
|
9
13
|
Factory.add_allow_switch :run, :default => true
|
14
|
+
Factory.add_allow_switch :ran
|
10
15
|
|
11
16
|
describe "Factory with an allow switch on run" do
|
12
17
|
it "should alias the original method" do
|
@@ -31,13 +36,25 @@ describe "Factory with an allow switch on run" do
|
|
31
36
|
Factory.run.should == true
|
32
37
|
}.should.not.raise
|
33
38
|
end
|
39
|
+
|
40
|
+
it "should forward passed blocks and arguments" do
|
41
|
+
Factory.allow_ran = true
|
42
|
+
Factory.ran('Machine') do |name|
|
43
|
+
name + '!'
|
44
|
+
end.should == 'Machine was run!'
|
45
|
+
end
|
34
46
|
end
|
35
47
|
|
36
48
|
class Bunny
|
49
|
+
def hip(name, &block)
|
50
|
+
block.call("#{name} is hip")
|
51
|
+
end
|
52
|
+
|
37
53
|
def hop
|
38
54
|
'Hop hop!'
|
39
55
|
end
|
40
56
|
end
|
57
|
+
Bunny.add_allow_switch :hip
|
41
58
|
Bunny.add_allow_switch :hop
|
42
59
|
|
43
60
|
describe "Bunny with an allow switch on hop" do
|
@@ -67,9 +84,15 @@ describe "Bunny with an allow switch on hop" do
|
|
67
84
|
@bunny.hop.should == 'Hop hop!'
|
68
85
|
}.should.not.raise
|
69
86
|
end
|
87
|
+
|
88
|
+
it "should forward passed blocks and arguments" do
|
89
|
+
Bunny.allow_hip = true
|
90
|
+
@bunny.hip('Bunny') do |name|
|
91
|
+
name + '!'
|
92
|
+
end.should == 'Bunny is hip!'
|
93
|
+
end
|
70
94
|
end
|
71
95
|
|
72
|
-
|
73
96
|
Kernel.add_allow_switch :system
|
74
97
|
|
75
98
|
describe "Kernel with an allow switch on system" do
|
data/test/rails_test.rb
CHANGED
@@ -4,6 +4,7 @@ require "test/spec/rails"
|
|
4
4
|
class RegularClass; end
|
5
5
|
class ActiveRecordModel < ActiveRecord::Base; end
|
6
6
|
class ActionControllerClass < ActionController::Base; end
|
7
|
+
class ActiveSupportTestCaseClass < ActiveSupport::TestCase; end
|
7
8
|
module ViewModuleHelper; end
|
8
9
|
|
9
10
|
CLASS_TO_TESTCASE_MAPPINGS = {
|
@@ -35,6 +36,20 @@ describe "A test case for an", ActionControllerClass do
|
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
39
|
+
describe "A test case for an ActiveSupport::TestCase descendant", ActiveSupportTestCaseClass do
|
40
|
+
test_case = self
|
41
|
+
|
42
|
+
it "should have itself assigned as the class to test and as the superclass" do
|
43
|
+
test_case.ancestors.should.include ActiveSupportTestCaseClass
|
44
|
+
test_case.superclass.should.be ActiveSupportTestCaseClass
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should not include itself in the description" do
|
48
|
+
test_case.name.should ==
|
49
|
+
"A test case for an ActiveSupport::TestCase descendant"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
38
53
|
describe "A test case for a", ViewModuleHelper do
|
39
54
|
test_case = self
|
40
55
|
|
@@ -97,4 +112,4 @@ CLASS_TO_TESTCASE_MAPPINGS.each do |test_class, expected_test_case|
|
|
97
112
|
end
|
98
113
|
end
|
99
114
|
|
100
|
-
end
|
115
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: on-test-spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manfred Stienstra
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date:
|
14
|
+
date: 2010-05-27 00:00:00 +02:00
|
15
15
|
default_executable:
|
16
16
|
dependencies: []
|
17
17
|
|