public
Rubygem
Description: Makes tests easy on the fingers and the eyes
Homepage: http://www.thoughtbot.com/projects/shoulda
Clone URL: git://github.com/thoughtbot/shoulda.git
- documentation
- moved should to context



git-svn-id: https://svn.thoughtbot.com/plugins/tb_test_helpers/trunk@75 
7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
tsaleh (author)
Thu Apr 05 12:15:56 -0700 2007
commit  1ecd02914b6b981bfb44b30bc6348c6161a2db72
tree    2fe6debbe9995dc5400481dd8e7be8c2eb598357
parent  6fd2363b8aac02d5eb0ac9b53997b5a4b89c437b
0
...
4
5
6
7
8
9
10
 
 
 
 
11
12
13
14
15
 
 
 
 
16
...
4
5
6
 
 
 
 
7
8
9
10
11
12
 
 
 
13
14
15
16
17
0
@@ -4,12 +4,13 @@ A collection of Test::Unit helper methods.
0
 
0
 Adds helpers for
0
 
0
-#. Contexts and should statements
0
-#. Common ActiveRecord model tests
0
-#. A few general purpose assertions
0
-
0
+1. context and should statements
0
+1. Common ActiveRecord model tests
0
+1. A few general purpose assertions
0
+
0
 == Todo
0
 
0
-#. Controller test helpers
0
-#. General code cleanups
0
-#. More options for AR helpers
0
+1. Controller test helpers
0
+1. General code cleanups
0
+1. More options for AR helpers
0
+
0
\ No newline at end of file
...
8
9
10
 
 
 
 
 
 
 
 
 
 
11
12
13
...
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
0
@@ -8,6 +8,16 @@ Rake::TestTask.new do |t|
0
   t.verbose = true
0
 end
0
 
0
+# Generate the RDoc documentation
0
+
0
+Rake::RDocTask.new { |rdoc|
0
+ rdoc.rdoc_dir = 'doc'
0
+ rdoc.title = "ThoughtBot Test Helpers -- Making your tests easy on the fingers and eyes"
0
+ rdoc.options << '--line-numbers' << '--inline-source'
0
+ rdoc.template = "#{ENV['template']}.rb" if ENV['template']
0
+ rdoc.rdoc_files.include('README', 'lib/**/*.rb')
0
+}
0
+
0
 desc 'Default: run tests.'
0
 task :default => ['test']
0
 
...
1
2
3
4
5
6
 
 
 
 
 
 
 
 
 
 
 
7
8
9
 
10
11
12
13
14
15
16
 
 
 
17
18
19
...
22
23
24
25
 
26
27
28
...
32
33
34
35
 
36
37
38
...
40
41
42
43
 
44
45
46
...
48
49
50
51
52
53
 
 
 
54
55
56
...
1
2
3
 
 
 
4
5
6
7
8
9
10
11
12
13
14
15
16
 
17
18
19
20
21
 
 
 
22
23
24
25
26
27
...
30
31
32
 
33
34
35
36
...
40
41
42
 
43
44
45
46
...
48
49
50
 
51
52
53
54
...
56
57
58
 
 
 
59
60
61
62
63
64
0
@@ -1,19 +1,27 @@
0
 require 'test/unit/ui/console/testrunner'
0
 
0
 # Completely stolen from redgreen gem
0
-module Color
0
- COLORS = { :clear => 0, :red => 31, :green => 32, :yellow => 33 }
0
- def self.method_missing(color_name, *args)
0
+#
0
+# Adds colored output to your tests. Specify <tt>color: true</tt> in
0
+# your <tt>test/tb_test_helpers.conf</tt> file to enable.
0
+#
0
+# *Bug*: for some reason, this adds another line of output to the end of
0
+# every rake task, as though there was another (empty) set of tests.
0
+# A fix would be most welcome.
0
+#
0
+module Color
0
+ COLORS = { :clear => 0, :red => 31, :green => 32, :yellow => 33 } # :nodoc:
0
+ def self.method_missing(color_name, *args) # :nodoc:
0
     color(color_name) + args.first + color(:clear)
0
   end
0
- def self.color(color)
0
+ def self.color(color) # :nodoc:
0
     "\e[#{COLORS[color.to_sym]}m"
0
   end
0
 end
0
 
0
-module Test
0
- module Unit
0
- class TestResult
0
+module Test # :nodoc:
0
+ module Unit # :nodoc:
0
+ class TestResult # :nodoc:
0
       alias :old_to_s :to_s
0
       def to_s
0
         if old_to_s =~ /\d+ tests, \d+ assertions, (\d+) failures, (\d+) errors/
0
@@ -22,7 +30,7 @@ module Test
0
       end
0
     end
0
 
0
- class AutoRunner
0
+ class AutoRunner # :nodoc:
0
       alias :old_initialize :initialize
0
       def initialize(standalone)
0
         old_initialize(standalone)
0
@@ -32,7 +40,7 @@ module Test
0
       end
0
     end
0
 
0
- class Failure
0
+ class Failure # :nodoc:
0
       alias :old_long_display :long_display
0
       def long_display
0
         # old_long_display.sub('Failure', Color.red('Failure'))
0
@@ -40,7 +48,7 @@ module Test
0
       end
0
     end
0
 
0
- class Error
0
+ class Error # :nodoc:
0
       alias :old_long_display :long_display
0
       def long_display
0
         # old_long_display.sub('Error', Color.yellow('Error'))
0
@@ -48,9 +56,9 @@ module Test
0
       end
0
     end
0
 
0
- module UI
0
- module Console
0
- class RedGreenTestRunner < Test::Unit::UI::Console::TestRunner
0
+ module UI # :nodoc:
0
+ module Console # :nodoc:
0
+ class RedGreenTestRunner < Test::Unit::UI::Console::TestRunner # :nodoc:
0
           def output_single(something, level=NORMAL)
0
             return unless (output?(level))
0
             something = case something
...
1
2
 
3
4
5
...
14
15
16
17
 
18
19
20
...
24
25
26
27
 
28
29
30
31
32
 
 
 
 
33
34
35
...
37
38
39
40
 
41
42
43
44
45
 
 
46
47
48
...
54
55
56
 
 
 
57
58
59
60
61
62
63
64
65
 
66
67
68
 
 
69
70
71
72
73
74
75
76
77
 
78
79
80
...
1
 
2
3
4
5
...
14
15
16
 
17
18
19
20
...
24
25
26
 
27
28
29
30
31
32
33
34
35
36
37
38
39
...
41
42
43
 
44
45
46
47
48
 
49
50
51
52
53
...
59
60
61
62
63
64
65
66
67
68
69
 
 
 
 
70
71
72
73
74
75
76
77
78
79
80
 
 
 
 
81
82
83
84
0
@@ -1,5 +1,5 @@
0
 require 'active_record_helpers'
0
-require 'should'
0
+require 'context'
0
 require 'yaml'
0
 
0
 config_file = "tb_test_helpers.conf"
0
@@ -14,7 +14,7 @@ module Test # :nodoc:
0
       class << self
0
         include TBTestHelpers::Should
0
     
0
- # Loads all fixture files
0
+ # Loads all fixture files (<tt>test/fixtures/*.yml</tt>)
0
         def load_all_fixtures
0
           all_fixtures = Dir.glob(File.join(RAILS_ROOT, "test", "fixtures", "*.yml")).collect do |f|
0
             File.basename(f, '.yml').to_sym
0
@@ -24,12 +24,16 @@ module Test # :nodoc:
0
     
0
       end
0
 
0
- # Logs a message, tagged with TESTING: and the name of the calling method.
0
+ # Prints a message to stdout, tagged with the name of the calling method.
0
       def report!(msg = "")
0
         puts("#{caller.first}: #{msg}")
0
       end
0
 
0
       # Ensures that the number of items in the collection changes
0
+ # assert_difference(User, :count, 1) { User.create }
0
+ # assert_difference(User.packages, :size, 3, true) { User.add_three_packages }
0
+ #
0
+ # Setting reload to true will call <tt>object.reload</tt> after the block (for ActiveRecord associations)
0
       def assert_difference(object, method, difference, reload = false, msg = nil)
0
         initial_value = object.send(method)
0
         yield
0
@@ -37,12 +41,13 @@ module Test # :nodoc:
0
         assert_equal initial_value + difference, object.send(method), (msg || "#{object}##{method} after block")
0
       end
0
 
0
- # Ensures that object.method does not change
0
+ # Ensures that object.method does not change. See assert_difference for usage.
0
       def assert_no_difference(object, method, reload = false, msg = nil, &block)
0
         assert_difference(object, method, 0, reload, msg, &block)
0
       end
0
 
0
- # asserts that two arrays contain the same elements, the same number of times. Essentially ==, but unordered.
0
+ # Asserts that two arrays contain the same elements, the same number of times. Essentially ==, but unordered.
0
+ # assert_same_elements([:a, :b, :c], [:c, :a, :b]) => passes
0
       def assert_same_elements(a1, a2, msg = nil)
0
         [:select, :inject, :size].each do |m|
0
           [a1, a2].each {|a| assert_respond_to(a, m, "Are you sure that #{a.inspect} is an array? It doesn't respond to #{m}.") }
0
@@ -54,27 +59,26 @@ module Test # :nodoc:
0
         assert_equal(a1h, a2h, msg)
0
       end
0
       
0
+ # Asserts that the given collection contains item x. If x is a regular expression, ensure that
0
+ # at least one element from the collection matches x.
0
+ # assert_contains(['a', '1'], /\d/) => passes
0
       def assert_contains(collection, x, extra_msg = "")
0
         collection = [collection] unless collection.is_a?(Array)
0
         msg = "#{x} not found in #{collection.to_a.inspect} " + extra_msg
0
         case x
0
         when Regexp: assert(collection.detect { |e| e =~ x }, msg)
0
- when String: assert(collection.include?(x), msg)
0
- when Fixnum: assert(collection.include?(x), msg)
0
- else
0
- raise ArgumentError, "Don't know what to do with #{x}"
0
+ else assert(collection.include?(x), msg)
0
         end
0
       end
0
 
0
+ # Asserts that the given collection does not contain item x. If x is a regular expression, ensure that
0
+ # none of the elements from the collection match x.
0
       def assert_does_not_contain(collection, x, extra_msg = "")
0
         collection = [collection] unless collection.is_a?(Array)
0
         msg = "#{x} found in #{collection.to_a.inspect} " + extra_msg
0
         case x
0
         when Regexp: assert(!collection.detect { |e| e =~ x }, msg)
0
- when String: assert(!collection.include?(x), msg)
0
- when Fixnum: assert(!collection.include?(x), msg)
0
- else
0
- raise ArgumentError, "Don't know what to do with #{x}"
0
+ else assert(!collection.include?(x), msg)
0
         end
0
       end
0
 

Comments

    No one has commented yet.