Fingertips-on-test-spec 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/LICENSE +20 -0
- data/README +12 -0
- data/Rakefile +30 -0
- data/VERSION +1 -0
- data/dot.autotest +93 -0
- data/lib/test/spec/add_allow_switch.rb +53 -0
- data/lib/test/spec/rails/controller_helpers.rb +40 -0
- data/lib/test/spec/rails/expectations.rb +196 -0
- data/lib/test/spec/rails/macros/authorization.rb +65 -0
- data/lib/test/spec/rails/macros.rb +78 -0
- data/lib/test/spec/rails/request_helpers.rb +11 -0
- data/lib/test/spec/rails/response_helpers.rb +42 -0
- data/lib/test/spec/rails/spec_responder.rb +12 -0
- data/lib/test/spec/rails/test_spec_ext.rb +23 -0
- data/lib/test/spec/rails.rb +41 -0
- data/lib/test/spec/share.rb +48 -0
- data/on-test-spec.gemspec +69 -0
- data/test/add_allow_switch_test.rb +104 -0
- data/test/expectations_test.rb +467 -0
- data/test/macros/authorization_test.rb +80 -0
- data/test/macros/base_test.rb +78 -0
- data/test/share_test.rb +52 -0
- data/test/test_helper.rb +8 -0
- metadata +85 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'test/spec'
|
2
|
+
|
3
|
+
module Test
|
4
|
+
module Spec
|
5
|
+
module Rails
|
6
|
+
module Assertions
|
7
|
+
include ActiveSupport::Testing::Assertions
|
8
|
+
include ActionController::TestCase::Assertions
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Should
|
13
|
+
include Rails::Assertions
|
14
|
+
end
|
15
|
+
|
16
|
+
class ShouldNot
|
17
|
+
include Rails::Assertions
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
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
|
+
module Kernel
|
26
|
+
alias :context_before_on_test_spec :context
|
27
|
+
alias :xcontext_before_on_test_spec :xcontext
|
28
|
+
|
29
|
+
def context(name, superclass=ActiveSupport::TestCase, klass=Test::Spec::TestCase, &block)
|
30
|
+
context_before_on_test_spec(name, superclass, klass, &block)
|
31
|
+
end
|
32
|
+
|
33
|
+
def xcontext(name, superclass=ActiveSupport::TestCase, &block)
|
34
|
+
xcontext_before_on_test_spec(name, superclass, &block)
|
35
|
+
end
|
36
|
+
|
37
|
+
private :context, :xcontext
|
38
|
+
|
39
|
+
alias :describe :context
|
40
|
+
alias :xdescribe :xcontext
|
41
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
$shared_specs = {}
|
2
|
+
|
3
|
+
module Kernel
|
4
|
+
# Stores the passed in block for inclusion in test cases.
|
5
|
+
#
|
6
|
+
# share "User" do
|
7
|
+
# it "should authenticate" do
|
8
|
+
# "me".should == "me"
|
9
|
+
# end
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# describe "User, in general" do
|
13
|
+
# shared_specs_for 'User'
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# describe "User, in another case" do
|
17
|
+
# shared_specs_for 'User'
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# 2 tests, 2 assertions, 0 failures, 0 errors
|
21
|
+
def share(name, &specs_block)
|
22
|
+
$shared_specs[name] = specs_block
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module SharedSpecsInclusionHelper
|
27
|
+
# Include the specified shared specs in this test case.
|
28
|
+
#
|
29
|
+
# share "User" do
|
30
|
+
# it "should authenticate" do
|
31
|
+
# "me".should == "me"
|
32
|
+
# end
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# describe "User, in general" do
|
36
|
+
# shared_specs_for 'User'
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# describe "User, in another case" do
|
40
|
+
# shared_specs_for 'User'
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# 2 tests, 2 assertions, 0 failures, 0 errors
|
44
|
+
def shared_specs_for(name)
|
45
|
+
self.class_eval &$shared_specs[name]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
Test::Unit::TestCase.send(:extend, SharedSpecsInclusionHelper)
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{on-test-spec}
|
8
|
+
s.version = "0.1.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Manfred Stienstra", "Eloy Duran", "Cristi Balan"]
|
12
|
+
s.date = %q{2009-08-24}
|
13
|
+
s.description = %q{Rails plugin to make testing Rails on test/spec easier.}
|
14
|
+
s.email = %q{eloy.de.enige@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"LICENSE",
|
22
|
+
"README",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"dot.autotest",
|
26
|
+
"lib/test/spec/add_allow_switch.rb",
|
27
|
+
"lib/test/spec/rails.rb",
|
28
|
+
"lib/test/spec/rails/controller_helpers.rb",
|
29
|
+
"lib/test/spec/rails/expectations.rb",
|
30
|
+
"lib/test/spec/rails/macros.rb",
|
31
|
+
"lib/test/spec/rails/macros/authorization.rb",
|
32
|
+
"lib/test/spec/rails/request_helpers.rb",
|
33
|
+
"lib/test/spec/rails/response_helpers.rb",
|
34
|
+
"lib/test/spec/rails/spec_responder.rb",
|
35
|
+
"lib/test/spec/rails/test_spec_ext.rb",
|
36
|
+
"lib/test/spec/share.rb",
|
37
|
+
"on-test-spec.gemspec",
|
38
|
+
"test/add_allow_switch_test.rb",
|
39
|
+
"test/expectations_test.rb",
|
40
|
+
"test/macros/authorization_test.rb",
|
41
|
+
"test/macros/base_test.rb",
|
42
|
+
"test/share_test.rb",
|
43
|
+
"test/test_helper.rb"
|
44
|
+
]
|
45
|
+
s.has_rdoc = true
|
46
|
+
s.homepage = %q{http://github.com/Fingertips/on-test-spec}
|
47
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
48
|
+
s.require_paths = ["lib"]
|
49
|
+
s.rubygems_version = %q{1.3.2}
|
50
|
+
s.summary = %q{Rails plugin to make testing Rails on test/spec easier.}
|
51
|
+
s.test_files = [
|
52
|
+
"test/add_allow_switch_test.rb",
|
53
|
+
"test/expectations_test.rb",
|
54
|
+
"test/macros/authorization_test.rb",
|
55
|
+
"test/macros/base_test.rb",
|
56
|
+
"test/share_test.rb",
|
57
|
+
"test/test_helper.rb"
|
58
|
+
]
|
59
|
+
|
60
|
+
if s.respond_to? :specification_version then
|
61
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
62
|
+
s.specification_version = 3
|
63
|
+
|
64
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
65
|
+
else
|
66
|
+
end
|
67
|
+
else
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'rubygems' rescue LoadError
|
2
|
+
|
3
|
+
require 'test/spec'
|
4
|
+
require 'mocha'
|
5
|
+
|
6
|
+
require File.expand_path('../../lib/test/spec/add_allow_switch', __FILE__)
|
7
|
+
|
8
|
+
module Factory
|
9
|
+
def self.run
|
10
|
+
true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
Factory.add_allow_switch :run, :default => true
|
14
|
+
|
15
|
+
describe "Factory with an allow switch on run" do
|
16
|
+
it "should alias the original method" do
|
17
|
+
Factory.respond_to?(:original_run, include_private=true).should == true
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should define a getter and setter" do
|
21
|
+
Factory.should.respond_to(:allow_run)
|
22
|
+
Factory.should.respond_to(:allow_run=)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should switch off" do
|
26
|
+
Factory.allow_run = false
|
27
|
+
lambda {
|
28
|
+
Factory.run
|
29
|
+
}.should.raise(RuntimeError)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should switch on" do
|
33
|
+
Factory.allow_run = true
|
34
|
+
lambda {
|
35
|
+
Factory.run.should == true
|
36
|
+
}.should.not.raise
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class Bunny
|
41
|
+
def hop
|
42
|
+
'Hop hop!'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
Bunny.add_allow_switch :hop
|
46
|
+
|
47
|
+
describe "Bunny with an allow switch on hop" do
|
48
|
+
before do
|
49
|
+
@bunny = Bunny.new
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should alias the original method" do
|
53
|
+
@bunny.respond_to?(:original_hop).should == true
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should define a getter and setter" do
|
57
|
+
Bunny.should.respond_to(:allow_hop)
|
58
|
+
Bunny.should.respond_to(:allow_hop=)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should switch off" do
|
62
|
+
Bunny.allow_hop = false
|
63
|
+
lambda {
|
64
|
+
@bunny.hop
|
65
|
+
}.should.raise(RuntimeError)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should switch on" do
|
69
|
+
Bunny.allow_hop = true
|
70
|
+
lambda {
|
71
|
+
@bunny.hop.should == 'Hop hop!'
|
72
|
+
}.should.not.raise
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
Kernel.add_allow_switch :system
|
78
|
+
|
79
|
+
describe "Kernel with an allow switch on system" do
|
80
|
+
SILENT_COMMANT = 'ls > /dev/null'
|
81
|
+
|
82
|
+
it "should alias the original method" do
|
83
|
+
Kernel.respond_to?(:original_system, include_private=true).should == true
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should define a getter and setter" do
|
87
|
+
Factory.should.respond_to(:allow_system)
|
88
|
+
Factory.should.respond_to(:allow_system=)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should switch off" do
|
92
|
+
Kernel.allow_system = false
|
93
|
+
lambda {
|
94
|
+
Kernel.system(SILENT_COMMANT)
|
95
|
+
}.should.raise(RuntimeError)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should switch on" do
|
99
|
+
Kernel.allow_system = true
|
100
|
+
lambda {
|
101
|
+
Kernel.system(SILENT_COMMANT)
|
102
|
+
}.should.not.raise
|
103
|
+
end
|
104
|
+
end
|