test-belt 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- test-belt (1.1.0)
4
+ test-belt (1.1.1)
5
5
  leftright (~> 0.9.0)
6
6
 
7
7
  GEM
@@ -40,44 +40,34 @@ just write Test::Unit tests with assertions
40
40
  === Leftright
41
41
  https://github.com/jordi/leftright
42
42
 
43
- === Shoulda
44
- https://github.com/thoughtbot/shoulda
45
-
46
- === Shoulda enhancements
47
- I've added some handy macros and extensions to some things Shoulda does. None of these are required so just use them as you see fit. Here's a sampling of what is added:
48
- * Class interface macros:
49
- * should_have_class_methods
50
- * should_have_readers
51
- * etc
52
- * Files macros:
53
- * should_have_files
54
- * should_have_directories
55
- * etc
56
- * Context macros:
57
- * before/after aliases for setup/teardown
58
- * etc
59
-
60
- === Additional Test::Unit context callbacks
61
- I've added some contexts callbacks in addition to the setup/teardown callbacks Shoulda provides:
62
- * setup_once / before_once - runs one time before any of the tests in the test case are run
63
- * teardown_once / after_once - runs one time after all of the tests in the test case are run
64
- * suite_started / on_suite_started - runs one time before any of the tests across the entire test suite are run
65
- * suite_finished / on_suite_finished - runs one time after all of the tests across the entire test suite are run
43
+ === Inheritence based contexts
44
+ * naming
45
+ * subjects
46
+ * callbacks (test, case, and suite)
47
+
48
+ === Custom matchers for repeatable macro-tests
49
+ * have_class_methods
50
+ * have_instance_methods
51
+ * have_readers
52
+ * have_writers
53
+ * have_accessors
54
+ * have_files
55
+ * base class for writing your own
66
56
 
67
57
  === Test::Unit 'skip' directive
68
58
  Test::Unit already provides a 'flunk' directive that will fail the current test. I've added a 'skip' directive that will skip the test when running the suite. I use it to ignore certain tests while I focus on others. Skipping while using LeftRight allows me to ignore the test but not forget about it when looking at my test results.
69
59
 
70
60
  class TestCaseTest < Test::Unit::TestCase
61
+ include TestBelt
71
62
 
72
- context "Something" do
73
- should "be something awesome" do
74
- skip
75
- # anything after the 'skip' directive will not be executed
76
- # => use skip(false) to not halt execution
77
- assert something_is_in_fact_awesome
78
- end
79
- end
63
+ context "Something"
80
64
 
65
+ should "be something awesome" do
66
+ skip
67
+ # anything after the 'skip' directive will not be executed
68
+ # => use skip(false) to not halt execution
69
+ assert something_is_in_fact_awesome
70
+ end
81
71
  end
82
72
 
83
73
  == Generated Rake tasks
@@ -102,7 +92,7 @@ Many times in developing code, I need to quickly load up IRB with my environment
102
92
 
103
93
  == License
104
94
 
105
- Copyright (c) 2010 Kelly D. Redding
95
+ Copyright (c) 2010-2011 Kelly D. Redding
106
96
 
107
97
  Permission is hereby granted, free of charge, to any person
108
98
  obtaining a copy of this software and associated documentation
@@ -2,7 +2,9 @@ require 'rubygems'
2
2
  require 'test/unit'
3
3
  require 'leftright'
4
4
 
5
+ require 'test_belt/utils'
5
6
  require 'test_belt/default_test'
7
+ require 'test_belt/testcase'
6
8
  require 'test_belt/should'
7
9
  require 'test_belt/context'
8
10
  require 'test_belt/subject'
@@ -15,7 +17,8 @@ module TestBelt
15
17
  def self.included(receiving_test_class)
16
18
  if receiving_test_class.ancestors.include?(::Test::Unit::TestCase)
17
19
  receiving_test_class.send(:include, DefaultTest)
18
- receiving_test_class.send(:extend, Should)
20
+ receiving_test_class.send(:include, TestCase)
21
+ receiving_test_class.send(:extend, Should)
19
22
  receiving_test_class.send(:include, Context)
20
23
  receiving_test_class.send(:include, Subject)
21
24
  receiving_test_class.send(:include, Skip)
@@ -0,0 +1,43 @@
1
+ module TestBelt
2
+ module TestCase
3
+
4
+ # This overrides the TestCase suite building behavior. It uses
5
+ # the local_public_instance_methods util to builde the suite of
6
+ # tests. What this gives you is only the tests defined or mixed
7
+ # in to the class will be run as part of the suite (non of the super
8
+ # class tests will be run
9
+
10
+ # Usage:
11
+ # class SomeTest < Test::Unit::TestCase
12
+ # include TestBelt::Suite
13
+ # end
14
+
15
+ def self.included(receiver)
16
+ receiver.send :extend, ClassMethods
17
+ end
18
+
19
+ module ClassMethods
20
+
21
+ # based on Ruby 1.8.7 suite method
22
+ def suite
23
+ # this is the only thing I'm changing
24
+ method_names = ::TestBelt::Utils.local_public_instance_methods(self)
25
+ # the rest is all the same
26
+ tests = method_names.delete_if {|method_name| method_name !~ /^test./}
27
+ suite = ::Test::Unit::TestSuite.new(name)
28
+ tests.sort.each do |test|
29
+ catch(:invalid_test) do
30
+ suite << new(test)
31
+ end
32
+ end
33
+ if (suite.empty?)
34
+ catch(:invalid_test) do
35
+ suite << new("default_test")
36
+ end
37
+ end
38
+ return suite
39
+ end
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,13 @@
1
+ module TestBelt::Utils
2
+ class << self
3
+
4
+ def local_public_instance_methods(klass)
5
+ methods = klass.public_instance_methods
6
+ while (klass.superclass)
7
+ methods -= (klass = klass.superclass).public_instance_methods
8
+ end
9
+ methods
10
+ end
11
+
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module TestBelt
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -0,0 +1,19 @@
1
+ module MixinStuff
2
+ def mixin_stuff
3
+ "from mixin"
4
+ end
5
+ end
6
+
7
+ class SuperStuff
8
+ def superclass_stuff
9
+ "from superclass"
10
+ end
11
+ end
12
+
13
+ class SubStuff
14
+ include MixinStuff
15
+
16
+ def subclass_stuff
17
+ "from subclass"
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ require "test/helper"
2
+ require 'test/fixtures/inherited_stuff'
3
+
4
+ module TestBelt::Utils
5
+
6
+ class Test < Test::Unit::TestCase
7
+ include TestBelt
8
+
9
+ context "the util"
10
+ subject { Utils }
11
+
12
+ should have_instance_method :local_public_instance_methods
13
+ end
14
+
15
+ class LocalMethodsTest < Test
16
+ context "'local_public_instance_methods'"
17
+
18
+ should "fine a class's local public instance methods" do
19
+ assert_equal(
20
+ ["subclass_stuff", "mixin_stuff"].sort,
21
+ subject.local_public_instance_methods(SubStuff).sort
22
+ )
23
+ end
24
+ end
25
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test-belt
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 0
10
- version: 1.1.0
9
+ - 1
10
+ version: 1.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kelly D. Redding
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-20 00:00:00 Z
18
+ date: 2011-06-04 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: bundler
@@ -83,15 +83,19 @@ files:
83
83
  - lib/test_belt/should.rb
84
84
  - lib/test_belt/skip.rb
85
85
  - lib/test_belt/subject.rb
86
+ - lib/test_belt/testcase.rb
87
+ - lib/test_belt/utils.rb
86
88
  - lib/test_belt/version.rb
87
89
  - test-belt.gemspec
88
90
  - test/callbacks_test.rb
89
91
  - test/env.rb
92
+ - test/fixtures/inherited_stuff.rb
90
93
  - test/fixtures/thing.rb
91
94
  - test/helper.rb
92
95
  - test/helpers_test.rb
93
96
  - test/matchers_test.rb
94
97
  - test/rake_tasks_test.rb
98
+ - test/utils_test.rb
95
99
  homepage: http://github.com/kelredd/test-belt
96
100
  licenses: []
97
101
 
@@ -128,8 +132,10 @@ summary: A gem for using testing tools I like - my Ruby testing toolbelt.
128
132
  test_files:
129
133
  - test/callbacks_test.rb
130
134
  - test/env.rb
135
+ - test/fixtures/inherited_stuff.rb
131
136
  - test/fixtures/thing.rb
132
137
  - test/helper.rb
133
138
  - test/helpers_test.rb
134
139
  - test/matchers_test.rb
135
140
  - test/rake_tasks_test.rb
141
+ - test/utils_test.rb