unit_record 0.4.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/CHANGELOG +14 -0
  2. data/LICENSE +20 -0
  3. data/README.markdown +137 -0
  4. data/Rakefile +63 -56
  5. data/lib/active_record/connection_adapters/unit_record_adapter.rb +97 -0
  6. data/lib/unit_record.rb +8 -1
  7. data/lib/unit_record/association_stubbing.rb +39 -0
  8. data/lib/unit_record/column_extension.rb +11 -0
  9. data/lib/unit_record/disconnected_active_record.rb +10 -32
  10. data/lib/unit_record/disconnected_test_case.rb +6 -0
  11. data/test/active_record/connection_adapters/unit_record_adapter_test.rb +103 -0
  12. data/test/db/schema.rb +9 -0
  13. data/test/sample_spec.rb +40 -0
  14. data/test/test_helper.rb +28 -4
  15. data/test/unit_record/association_stubbing_test.rb +37 -0
  16. data/test/unit_record/column_cacher_test.rb +26 -0
  17. data/test/{unit → unit_record}/column_extension_test.rb +1 -1
  18. data/test/{functional → unit_record}/column_test.rb +1 -1
  19. data/test/{functional → unit_record}/controller_test.rb +1 -1
  20. data/test/unit_record/disconnected_active_record_test.rb +52 -0
  21. data/test/{functional → unit_record}/disconnected_fixtures_test.rb +1 -1
  22. data/test/unit_record/disconnected_test_case_test.rb +19 -0
  23. data/vendor/dust-0.1.6/lib/array_extension.rb +5 -0
  24. data/vendor/dust-0.1.6/lib/definition_error.rb +20 -0
  25. data/vendor/dust-0.1.6/lib/dust.rb +8 -0
  26. data/vendor/dust-0.1.6/lib/nil_extension.rb +5 -0
  27. data/vendor/dust-0.1.6/lib/object_extension.rb +62 -0
  28. data/vendor/dust-0.1.6/lib/string_extension.rb +5 -0
  29. data/vendor/dust-0.1.6/lib/symbol_extension.rb +5 -0
  30. data/vendor/dust-0.1.6/lib/test_case_extension.rb +76 -0
  31. data/vendor/dust-0.1.6/rakefile.rb +50 -0
  32. data/vendor/dust-0.1.6/test/all_tests.rb +1 -0
  33. data/vendor/dust-0.1.6/test/failing_with_helper_unit_test.rb +16 -0
  34. data/vendor/dust-0.1.6/test/failing_with_setup_unit_test.rb +16 -0
  35. data/vendor/dust-0.1.6/test/functional_test.rb +12 -0
  36. data/vendor/dust-0.1.6/test/passing_unit_test.rb +11 -0
  37. data/vendor/dust-0.1.6/test/passing_with_helper_unit_test.rb +10 -0
  38. data/vendor/dust-0.1.6/test/passing_with_helpers_unit_test.rb +13 -0
  39. data/vendor/dust-0.1.6/test/passing_with_setup_unit_test.rb +10 -0
  40. data/vendor/dust-0.1.6/test/test_helper.rb +1 -0
  41. metadata +75 -52
  42. data/README +0 -60
  43. data/lib/unit_record/column_cacher.rb +0 -45
  44. data/test/functional/column_cacher_test.rb +0 -19
  45. data/test/functional/disconnected_active_record_test.rb +0 -33
  46. data/test/functional/disconnected_test_case_test.rb +0 -7
  47. data/test/functional/functional_test_helper.rb +0 -4
  48. data/test/unit/unit_test_helper.rb +0 -5
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/functional_test_helper"
1
+ require File.dirname(__FILE__) + "/../test_helper"
2
2
 
3
3
  functional_tests do
4
4
  test "create_fixtures does nothing" do
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + "/../test_helper"
2
+
3
+ functional_tests do
4
+ test "use_transactional_fixtures is false" do
5
+ assert_equal false, Test::Unit::TestCase.use_transactional_fixtures
6
+ end
7
+
8
+ test "trying to use fixtures gives useful message" do
9
+ exception = nil
10
+ begin
11
+ Class.new(Test::Unit::TestCase) do
12
+ fixtures :users
13
+ end
14
+ rescue => exception
15
+ end
16
+ assert_not_nil exception
17
+ assert_equal "Fixtures cannot be used with UnitRecord. ActiveRecord is disconnected; database access is unavailable in unit tests.", exception.message
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ class Array #:nodoc:
2
+ def arrayize
3
+ self
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ module Dust #:nodoc:
2
+ # Dust::DefinitionError is raised when you attempt to define a disallowed method within a test file.
3
+ #
4
+ # Test::Unit::TestCase.disallow_setup!
5
+ #
6
+ # unit_tests do
7
+ # def setup
8
+ # ...
9
+ # end
10
+ #
11
+ # test "name" do
12
+ # ...
13
+ # end
14
+ # end
15
+ #
16
+ # The above code will generate the following error
17
+ # Dust::DefinitionError: setup is not allowed on class Units::[TestClassName]
18
+ class DefinitionError < StandardError
19
+ end
20
+ end
@@ -0,0 +1,8 @@
1
+ require 'test/unit'
2
+ require File.expand_path(File.dirname(__FILE__) + '/object_extension')
3
+ require File.expand_path(File.dirname(__FILE__) + '/array_extension')
4
+ require File.expand_path(File.dirname(__FILE__) + '/nil_extension')
5
+ require File.expand_path(File.dirname(__FILE__) + '/string_extension')
6
+ require File.expand_path(File.dirname(__FILE__) + '/symbol_extension')
7
+ require File.expand_path(File.dirname(__FILE__) + '/test_case_extension')
8
+ require File.expand_path(File.dirname(__FILE__) + '/definition_error')
@@ -0,0 +1,5 @@
1
+ class NilClass #:nodoc:
2
+ def arrayize
3
+ []
4
+ end
5
+ end
@@ -0,0 +1,62 @@
1
+ class Object
2
+ # call-seq: unit_tests(options={}, &block)
3
+ #
4
+ # Used to define a block of unit tests.
5
+ #
6
+ # unit_tests do
7
+ # test "verify something" do
8
+ # ...
9
+ # end
10
+ # end
11
+ #
12
+ # Configuration Options:
13
+ # * allow - Allows you to specify the methods that are allowed despite being disallowed.
14
+ # See Test::Unit::TestCase.disallow_helpers! or Test::Unit::TestCase.disallow_setup! for more info
15
+ def unit_tests(options={}, &block)
16
+ do_tests("Units", options, &block)
17
+ end
18
+
19
+ # call-seq: functional_tests(options={}, &block)
20
+ #
21
+ # Used to define a block of functional tests.
22
+ #
23
+ # functional_tests do
24
+ # test "verify something" do
25
+ # ...
26
+ # end
27
+ # end
28
+ #
29
+ # Configuration Options:
30
+ # * allow - Allows you to specify the methods that are allowed despite being disallowed.
31
+ # See Test::Unit::TestCase.disallow_helpers! or Test::Unit::TestCase.disallow_setup! for more info
32
+ def functional_tests(options={}, &block)
33
+ do_tests("Functionals", options, &block)
34
+ end
35
+
36
+ protected
37
+ def do_tests(type, options, &block) #:nodoc:
38
+ options[:allow] = options[:allow].arrayize
39
+ full_path_file_name = eval "__FILE__", block.binding
40
+ test_name = File.basename(full_path_file_name, ".rb")
41
+ test_class = eval "module #{type}; class #{test_name.to_class_name} < Test::Unit::TestCase; self; end; end"
42
+ test_class.class_eval &block
43
+ check_for_setup(test_class, options)
44
+ check_for_helpers(test_class, options)
45
+ end
46
+
47
+ def check_for_setup(test_class, options) #:nodoc:
48
+ if test_class.instance_methods(false).include?("setup") && Test::Unit::TestCase.disallow_setup? &&
49
+ !options[:allow].include?(:setup)
50
+ raise Dust::DefinitionError.new("setup is not allowed on class #{test_class.name}")
51
+ end
52
+ end
53
+
54
+ def check_for_helpers(test_class, options) #:nodoc:
55
+ test_class.instance_methods(false).each do |method_name|
56
+ if method_name !~ /^test_/ && Test::Unit::TestCase.disallow_helpers? && !options[:allow].include?(method_name.to_sym)
57
+ p method_name.to_sym
58
+ raise Dust::DefinitionError.new("helper methods are not allowed on class #{test_class.name}")
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,5 @@
1
+ class String #:nodoc:
2
+ def to_class_name
3
+ gsub(/(^|_)(.)/) { $2.upcase }
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class Symbol #:nodoc:
2
+ def arrayize
3
+ [self]
4
+ end
5
+ end
@@ -0,0 +1,76 @@
1
+ module Test #:nodoc:
2
+ module Unit #:nodoc:
3
+ class TestCase
4
+ # call-seq: disallow_setup!
5
+ #
6
+ # Used to disallow setup methods in test specifications.
7
+ #
8
+ # Test::Unit::TestCase.disallow_setup!
9
+ #
10
+ # A test specification can override this behavior by passing :setup in the :allow options.
11
+ #
12
+ # unit_tests :allow => :setup do
13
+ # def setup
14
+ # ...
15
+ # end
16
+ #
17
+ # test "verify something" do
18
+ # ...
19
+ # end
20
+ # end
21
+ def self.disallow_setup!
22
+ @disallow_setup = true
23
+ end
24
+
25
+ def self.disallow_setup? #:nodoc:
26
+ @disallow_setup
27
+ end
28
+
29
+ # call-seq: disallow_helpers!
30
+ #
31
+ # Used to disallow helper methods in test specifications.
32
+ #
33
+ # Test::Unit::TestCase.disallow_helper!
34
+ #
35
+ # A test specification can override this behavior by passing the helper name (as a symbol) in the :allow options.
36
+ #
37
+ # unit_tests :allow => [:create_something, :destroy_something] do
38
+ # test "verify something" do
39
+ # ...
40
+ # end
41
+ #
42
+ # def create_something
43
+ # ...
44
+ # end
45
+ #
46
+ # def destroy_something
47
+ # ...
48
+ # end
49
+ # end
50
+ def self.disallow_helpers!
51
+ @disallow_helpers = true
52
+ end
53
+
54
+ def self.disallow_helpers? #:nodoc:
55
+ @disallow_helpers
56
+ end
57
+
58
+ # call-seq: test(name, &block)
59
+ #
60
+ # Used to define a test and assign it a descriptive name.
61
+ #
62
+ # unit_tests do
63
+ # test "verify something" do
64
+ # ...
65
+ # end
66
+ # end
67
+ def self.test(name, &block)
68
+ test_name = "test_#{name.gsub(/[\s]/,'_')}".to_sym
69
+ raise "#{test_name} is already defined in #{self}" if self.instance_methods.include? test_name.to_s
70
+ define_method test_name do
71
+ instance_eval &block
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rake/rdoctask'
4
+ require 'rake/contrib/sshpublisher'
5
+
6
+ task :default => :test
7
+
8
+ task :test do
9
+ require File.dirname(__FILE__) + '/test/all_tests.rb'
10
+ end
11
+
12
+ desc 'Generate RDoc'
13
+ Rake::RDocTask.new do |task|
14
+ task.main = 'README'
15
+ task.title = 'Dust'
16
+ task.rdoc_dir = 'doc'
17
+ task.options << "--line-numbers" << "--inline-source"
18
+ task.rdoc_files.include('README', 'lib/**/*.rb')
19
+ end
20
+
21
+ desc "Upload RDoc to RubyForge"
22
+ task :publish_rdoc => [:rdoc] do
23
+ Rake::SshDirPublisher.new("jaycfields@rubyforge.org", "/var/www/gforge-projects/dust", "doc").upload
24
+ end
25
+
26
+ Gem::manage_gems
27
+
28
+ specification = Gem::Specification.new do |s|
29
+ s.name = "dust"
30
+ s.summary = "Dust is an add on for Test::Unit that allows an alternative test definintion syntax."
31
+ s.version = "0.1.6"
32
+ s.author = 'Jay Fields'
33
+ s.description = "Dust is an add on for Test::Unit that allows an alternative test definintion syntax."
34
+ s.email = 'dust-developer@rubyforge.org'
35
+ s.homepage = 'http://dust.rubyforge.org'
36
+ s.rubyforge_project = 'dust'
37
+
38
+ s.has_rdoc = true
39
+ s.extra_rdoc_files = ['README']
40
+ s.rdoc_options << '--title' << 'Dust' << '--main' << 'README' << '--line-numbers'
41
+
42
+ s.autorequire = 'dust'
43
+ s.files = FileList['{lib,test}/**/*.rb', '[A-Z]*$', 'rakefile.rb'].to_a
44
+ s.test_file = "test/all_tests.rb"
45
+ end
46
+
47
+ Rake::GemPackageTask.new(specification) do |package|
48
+ package.need_zip = false
49
+ package.need_tar = false
50
+ end
@@ -0,0 +1 @@
1
+ Dir['**/*_test.rb'].each { |test_case| require test_case }
@@ -0,0 +1,16 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ begin
4
+ unit_tests do
5
+ Test::Unit::TestCase.disallow_helpers!
6
+ def helper_method
7
+ end
8
+
9
+ test("true"){}
10
+ end
11
+ raise "shouldn't be here"
12
+ rescue Dust::DefinitionError => ex
13
+ raise unless ex.message == "helper methods are not allowed on class Units::FailingWithHelperUnitTest"
14
+ ensure
15
+ Test::Unit::TestCase.class_eval { @disallow_helpers = nil }
16
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ begin
4
+ unit_tests do
5
+ Test::Unit::TestCase.disallow_setup!
6
+ def setup
7
+ end
8
+
9
+ test("true"){}
10
+ end
11
+ raise "shouldn't be here"
12
+ rescue Dust::DefinitionError => ex
13
+ raise unless ex.message == "setup is not allowed on class Units::FailingWithSetupUnitTest"
14
+ ensure
15
+ Test::Unit::TestCase.class_eval { @disallow_setup = nil }
16
+ end
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ functional_tests do
4
+ test "assert true" do
5
+ assert_equal true, true
6
+ end
7
+
8
+ test "class name is Functionals::FunctionalTest" do
9
+ assert_equal "Functionals::FunctionalTest", self.class.name
10
+ end
11
+
12
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ unit_tests do
4
+ test "assert true" do
5
+ assert_equal true, true
6
+ end
7
+
8
+ test "class name is Units::PassingUnitTest" do
9
+ assert_equal "Units::PassingUnitTest", self.class.name
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ Test::Unit::TestCase.disallow_helpers!
4
+ unit_tests :allow => :helper do
5
+ def helper
6
+ end
7
+
8
+ test("true"){}
9
+ end
10
+ Test::Unit::TestCase.class_eval { @disallow_helpers = nil }
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ Test::Unit::TestCase.disallow_helpers!
4
+ unit_tests :allow => [:helper, :helper2] do
5
+ def helper
6
+ end
7
+
8
+ def helper2
9
+ end
10
+
11
+ test("true"){}
12
+ end
13
+ Test::Unit::TestCase.class_eval { @disallow_helpers = nil }
@@ -0,0 +1,10 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ Test::Unit::TestCase.disallow_setup!
4
+ unit_tests :allow => :setup do
5
+ def setup
6
+ end
7
+
8
+ test("true"){}
9
+ end
10
+ Test::Unit::TestCase.class_eval { @disallow_setup = nil }
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + '/../lib/dust'
metadata CHANGED
@@ -1,70 +1,93 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: unit_record
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.4.1
7
- date: 2007-12-10 00:00:00 -05:00
8
- summary: UnitRecord enables unit testing without hitting the database.
9
- require_paths:
10
- - lib
11
- email: daniel.manges@gmail.com
12
- homepage: http://unit-test-ar.rubyforge.org
13
- rubyforge_project: unit-test-ar
14
- description: UnitRecord enables unit testing without hitting the database.
15
- autorequire: unit_record
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.9.0
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Dan Manges
8
+ autorequire: unit_record
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-15 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: UnitRecord enables unit testing without hitting the database.
17
+ email: daniel.manges@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
31
24
  files:
32
- - lib/unit_record.rb
33
- - lib/unit_record/column_cacher.rb
25
+ - lib/active_record/connection_adapters/unit_record_adapter.rb
26
+ - lib/unit_record/association_stubbing.rb
34
27
  - lib/unit_record/column_extension.rb
35
28
  - lib/unit_record/disconnected_active_record.rb
36
29
  - lib/unit_record/disconnected_fixtures.rb
37
30
  - lib/unit_record/disconnected_test_case.rb
38
- - test/test_helper.rb
31
+ - lib/unit_record.rb
32
+ - test/active_record/connection_adapters/unit_record_adapter_test.rb
39
33
  - test/db/schema.rb
40
- - test/functional/column_cacher_test.rb
41
- - test/functional/column_test.rb
42
- - test/functional/controller_test.rb
43
- - test/functional/disconnected_active_record_test.rb
44
- - test/functional/disconnected_fixtures_test.rb
45
- - test/functional/disconnected_test_case_test.rb
46
- - test/functional/functional_test_helper.rb
47
- - test/unit/column_extension_test.rb
48
- - test/unit/unit_test_helper.rb
34
+ - test/sample_spec.rb
35
+ - test/test_helper.rb
36
+ - test/unit_record/association_stubbing_test.rb
37
+ - test/unit_record/column_cacher_test.rb
38
+ - test/unit_record/column_extension_test.rb
39
+ - test/unit_record/column_test.rb
40
+ - test/unit_record/controller_test.rb
41
+ - test/unit_record/disconnected_active_record_test.rb
42
+ - test/unit_record/disconnected_fixtures_test.rb
43
+ - test/unit_record/disconnected_test_case_test.rb
44
+ - vendor/dust-0.1.6/lib/array_extension.rb
45
+ - vendor/dust-0.1.6/lib/definition_error.rb
46
+ - vendor/dust-0.1.6/lib/dust.rb
47
+ - vendor/dust-0.1.6/lib/nil_extension.rb
48
+ - vendor/dust-0.1.6/lib/object_extension.rb
49
+ - vendor/dust-0.1.6/lib/string_extension.rb
50
+ - vendor/dust-0.1.6/lib/symbol_extension.rb
51
+ - vendor/dust-0.1.6/lib/test_case_extension.rb
52
+ - vendor/dust-0.1.6/rakefile.rb
53
+ - vendor/dust-0.1.6/test/all_tests.rb
54
+ - vendor/dust-0.1.6/test/failing_with_helper_unit_test.rb
55
+ - vendor/dust-0.1.6/test/failing_with_setup_unit_test.rb
56
+ - vendor/dust-0.1.6/test/functional_test.rb
57
+ - vendor/dust-0.1.6/test/passing_unit_test.rb
58
+ - vendor/dust-0.1.6/test/passing_with_helper_unit_test.rb
59
+ - vendor/dust-0.1.6/test/passing_with_helpers_unit_test.rb
60
+ - vendor/dust-0.1.6/test/passing_with_setup_unit_test.rb
61
+ - vendor/dust-0.1.6/test/test_helper.rb
49
62
  - CHANGELOG
50
- - README
63
+ - LICENSE
64
+ - README.markdown
51
65
  - Rakefile
52
- test_files: []
53
-
54
- rdoc_options:
55
- - --title
56
- - UnitRecord
57
- - --main
58
- - README
59
- - --line-numbers
60
- extra_rdoc_files:
61
- - README
62
- - CHANGELOG
63
- executables: []
64
-
65
- extensions: []
66
+ has_rdoc: false
67
+ homepage: http://unit-test-ar.rubyforge.org
68
+ post_install_message:
69
+ rdoc_options: []
66
70
 
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
67
85
  requirements: []
68
86
 
69
- dependencies: []
87
+ rubyforge_project: unit-test-ar
88
+ rubygems_version: 1.3.1
89
+ signing_key:
90
+ specification_version: 2
91
+ summary: UnitRecord enables unit testing without hitting the database.
92
+ test_files: []
70
93