test-belt 0.2.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.gitignore +2 -1
  2. data/Gemfile.lock +23 -0
  3. data/lib/test_belt/callbacks.rb +22 -0
  4. data/lib/test_belt/callbacks/case.rb +86 -0
  5. data/lib/test_belt/callbacks/suite.rb +106 -0
  6. data/lib/test_belt/callbacks/test.rb +58 -0
  7. data/lib/test_belt/context.rb +40 -0
  8. data/lib/test_belt/default_test.rb +18 -0
  9. data/lib/test_belt/helper.rb +24 -3
  10. data/lib/test_belt/matchers.rb +29 -0
  11. data/lib/test_belt/matchers/base.rb +21 -0
  12. data/lib/test_belt/matchers/have_accessors.rb +23 -0
  13. data/lib/test_belt/matchers/have_class_methods.rb +40 -0
  14. data/lib/test_belt/matchers/have_files.rb +38 -0
  15. data/lib/test_belt/matchers/have_instance_methods.rb +44 -0
  16. data/lib/test_belt/matchers/have_readers.rb +26 -0
  17. data/lib/test_belt/matchers/have_writers.rb +30 -0
  18. data/lib/test_belt/should.rb +76 -0
  19. data/lib/test_belt/skip.rb +41 -0
  20. data/lib/test_belt/subject.rb +47 -0
  21. data/lib/test_belt/version.rb +1 -1
  22. data/test/callbacks_test.rb +172 -0
  23. data/test/fixtures/{shoulda_macros/thing.rb → thing.rb} +0 -0
  24. data/test/helpers_test.rb +175 -0
  25. data/test/matchers_test.rb +135 -0
  26. data/test/rake_tasks_test.rb +8 -17
  27. metadata +33 -31
  28. data/lib/test_belt/shoulda_macros.rb +0 -9
  29. data/lib/test_belt/shoulda_macros/classes.rb +0 -105
  30. data/lib/test_belt/shoulda_macros/context.rb +0 -25
  31. data/lib/test_belt/shoulda_macros/files.rb +0 -49
  32. data/lib/test_belt/test_unit.rb +0 -8
  33. data/lib/test_belt/test_unit/context.rb +0 -71
  34. data/lib/test_belt/test_unit/runner.rb +0 -48
  35. data/lib/test_belt/test_unit/test_case.rb +0 -26
  36. data/test/shoulda_macros/classes_test.rb +0 -58
  37. data/test/shoulda_macros/context_test.rb +0 -28
  38. data/test/shoulda_macros/files_test.rb +0 -36
  39. data/test/test_unit/context_test.rb +0 -65
  40. data/test/test_unit/runner_test.rb +0 -31
  41. data/test/test_unit/test_case_test.rb +0 -30
@@ -1,9 +0,0 @@
1
- require 'shoulda'
2
-
3
- module TestBelt; end
4
- module TestBelt::ShouldaMacros; end
5
-
6
- require 'test_belt/shoulda_macros/classes'
7
- require 'test_belt/shoulda_macros/context'
8
- require 'test_belt/shoulda_macros/files'
9
-
@@ -1,105 +0,0 @@
1
- require 'useful/ruby_extensions/string' unless String.new.respond_to?(:constantize)
2
-
3
- module TestBelt; end
4
- module TestBelt::ShouldaMacros; end
5
- module TestBelt::ShouldaMacros::Classes
6
-
7
- # Ripped from Shoulda::ActiveRecord::Macros
8
- def should_have_class_methods(*methods)
9
- handle_methods(methods) do |method|
10
- should "respond to class method ##{method}" do
11
- klass = construct_subject.class
12
- assert_respond_to klass, method, "#{klass.name} does not have class method #{method}"
13
- end
14
- end
15
- end
16
- alias_method :should_have_class_method, :should_have_class_methods
17
- protected :should_have_class_methods, :should_have_class_method
18
- def skip_should_have_class_methods(*methods)
19
- handle_methods(methods) do |method|
20
- should "(skip) respond to class method ##{method}" do
21
- skip
22
- end
23
- end
24
- end
25
- alias_method :skip_should_have_class_method, :skip_should_have_class_methods
26
- protected :skip_should_have_class_methods, :skip_should_have_class_method
27
-
28
-
29
- # Ripped from Shoulda::ActiveRecord::Macros
30
- def should_have_instance_methods(*methods)
31
- handle_methods(methods) do |method|
32
- should "respond to instance method ##{method}" do
33
- the_subject = construct_subject
34
- assert_respond_to(the_subject, method, "#{the_subject.class.name} does not have instance method #{method}")
35
- end
36
- end
37
- end
38
- alias_method :should_have_instance_method, :should_have_instance_methods
39
- protected :should_have_instance_methods, :should_have_instance_method
40
- def skip_should_have_instance_methods(*methods)
41
- handle_methods(methods) do |method|
42
- should "(skip) respond to instance method ##{method}" do
43
- skip
44
- end
45
- end
46
- end
47
- alias_method :skip_should_have_instance_method, :skip_should_have_instance_methods
48
- protected :skip_should_have_instance_methods, :skip_should_have_instance_method
49
-
50
-
51
- def should_have_readers(*readers)
52
- get_options!(readers)
53
- should_have_instance_methods *readers
54
- end
55
- alias_method :should_have_reader, :should_have_readers
56
- protected :should_have_readers, :should_have_reader
57
- def skip_should_have_readers(*readers)
58
- get_options!(readers)
59
- skip_should_have_instance_methods *readers
60
- end
61
- alias_method :skip_should_have_reader, :skip_should_have_readers
62
- protected :skip_should_have_readers, :skip_should_have_reader
63
-
64
-
65
- def should_have_writers(*writers)
66
- get_options!(writers)
67
- should_have_instance_methods *(writers.collect{|w| "#{w}="})
68
- end
69
- alias_method :should_have_writer, :should_have_writers
70
- protected :should_have_writers, :should_have_writer
71
- def skip_should_have_writers(*writers)
72
- get_options!(writers)
73
- skip_should_have_instance_methods *(writers.collect{|w| "#{w}="})
74
- end
75
- alias_method :skip_should_have_writer, :skip_should_have_writers
76
- protected :skip_should_have_writers, :skip_should_have_writer
77
-
78
-
79
- def should_have_accessors(*accessors)
80
- get_options!(accessors)
81
- should_have_instance_methods *accessors
82
- should_have_instance_methods *(accessors.collect{|a| "#{a}="})
83
- end
84
- alias_method :should_have_accessor, :should_have_accessors
85
- protected :should_have_accessors, :should_have_accessor
86
- def skip_should_have_accessors(*accessors)
87
- get_options!(accessors)
88
- skip_should_have_instance_methods *accessors
89
- skip_should_have_instance_methods *(accessors.collect{|a| "#{a}="})
90
- end
91
- alias_method :skip_should_have_accessor, :skip_should_have_accessors
92
- protected :skip_should_have_accessors, :skip_should_have_accessor
93
-
94
-
95
-
96
-
97
- def handle_methods(methods)
98
- get_options!(methods)
99
- methods.each {|m| yield m if block_given?}
100
- end
101
- private :handle_methods
102
-
103
- end
104
-
105
- Test::Unit::TestCase.extend(TestBelt::ShouldaMacros::Classes) if defined? Test::Unit::TestCase
@@ -1,25 +0,0 @@
1
- module TestBelt; end
2
- module TestBelt::ShouldaMacros; end
3
- module TestBelt::ShouldaMacros::Context
4
- end
5
-
6
-
7
- if defined? Shoulda::Context
8
- module Shoulda
9
- class Context
10
-
11
- alias_method :before, :setup
12
- alias_method :after, :teardown
13
-
14
- # TODO: override described_type to use string blessed with constantize method
15
- # alias_method(:orig_described_type, :described_type) rescue NameError
16
- # def described_type
17
- # self.name.gsub(/Test$/, '').constantize
18
- # end
19
- # protected :described_type
20
-
21
- end
22
- end
23
-
24
- Shoulda::Context.extend(TestBelt::ShouldaMacros::Context)
25
- end
@@ -1,49 +0,0 @@
1
- require 'useful/ruby_extensions/string' unless String.new.respond_to?(:constantize)
2
-
3
- module TestBelt; end
4
- module TestBelt::ShouldaMacros; end
5
- module TestBelt::ShouldaMacros::Files
6
-
7
- def should_have_files(*files)
8
- the_files = files.flatten
9
- if the_files.empty?
10
- should "have @root_path" do
11
- assert @root_path, "the variable @root_path is not defined"
12
- assert File.exists?(@root_path), "'#{@root_path}' does not exist"
13
- end
14
- else
15
- the_files.each do |file|
16
- should "have the file '#{file}' in @root_path" do
17
- assert @root_path, "the variable @root_path is not defined"
18
- assert File.exists?(File.join(@root_path, file)), "'#{file}' does not exist in '#{@root_path}'"
19
- end
20
- end
21
- end
22
- end
23
- protected :should_have_files
24
- def skip_should_have_files(*files)
25
- the_files = files.flatten
26
- if the_files.empty?
27
- should "(skip) have @root_path" do
28
- skip
29
- end
30
- else
31
- the_files.each do |file|
32
- should "(skip) have the file '#{file}' in @root_path" do
33
- skip
34
- end
35
- end
36
- end
37
- end
38
- protected :skip_should_have_files
39
-
40
- alias_method :should_have_file, :should_have_files
41
- alias_method :should_have_directories, :should_have_files
42
- alias_method :should_have_directory, :should_have_files
43
- alias_method :skip_should_have_file, :skip_should_have_files
44
- alias_method :skip_should_have_directories, :skip_should_have_files
45
- alias_method :skip_should_have_directory, :skip_should_have_files
46
-
47
- end
48
-
49
- Test::Unit::TestCase.extend(TestBelt::ShouldaMacros::Files) if defined? Test::Unit::TestCase
@@ -1,8 +0,0 @@
1
- require 'test/unit'
2
-
3
- module TestBelt; end
4
- module TestBelt::TestUnit; end
5
-
6
- require 'test_belt/test_unit/context'
7
- require 'test_belt/test_unit/test_case'
8
-
@@ -1,71 +0,0 @@
1
- require 'test/unit'
2
- require 'test_belt/test_unit/runner'
3
-
4
- module Test::Unit
5
-
6
- class TestCase
7
-
8
- class << self
9
-
10
- def _testbelt_suite_callbacks
11
- @_testbelt_suite_callbacks ||= {
12
- :started => [],
13
- :finished => []
14
- }
15
- end
16
-
17
- def _testbelt_testcase_callbacks
18
- @_testbelt_testcase_callbacks ||= {
19
- :setup => [],
20
- :teardown => []
21
- }
22
- end
23
-
24
- protected
25
-
26
- # Suite level callbacks
27
- def suite_started(&block)
28
- ::Test::Unit::TestCase._testbelt_suite_callbacks[:started] << block
29
- end
30
- alias :on_suite_started :suite_started
31
-
32
- def suite_finished(&block)
33
- ::Test::Unit::TestCase._testbelt_suite_callbacks[:finished] << block
34
- end
35
- alias :on_suite_finished :suite_finished
36
-
37
- # TestCase level callbacks
38
- def setup_once(&block)
39
- _testbelt_testcase_callbacks[:setup] << block
40
- end
41
- alias :before_once :setup_once
42
-
43
- def teardown_once(&block)
44
- _testbelt_testcase_callbacks[:teardown] << block
45
- end
46
- alias :after_once :teardown_once
47
-
48
- end
49
- end
50
-
51
-
52
- # override the TestSuite with TestCase callbacks
53
- class TestSuite
54
- alias_method :run_without_testbelt_callbacks, :run
55
-
56
- def run(*args, &block) # :nodoc:
57
- if !tests.empty? && (testclass = tests.first).kind_of?(::Test::Unit::TestCase)
58
- tests.first.class._testbelt_testcase_callbacks[:setup].each do |callback|
59
- callback.call
60
- end
61
- end
62
- run_without_testbelt_callbacks *args, &block
63
- if !tests.empty? && (testclass = tests.first).kind_of?(::Test::Unit::TestCase)
64
- tests.first.class._testbelt_testcase_callbacks[:teardown].reverse.each do |callback|
65
- callback.call
66
- end
67
- end
68
- end
69
- end
70
-
71
- end
@@ -1,48 +0,0 @@
1
- require 'test/unit'
2
- require 'test/unit/ui/console/testrunner'
3
-
4
- module TestBelt; end
5
- module TestBelt::TestUnit
6
-
7
- if defined? ::LeftRight::Runner
8
- class Runner < ::LeftRight::Runner; end
9
- else
10
- class Runner < ::Test::Unit::UI::Console::TestRunner; end
11
- end
12
-
13
- class Runner
14
- def started(*args)
15
- super
16
- if ::Test::Unit::TestCase.respond_to?("_testbelt_suite_callbacks")
17
- ::Test::Unit::TestCase._testbelt_suite_callbacks[:started].each do |callback|
18
- callback.call
19
- end
20
- end
21
- end
22
-
23
- def finished(*args)
24
- if ::Test::Unit::TestCase.respond_to?("_testbelt_suite_callbacks")
25
- ::Test::Unit::TestCase._testbelt_suite_callbacks[:finished].reverse.each do |callback|
26
- callback.call
27
- end
28
- end
29
- super
30
- end
31
- end
32
-
33
- end
34
-
35
- module Test::Unit
36
-
37
- # override the AutoRunner's runner to use TestBelt's
38
- # with callback for suite started/finished
39
- class AutoRunner
40
- alias_method :initialize_without_testbelt_runner, :initialize
41
-
42
- def initialize(*args)
43
- initialize_without_testbelt_runner *args
44
- @runner = lambda { |r| ::TestBelt::TestUnit::Runner }
45
- end
46
- end
47
-
48
- end
@@ -1,26 +0,0 @@
1
- require 'test/unit'
2
-
3
- module TestBelt::TestUnit
4
- class TestSkipped < Exception; end
5
- end
6
-
7
- module Test::Unit
8
- class TestCase
9
-
10
- alias_method(:orig_add_error, :add_error)
11
- def add_error(*args, &block)
12
- unless args.first.kind_of?(::TestBelt::TestUnit::TestSkipped)
13
- orig_add_error *args, &block
14
- end
15
- end
16
-
17
- def skip(halt_test=true)
18
- if defined? ::LeftRight
19
- ::LeftRight.state.skip = true
20
- ::LeftRight.state.skipped_count += 1
21
- end
22
- raise ::TestBelt::TestUnit::TestSkipped if halt_test
23
- end
24
-
25
- end
26
- end
@@ -1,58 +0,0 @@
1
- require "test/helper"
2
- require "test/fixtures/shoulda_macros/thing"
3
-
4
- class ClassesTest < Test::Unit::TestCase
5
-
6
- context "TestBelt Shoulda Macros for classes" do
7
- subject { Thing.new }
8
-
9
- # should provide these macros
10
- should "provide a set of macros" do
11
- assert self.class.respond_to?(:should_have_instance_methods), "no :should_have_instance_methods macro"
12
- assert self.class.respond_to?(:should_have_instance_method), "no :should_have_instance_method macro"
13
- assert self.class.respond_to?(:should_have_class_methods), "no :should_have_class_methods macro"
14
- assert self.class.respond_to?(:should_have_class_method), "no :should_have_class_method macro"
15
- assert self.class.respond_to?(:should_have_readers), "no :should_have_readers macro"
16
- assert self.class.respond_to?(:should_have_reader), "no :should_have_reader macro"
17
- assert self.class.respond_to?(:should_have_writers), "no :should_have_writers macro"
18
- assert self.class.respond_to?(:should_have_writer), "no :should_have_writer macro"
19
- assert self.class.respond_to?(:should_have_accessors), "no :should_have_accessors macro"
20
- assert self.class.respond_to?(:should_have_accessor), "no :should_have_accessor macro"
21
-
22
- assert self.class.respond_to?(:skip_should_have_instance_methods), "no :skip_should_have_instance_methods macro"
23
- assert self.class.respond_to?(:skip_should_have_instance_method), "no :skip_should_have_instance_method macro"
24
- assert self.class.respond_to?(:skip_should_have_class_methods), "no :skip_should_have_class_methods macro"
25
- assert self.class.respond_to?(:skip_should_have_class_method), "no :skip_should_have_class_method macro"
26
- assert self.class.respond_to?(:skip_should_have_readers), "no :skip_should_have_readers macro"
27
- assert self.class.respond_to?(:skip_should_have_reader), "no :skip_should_have_reader macro"
28
- assert self.class.respond_to?(:skip_should_have_writers), "no :skip_should_have_writers macro"
29
- assert self.class.respond_to?(:skip_should_have_writer), "no :skip_should_have_writer macro"
30
- assert self.class.respond_to?(:skip_should_have_accessors), "no :skip_should_have_accessors macro"
31
- assert self.class.respond_to?(:skip_should_have_accessor), "no :skip_should_have_accessor macro"
32
- end
33
-
34
-
35
- should_have_instance_method :an_instance_meth
36
- should_have_instance_methods :instance1, :instance2
37
- should_have_class_method :a_class_meth
38
- should_have_class_methods :class1, :class2
39
- should_have_readers :reader1, :reader2
40
- should_have_reader :reader3
41
- should_have_writers :writer1, :writer2
42
- should_have_writer :writer3
43
- should_have_accessors :accessor1, :accessor2
44
- should_have_accessor :accessor3
45
-
46
- skip_should_have_instance_method :an_instance_meth
47
- skip_should_have_instance_methods :instance1, :instance2
48
- skip_should_have_class_method :a_class_meth
49
- skip_should_have_class_methods :class1, :class2
50
- skip_should_have_readers :reader1, :reader2
51
- skip_should_have_reader :reader3
52
- skip_should_have_writers :writer1, :writer2
53
- skip_should_have_writer :writer3
54
- skip_should_have_accessors :accessor1, :accessor2
55
- skip_should_have_accessor :accessor3
56
- end
57
-
58
- end
@@ -1,28 +0,0 @@
1
- require "test/helper"
2
- require "test/fixtures/shoulda_macros/thing"
3
-
4
- module TestBelt::ShouldaMacros
5
- class ContextTest < Test::Unit::TestCase
6
-
7
- context "TestBelt Shoulda Macros for context" do
8
- setup do
9
- @thing = Thing.new
10
- end
11
-
12
- context "callbacks that setup/teardown each test" do
13
- before do
14
- @thing.accessor1 = "before"
15
- end
16
- after do
17
- assert_equal 'after', @thing.accessor1, "the accessor was not set correctly in the after block"
18
- end
19
-
20
- should "run using before/after blocks" do
21
- assert_equal 'before', @thing.accessor1, "the accessor was not set correctly in the before block"
22
- @thing.accessor1 = "after"
23
- end
24
- end
25
- end
26
-
27
- end
28
- end
@@ -1,36 +0,0 @@
1
- require "test/helper"
2
-
3
- module TestBelt::ShouldaMacros
4
- class FilesTest < Test::Unit::TestCase
5
-
6
- context "TestBelt Shoulda Macros for files" do
7
-
8
- # should require a root path
9
- setup do
10
- @root_path = File.expand_path(File.dirname(__FILE__))
11
- end
12
-
13
- # should provide these macros
14
- should "provide a set of macros" do
15
- assert self.class.respond_to?(:should_have_directories), "no :should_have_directories macro"
16
- assert self.class.respond_to?(:should_have_directory), "no :should_have_directory macro"
17
- assert self.class.respond_to?(:should_have_files), "no :should_have_files macro"
18
- assert self.class.respond_to?(:should_have_file), "no :should_have_file macro"
19
-
20
- assert self.class.respond_to?(:skip_should_have_directories), "no :should_have_directories macro"
21
- assert self.class.respond_to?(:skip_should_have_directory), "no :should_have_directory macro"
22
- assert self.class.respond_to?(:skip_should_have_files), "no :should_have_files macro"
23
- assert self.class.respond_to?(:skip_should_have_file), "no :should_have_file macro"
24
- end
25
-
26
- # should find the @root_path directory
27
- should_have_directories
28
- skip_should_have_directories
29
-
30
- #should find files in the @root_path directory
31
- should_have_files 'files_test.rb'
32
- skip_should_have_files 'files_test.rb'
33
- end
34
-
35
- end
36
- end