Fingertips-on-test-spec 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +4 -0
- data/lib/test/spec/rails.rb +65 -17
- data/lib/test/spec/rails/request_helpers.rb +1 -1
- data/lib/test/spec/rails/response_helpers.rb +1 -1
- data/on-test-spec.gemspec +8 -6
- data/test/add_allow_switch_test.rb +2 -6
- data/test/controller_helpers_test.rb +29 -0
- data/test/expectations_test.rb +2 -8
- data/test/rails_test.rb +100 -0
- data/test/share_test.rb +2 -4
- data/test/test_helper.rb +2 -4
- metadata +8 -5
- data/VERSION +0 -1
- data/lib/test/spec/rails/controller_helpers.rb +0 -40
data/VERSION.yml
ADDED
data/lib/test/spec/rails.rb
CHANGED
@@ -1,36 +1,84 @@
|
|
1
1
|
require 'test/spec'
|
2
2
|
|
3
|
+
require 'active_support/test_case'
|
4
|
+
|
5
|
+
require 'active_record'
|
6
|
+
require 'active_record/test_case'
|
7
|
+
|
8
|
+
require 'action_controller'
|
9
|
+
require 'action_controller/test_case'
|
10
|
+
|
11
|
+
require 'action_view'
|
12
|
+
require 'action_view/test_case'
|
13
|
+
|
14
|
+
%w(test_spec_ext spec_responder expectations).each { |lib| require "test/spec/rails/#{lib}" }
|
15
|
+
Dir[File.dirname(__FILE__) + '/rails/**/*_helpers.rb'].each { |lib| require lib }
|
16
|
+
|
3
17
|
module Test
|
4
18
|
module Spec
|
5
19
|
module Rails
|
6
|
-
|
7
|
-
|
8
|
-
|
20
|
+
def self.extract_test_case_args(args)
|
21
|
+
name = args.map { |a| a.to_s }.join(' ')
|
22
|
+
class_to_test = args.find { |a| a.is_a?(Module) }
|
23
|
+
superclass = test_case_for_class(class_to_test)
|
24
|
+
[name, class_to_test, superclass]
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.test_case_for_class(klass)
|
28
|
+
if klass
|
29
|
+
if klass.ancestors.include?(ActiveRecord::Base)
|
30
|
+
ActiveRecord::TestCase
|
31
|
+
elsif klass.ancestors.include?(ActionController::Base)
|
32
|
+
ActionController::TestCase
|
33
|
+
elsif !klass.is_a?(Class) && klass.to_s.ends_with?('Helper')
|
34
|
+
ActionView::TestCase
|
35
|
+
end
|
36
|
+
end || ActiveSupport::TestCase
|
9
37
|
end
|
10
|
-
end
|
11
|
-
|
12
|
-
class Should
|
13
|
-
include Rails::Assertions
|
14
|
-
end
|
15
|
-
|
16
|
-
class ShouldNot
|
17
|
-
include Rails::Assertions
|
18
38
|
end
|
19
39
|
end
|
20
40
|
end
|
21
41
|
|
22
|
-
%w(test_spec_ext spec_responder expectations).each { |lib| require "test/spec/rails/#{lib}" }
|
23
|
-
Dir[File.dirname(__FILE__) + '/rails/**/*_helpers.rb'].each { |lib| require lib }
|
24
|
-
|
25
42
|
module Kernel
|
26
43
|
alias :context_before_on_test_spec :context
|
27
44
|
alias :xcontext_before_on_test_spec :xcontext
|
28
45
|
|
29
|
-
|
30
|
-
|
46
|
+
# Creates a new test case.
|
47
|
+
#
|
48
|
+
# The description of the test case, can consist from strings and/or the class
|
49
|
+
# that's to be tested.
|
50
|
+
#
|
51
|
+
# If the class inherits from ActiveRecord::Base, ActiveRecord::TestCase will
|
52
|
+
# be used as the test case superclass. In the case of a class which inherits
|
53
|
+
# from ActionController::Base, ActionController::TestCase will be used. And
|
54
|
+
# when given a module which name ends with “Helper”, ActionView::TestCase
|
55
|
+
# will be used. In the latter two cases, the test case will be setup for the
|
56
|
+
# class that's to be tested.
|
57
|
+
#
|
58
|
+
# In all other cases the test case superclass will be ActiveSupport::TestCase.
|
59
|
+
#
|
60
|
+
# Examples:
|
61
|
+
#
|
62
|
+
# describe Member do # "Member"
|
63
|
+
# ...
|
64
|
+
# end
|
65
|
+
#
|
66
|
+
# describe 'On a', MembersController do # "On a MembersController"
|
67
|
+
# ...
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
# describe 'The', MembersHelper, ', concerning dates' do # "The MembersHelper, concerning dates"
|
71
|
+
# ...
|
72
|
+
# end
|
73
|
+
def context(*args, &block)
|
74
|
+
name, class_to_test, superclass = Test::Spec::Rails.extract_test_case_args(args)
|
75
|
+
spec = context_before_on_test_spec(name, superclass) { tests class_to_test if respond_to?(:tests) }
|
76
|
+
spec.testcase.class_eval(&block)
|
77
|
+
spec
|
31
78
|
end
|
32
79
|
|
33
|
-
def xcontext(
|
80
|
+
def xcontext(*args, &block)
|
81
|
+
name, _, superclass = Test::Spec::Rails.extract_test_case_args(args)
|
34
82
|
xcontext_before_on_test_spec(name, superclass, &block)
|
35
83
|
end
|
36
84
|
|
data/on-test-spec.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{on-test-spec}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
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{2009-
|
12
|
+
s.date = %q{2009-09-11}
|
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 = [
|
@@ -21,11 +21,10 @@ Gem::Specification.new do |s|
|
|
21
21
|
"LICENSE",
|
22
22
|
"README",
|
23
23
|
"Rakefile",
|
24
|
-
"VERSION",
|
24
|
+
"VERSION.yml",
|
25
25
|
"dot.autotest",
|
26
26
|
"lib/test/spec/add_allow_switch.rb",
|
27
27
|
"lib/test/spec/rails.rb",
|
28
|
-
"lib/test/spec/rails/controller_helpers.rb",
|
29
28
|
"lib/test/spec/rails/expectations.rb",
|
30
29
|
"lib/test/spec/rails/macros.rb",
|
31
30
|
"lib/test/spec/rails/macros/authorization.rb",
|
@@ -36,23 +35,26 @@ Gem::Specification.new do |s|
|
|
36
35
|
"lib/test/spec/share.rb",
|
37
36
|
"on-test-spec.gemspec",
|
38
37
|
"test/add_allow_switch_test.rb",
|
38
|
+
"test/controller_helpers_test.rb",
|
39
39
|
"test/expectations_test.rb",
|
40
40
|
"test/macros/authorization_test.rb",
|
41
41
|
"test/macros/base_test.rb",
|
42
|
+
"test/rails_test.rb",
|
42
43
|
"test/share_test.rb",
|
43
44
|
"test/test_helper.rb"
|
44
45
|
]
|
45
|
-
s.has_rdoc = true
|
46
46
|
s.homepage = %q{http://github.com/Fingertips/on-test-spec}
|
47
47
|
s.rdoc_options = ["--charset=UTF-8"]
|
48
48
|
s.require_paths = ["lib"]
|
49
|
-
s.rubygems_version = %q{1.3.
|
49
|
+
s.rubygems_version = %q{1.3.5}
|
50
50
|
s.summary = %q{Rails plugin to make testing Rails on test/spec easier.}
|
51
51
|
s.test_files = [
|
52
52
|
"test/add_allow_switch_test.rb",
|
53
|
+
"test/controller_helpers_test.rb",
|
53
54
|
"test/expectations_test.rb",
|
54
55
|
"test/macros/authorization_test.rb",
|
55
56
|
"test/macros/base_test.rb",
|
57
|
+
"test/rails_test.rb",
|
56
58
|
"test/share_test.rb",
|
57
59
|
"test/test_helper.rb"
|
58
60
|
]
|
@@ -1,9 +1,5 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
require 'test/spec'
|
4
|
-
require 'mocha'
|
5
|
-
|
6
|
-
require File.expand_path('../../lib/test/spec/add_allow_switch', __FILE__)
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
require 'test/spec/add_allow_switch'
|
7
3
|
|
8
4
|
module Factory
|
9
5
|
def self.run
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
require 'test/spec/rails/request_helpers'
|
3
|
+
require 'test/spec/rails/response_helpers'
|
4
|
+
|
5
|
+
class ActionControllerClass < ActionController::Base; end
|
6
|
+
|
7
|
+
describe ActionControllerClass, "response helpers for a controller test" do
|
8
|
+
it "should map #status to the response status" do
|
9
|
+
expects(:assert_response).with(:success, 'the message')
|
10
|
+
status.should.be :success, 'the message'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should map #template to the response template" do
|
14
|
+
expects(:assert_template).with('show', 'the message')
|
15
|
+
template.should.be 'show', 'the message'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should map #layout to the response layout" do
|
19
|
+
@response.stubs(:layout).returns('layouts/application')
|
20
|
+
expects(:assert_equal).with('application', 'application', 'the message')
|
21
|
+
layout.should.be 'application', 'the message'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe ActionControllerClass, "request helpers for a controller test" do
|
26
|
+
it "should make @request available as an accessor" do
|
27
|
+
request.should.be @request
|
28
|
+
end
|
29
|
+
end
|
data/test/expectations_test.rb
CHANGED
@@ -1,11 +1,5 @@
|
|
1
|
-
require '
|
2
|
-
require 'test/spec'
|
3
|
-
require 'mocha'
|
4
|
-
|
5
|
-
require 'active_support'
|
6
|
-
require 'active_support/testing/assertions'
|
7
|
-
|
8
|
-
require File.expand_path('../../lib/test/spec/rails/expectations', __FILE__)
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
require 'test/spec/rails'
|
9
3
|
|
10
4
|
module TestingAssertionsThemselves
|
11
5
|
class << self
|
data/test/rails_test.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require File.expand_path("../test_helper", __FILE__)
|
2
|
+
require "test/spec/rails"
|
3
|
+
|
4
|
+
class RegularClass; end
|
5
|
+
class ActiveRecordModel < ActiveRecord::Base; end
|
6
|
+
class ActionControllerClass < ActionController::Base; end
|
7
|
+
module ViewModuleHelper; end
|
8
|
+
|
9
|
+
CLASS_TO_TESTCASE_MAPPINGS = {
|
10
|
+
RegularClass => ActiveSupport::TestCase,
|
11
|
+
ActiveRecordModel => ActiveRecord::TestCase,
|
12
|
+
ActionControllerClass => ActionController::TestCase,
|
13
|
+
ViewModuleHelper => ActionView::TestCase
|
14
|
+
}
|
15
|
+
|
16
|
+
describe "A test case with a traditional, string only, description" do
|
17
|
+
test_case = self
|
18
|
+
|
19
|
+
it "should inherit from ActiveSupport::TestCase" do
|
20
|
+
test_case.superclass.should.be ActiveSupport::TestCase
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have the description given" do
|
24
|
+
test_case.name.should ==
|
25
|
+
"A test case with a traditional, string only, description"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "A test case for an", ActionControllerClass do
|
30
|
+
test_case = self
|
31
|
+
|
32
|
+
it "should have the class assigned as the class to test" do
|
33
|
+
test_case.controller_class.should.be ActionControllerClass
|
34
|
+
@controller.should.be.instance_of ActionControllerClass
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "A test case for a", ViewModuleHelper do
|
39
|
+
test_case = self
|
40
|
+
|
41
|
+
it "should have the module assigned as the module to test" do
|
42
|
+
test_case.helper_class.should.be ViewModuleHelper
|
43
|
+
test_case.ancestors.should.include ViewModuleHelper
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
CLASS_TO_TESTCASE_MAPPINGS.each do |test_class, expected_test_case|
|
48
|
+
|
49
|
+
describe test_class do
|
50
|
+
test_case = self
|
51
|
+
|
52
|
+
it "should inherit from #{expected_test_case}" do
|
53
|
+
test_case.superclass.should.be expected_test_case
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should use the model class name as the description" do
|
57
|
+
test_case.name.should == test_class.to_s
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "A test case with prepended description for", test_class do
|
62
|
+
test_case = self
|
63
|
+
|
64
|
+
it "should inherit from #{expected_test_case}" do
|
65
|
+
test_case.superclass.should.be expected_test_case
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should have appended the model class name to the description" do
|
69
|
+
test_case.name.should ==
|
70
|
+
"A test case with prepended description for #{test_class}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe test_class, "test case with a model class and an appended description" do
|
75
|
+
test_case = self
|
76
|
+
|
77
|
+
it "should inherit from #{expected_test_case}" do
|
78
|
+
test_case.superclass.should.be expected_test_case
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should have prepended the model class name to the description" do
|
82
|
+
test_case.name.should ==
|
83
|
+
"#{test_class} test case with a model class and an appended description"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "An", test_class, "test case with a model class and a prepended _and_ appended description" do
|
88
|
+
test_case = self
|
89
|
+
|
90
|
+
it "should inherit from #{expected_test_case}" do
|
91
|
+
test_case.superclass.should.be expected_test_case
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should have inserted the model class name in the middle of the description" do
|
95
|
+
test_case.name.should ==
|
96
|
+
"An #{test_class} test case with a model class and a prepended _and_ appended description"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
data/test/share_test.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
require '
|
2
|
-
require 'test/spec'
|
3
|
-
|
4
|
-
require File.expand_path('../../lib/test/spec/share', __FILE__)
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
require 'test/spec/share'
|
5
3
|
|
6
4
|
class DummyMock
|
7
5
|
extend SharedSpecsInclusionHelper
|
data/test/test_helper.rb
CHANGED
@@ -2,7 +2,5 @@ require 'rubygems' rescue LoadError
|
|
2
2
|
require 'test/spec'
|
3
3
|
require 'mocha'
|
4
4
|
|
5
|
-
|
6
|
-
require '
|
7
|
-
|
8
|
-
$:.unshift(File.expand_path('../../lib', __FILE__))
|
5
|
+
$:.unshift(File.expand_path('../../lib', __FILE__))
|
6
|
+
require 'test/spec/rails'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Fingertips-on-test-spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
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: 2009-
|
14
|
+
date: 2009-09-11 00:00:00 -07:00
|
15
15
|
default_executable:
|
16
16
|
dependencies: []
|
17
17
|
|
@@ -29,11 +29,10 @@ files:
|
|
29
29
|
- LICENSE
|
30
30
|
- README
|
31
31
|
- Rakefile
|
32
|
-
- VERSION
|
32
|
+
- VERSION.yml
|
33
33
|
- dot.autotest
|
34
34
|
- lib/test/spec/add_allow_switch.rb
|
35
35
|
- lib/test/spec/rails.rb
|
36
|
-
- lib/test/spec/rails/controller_helpers.rb
|
37
36
|
- lib/test/spec/rails/expectations.rb
|
38
37
|
- lib/test/spec/rails/macros.rb
|
39
38
|
- lib/test/spec/rails/macros/authorization.rb
|
@@ -44,12 +43,14 @@ files:
|
|
44
43
|
- lib/test/spec/share.rb
|
45
44
|
- on-test-spec.gemspec
|
46
45
|
- test/add_allow_switch_test.rb
|
46
|
+
- test/controller_helpers_test.rb
|
47
47
|
- test/expectations_test.rb
|
48
48
|
- test/macros/authorization_test.rb
|
49
49
|
- test/macros/base_test.rb
|
50
|
+
- test/rails_test.rb
|
50
51
|
- test/share_test.rb
|
51
52
|
- test/test_helper.rb
|
52
|
-
has_rdoc:
|
53
|
+
has_rdoc: false
|
53
54
|
homepage: http://github.com/Fingertips/on-test-spec
|
54
55
|
licenses:
|
55
56
|
post_install_message:
|
@@ -78,8 +79,10 @@ specification_version: 3
|
|
78
79
|
summary: Rails plugin to make testing Rails on test/spec easier.
|
79
80
|
test_files:
|
80
81
|
- test/add_allow_switch_test.rb
|
82
|
+
- test/controller_helpers_test.rb
|
81
83
|
- test/expectations_test.rb
|
82
84
|
- test/macros/authorization_test.rb
|
83
85
|
- test/macros/base_test.rb
|
86
|
+
- test/rails_test.rb
|
84
87
|
- test/share_test.rb
|
85
88
|
- test/test_helper.rb
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.2
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'action_controller/test_case'
|
2
|
-
|
3
|
-
module Test
|
4
|
-
module Spec
|
5
|
-
module Rails
|
6
|
-
module Controller
|
7
|
-
module ClassMethods
|
8
|
-
# Sets up the test environment before every functional test
|
9
|
-
def tests(controller_class)
|
10
|
-
setups << lambda { setup_request_environment(controller_class) }
|
11
|
-
end
|
12
|
-
end
|
13
|
-
module InstanceMethods
|
14
|
-
include ActionController::TestProcess
|
15
|
-
include ActionController::TestCase::Assertions
|
16
|
-
|
17
|
-
attr_reader :controller
|
18
|
-
|
19
|
-
# Sets up the test environment for functional tests
|
20
|
-
def setup_request_environment(controller_class)
|
21
|
-
controller_class.class_eval do
|
22
|
-
def rescue_action(e)
|
23
|
-
raise e
|
24
|
-
end
|
25
|
-
end
|
26
|
-
@controller = controller_class.new
|
27
|
-
@controller.request = @request = ActionController::TestRequest.new
|
28
|
-
@response = ActionController::TestResponse.new
|
29
|
-
|
30
|
-
@controller.params = {}
|
31
|
-
@controller.send(:initialize_current_url)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
ActiveSupport::TestCase.send(:extend, Test::Spec::Rails::Controller::ClassMethods)
|
40
|
-
ActiveSupport::TestCase.send(:include, Test::Spec::Rails::Controller::InstanceMethods)
|