jakewendt-simply_testable 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +42 -0
- data/generators/simply_testable/USAGE +0 -0
- data/generators/simply_testable/simply_testable_generator.rb +72 -0
- data/lib/jakewendt-simply_testable.rb +1 -0
- data/lib/simply_testable.rb +33 -0
- data/lib/simply_testable/action_controller_extension.rb +6 -0
- data/lib/simply_testable/action_controller_extension/accessible_via_format.rb +4 -0
- data/lib/simply_testable/action_controller_extension/accessible_via_protocol.rb +403 -0
- data/lib/simply_testable/action_controller_extension/accessible_via_user.rb +452 -0
- data/lib/simply_testable/action_controller_extension/routing.rb +27 -0
- data/lib/simply_testable/action_controller_extension/test_case.rb +23 -0
- data/lib/simply_testable/acts_as_list.rb +41 -0
- data/lib/simply_testable/assertions.rb +49 -0
- data/lib/simply_testable/associations.rb +222 -0
- data/lib/simply_testable/attributes.rb +240 -0
- data/lib/simply_testable/declarative.rb +57 -0
- data/lib/simply_testable/errors.rb +14 -0
- data/lib/simply_testable/pending.rb +73 -0
- data/lib/simply_testable/test_case.rb +65 -0
- metadata +102 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
module SimplyTestable::Declarative
|
2
|
+
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ClassMethods
|
5
|
+
base.class_eval do
|
6
|
+
class << self
|
7
|
+
alias_method_chain :test, :verbosity
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
|
14
|
+
def test_with_verbosity(name,&block)
|
15
|
+
test_without_verbosity(name,&block)
|
16
|
+
|
17
|
+
test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
|
18
|
+
define_method("_#{test_name}_with_verbosity") do
|
19
|
+
print "\n#{self.class.name.gsub(/Test$/,'').titleize} #{name}: "
|
20
|
+
send("_#{test_name}_without_verbosity")
|
21
|
+
end
|
22
|
+
#
|
23
|
+
# can't do this.
|
24
|
+
# alias_method_chain test_name, :verbosity
|
25
|
+
# end up with 2 methods that begin
|
26
|
+
# with 'test_' so they both get run
|
27
|
+
#
|
28
|
+
alias_method "_#{test_name}_without_verbosity".to_sym,
|
29
|
+
test_name
|
30
|
+
alias_method test_name,
|
31
|
+
"_#{test_name}_with_verbosity".to_sym
|
32
|
+
end
|
33
|
+
|
34
|
+
end # ClassMethods
|
35
|
+
|
36
|
+
end
|
37
|
+
require 'active_support'
|
38
|
+
require 'active_support/test_case'
|
39
|
+
ActiveSupport::TestCase.send(:include,SimplyTestable::Declarative)
|
40
|
+
|
41
|
+
Rails.backtrace_cleaner.add_silencer {|line|
|
42
|
+
# line =~ /\/test\/.*\.\.\/declarative\.rb:/
|
43
|
+
# Due to my modification, every error is accompanied by
|
44
|
+
# 3 additional and unnecessary lines like ...
|
45
|
+
# /test/functional/../declarative.rb:21:in `_test_should_change_locale_to_es_without_verbosity'
|
46
|
+
#/test/functional/../declarative.rb:21:in `send'
|
47
|
+
#/test/functional/../declarative.rb:21:in `_test_should_change_locale_to_es_with_verbosity']:
|
48
|
+
#
|
49
|
+
# in rvm/jruby the error is passing through
|
50
|
+
# test/declarative.rb:21:in `_test_should_NOT_create_new_user_if_invitation_update_fails_with_verbosity']:
|
51
|
+
|
52
|
+
# /Users/jakewendt/github_repo/jakewendt/ucb_ccls_clic/vendor/plugins/ucb_ccls_engine/rails/../test/helpers/declarative.rb:21:in `_test_AWiHTTP_should_get_show_with_admin_login_with_verbosity'
|
53
|
+
|
54
|
+
# This doesn't seem to work at all in the plugin engine.
|
55
|
+
# line =~ /test.*\/declarative\.rb:/
|
56
|
+
line =~ /simply_testable\/declarative\.rb:/
|
57
|
+
} if defined? Rails
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module SimplyTestable::Errors
|
2
|
+
def self.included(base)
|
3
|
+
base.send(:include,InstanceMethods)
|
4
|
+
end
|
5
|
+
module InstanceMethods
|
6
|
+
def on_attr_and_type(attribute,type)
|
7
|
+
attribute = attribute.to_s
|
8
|
+
return nil unless @errors.has_key?(attribute)
|
9
|
+
@errors[attribute].collect(&:type).include?(type)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end # SimplyTestable::Errors
|
13
|
+
ActiveRecord::Errors.send(:include,
|
14
|
+
SimplyTestable::Errors)
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# Some code from jeremymcanally's "pending"
|
2
|
+
# http://github.com/jeremymcanally/pending/tree/master
|
3
|
+
|
4
|
+
module ActiveSupport
|
5
|
+
module Testing
|
6
|
+
module Pending
|
7
|
+
|
8
|
+
unless defined?(Spec)
|
9
|
+
|
10
|
+
@@pending_cases = []
|
11
|
+
@@at_exit = false
|
12
|
+
|
13
|
+
def pending(description = "", &block)
|
14
|
+
if description.is_a?(Symbol)
|
15
|
+
is_pending = $tags[description]
|
16
|
+
return block.call unless is_pending
|
17
|
+
end
|
18
|
+
|
19
|
+
if block_given?
|
20
|
+
failed = false
|
21
|
+
|
22
|
+
begin
|
23
|
+
block.call
|
24
|
+
rescue Exception
|
25
|
+
failed = true
|
26
|
+
end
|
27
|
+
|
28
|
+
flunk("<#{description}> did not fail.") unless failed
|
29
|
+
end
|
30
|
+
|
31
|
+
caller[0] =~ (/(.*):(.*):in `(.*)'/)
|
32
|
+
#puts caller.inspect
|
33
|
+
|
34
|
+
# looks like we lose the name of the 'method' in 1.9.1
|
35
|
+
#"/Users/jakewendt/github_repo/jakewendt/ucb_ccls_homex/test/unit/subject_test.rb:145:in `block in <class:SubjectTest>'",
|
36
|
+
|
37
|
+
# @@pending_cases << "#{$3} at #{$1}, line #{$2}"
|
38
|
+
# Gotta remember these as the next Regex will overwrite them.
|
39
|
+
filename = $1
|
40
|
+
linenumber = $2
|
41
|
+
# ruby 1.8.7
|
42
|
+
# Hx/Addresses Controller should NOT create new address with employee login and invalid address:
|
43
|
+
# ruby 1.9.1
|
44
|
+
#Hx/Addresses Controller block (2 levels) in <class:AddressesControllerTest>:
|
45
|
+
testmethod = $3
|
46
|
+
|
47
|
+
model = self.class.to_s.gsub(/Test$/,'').titleize
|
48
|
+
method = testmethod.gsub(/_/,' ').gsub(/^test /,'')
|
49
|
+
@@pending_cases << "#{model} #{method}:\n.\t#{filename} line #{linenumber}"
|
50
|
+
# @@pending_cases << "#{testmethod} at #{filename}, line #{linenumber}"
|
51
|
+
print "P"
|
52
|
+
|
53
|
+
@@at_exit ||= begin
|
54
|
+
at_exit do
|
55
|
+
# For some reason, special characters don't always
|
56
|
+
# print the way you would expect. Leading white space (tabs)
|
57
|
+
# and some carriage returns just weren't happening?
|
58
|
+
# Is this at_exit doing some parsing??
|
59
|
+
puts "\nPending Cases:"
|
60
|
+
@@pending_cases.each do |test_case|
|
61
|
+
puts test_case
|
62
|
+
end
|
63
|
+
puts " \n"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
require 'active_support/test_case'
|
73
|
+
ActiveSupport::TestCase.send(:include, ActiveSupport::Testing::Pending)
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module SimplyTestable::TestCase
|
2
|
+
|
3
|
+
def self.included(base)
|
4
|
+
base.extend(ClassMethods)
|
5
|
+
base.send(:include, InstanceMethods)
|
6
|
+
base.class_eval do
|
7
|
+
# class << self
|
8
|
+
alias_method_chain :method_missing, :create_object
|
9
|
+
# end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
|
15
|
+
# I don't like this quick and dirty name
|
16
|
+
def st_model_name
|
17
|
+
self.name.demodulize.sub(/Test$/,'')
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
module InstanceMethods
|
23
|
+
|
24
|
+
def model_name
|
25
|
+
# self.class.name.sub(/Test$/,'')
|
26
|
+
# self.class.name.demodulize.sub(/Test$/,'')
|
27
|
+
self.class.st_model_name
|
28
|
+
end
|
29
|
+
|
30
|
+
def method_missing_with_create_object(symb,*args, &block)
|
31
|
+
method = symb.to_s
|
32
|
+
# if method =~ /^create_(.+)(\!?)$/
|
33
|
+
if method =~ /^create_([^!]+)(!?)$/
|
34
|
+
factory = if( $1 == 'object' )
|
35
|
+
# doesn't work for controllers yet. Need to consider
|
36
|
+
# singular and plural as well as "tests" method.
|
37
|
+
# Probably should just use the explicit factory
|
38
|
+
# name in the controller tests.
|
39
|
+
# self.class.name.sub(/Test$/,'').underscore
|
40
|
+
model_name.underscore
|
41
|
+
else
|
42
|
+
$1
|
43
|
+
end
|
44
|
+
bang = $2
|
45
|
+
options = args.extract_options!
|
46
|
+
if bang.blank?
|
47
|
+
record = Factory.build(factory,options)
|
48
|
+
record.attributes = options # occassionally needed (study_subject_id)
|
49
|
+
record.save
|
50
|
+
record
|
51
|
+
else
|
52
|
+
Factory(factory,options)
|
53
|
+
end
|
54
|
+
else
|
55
|
+
# super(symb,*args, &block)
|
56
|
+
method_missing_without_create_object(symb,*args, &block)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end # InstanceMethods
|
61
|
+
end # SimplyTestable::TestCase
|
62
|
+
require 'active_support'
|
63
|
+
require 'active_support/test_case'
|
64
|
+
ActiveSupport::TestCase.send(:include,
|
65
|
+
SimplyTestable::TestCase)
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jakewendt-simply_testable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 6
|
9
|
+
- 0
|
10
|
+
version: 1.6.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jake
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-02-10 00:00:00 -08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: ssl_requirement
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 27
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 1
|
33
|
+
- 0
|
34
|
+
version: 0.1.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: longer description of your gem
|
38
|
+
email: github@jake.otherinbox.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- LICENSE
|
45
|
+
- README.rdoc
|
46
|
+
files:
|
47
|
+
- generators/simply_testable/USAGE
|
48
|
+
- generators/simply_testable/simply_testable_generator.rb
|
49
|
+
- lib/jakewendt-simply_testable.rb
|
50
|
+
- lib/simply_testable.rb
|
51
|
+
- lib/simply_testable/action_controller_extension.rb
|
52
|
+
- lib/simply_testable/action_controller_extension/accessible_via_format.rb
|
53
|
+
- lib/simply_testable/action_controller_extension/accessible_via_protocol.rb
|
54
|
+
- lib/simply_testable/action_controller_extension/accessible_via_user.rb
|
55
|
+
- lib/simply_testable/action_controller_extension/routing.rb
|
56
|
+
- lib/simply_testable/action_controller_extension/test_case.rb
|
57
|
+
- lib/simply_testable/acts_as_list.rb
|
58
|
+
- lib/simply_testable/assertions.rb
|
59
|
+
- lib/simply_testable/associations.rb
|
60
|
+
- lib/simply_testable/attributes.rb
|
61
|
+
- lib/simply_testable/declarative.rb
|
62
|
+
- lib/simply_testable/errors.rb
|
63
|
+
- lib/simply_testable/pending.rb
|
64
|
+
- lib/simply_testable/test_case.rb
|
65
|
+
- LICENSE
|
66
|
+
- README.rdoc
|
67
|
+
has_rdoc: true
|
68
|
+
homepage: http://github.com/jakewendt/simply_testable
|
69
|
+
licenses: []
|
70
|
+
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
hash: 3
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
requirements: []
|
95
|
+
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 1.5.0
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: one-line summary of your gem
|
101
|
+
test_files: []
|
102
|
+
|