rspec 0.5.11 → 0.5.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/CHANGES +12 -0
  2. data/README +4 -2
  3. data/Rakefile +14 -4
  4. data/bin/spec +7 -7
  5. data/bin/test2spec +13 -8
  6. data/lib/spec/api/helper/diff.rb +53 -0
  7. data/lib/spec/api/helper/instance_helper.rb +11 -11
  8. data/lib/spec/api/helper/instance_negator.rb +11 -11
  9. data/lib/spec/api/helper/kind_helper.rb +11 -11
  10. data/lib/spec/api/helper/kind_negator.rb +11 -11
  11. data/lib/spec/api/helper/respond_helper.rb +11 -11
  12. data/lib/spec/api/helper/respond_negator.rb +11 -11
  13. data/lib/spec/api/helper/should_base.rb +6 -6
  14. data/lib/spec/api/helper/should_helper.rb +35 -35
  15. data/lib/spec/api/helper/should_negator.rb +20 -20
  16. data/lib/spec/rake/spectask.rb +15 -6
  17. data/lib/spec/runner.rb +1 -0
  18. data/lib/spec/runner/backtrace_tweaker.rb +2 -0
  19. data/lib/spec/runner/base_text_formatter.rb +3 -1
  20. data/lib/spec/runner/html_formatter.rb +153 -0
  21. data/lib/spec/runner/option_parser.rb +9 -2
  22. data/lib/spec/runner/progress_bar_formatter.rb +4 -0
  23. data/lib/spec/runner/rdoc_formatter.rb +3 -0
  24. data/lib/spec/runner/reporter.rb +5 -5
  25. data/lib/spec/runner/specdoc_formatter.rb +3 -0
  26. data/lib/spec/test_to_spec/sexp_transformer.rb +1 -0
  27. data/lib/spec/test_to_spec/translation_test_runner.rb +10 -2
  28. data/lib/spec/version.rb +1 -1
  29. data/test/spec/api/helper/arbitrary_predicate_test.rb +49 -73
  30. data/test/spec/api/helper/diff_test.rb +60 -0
  31. data/test/spec/api/helper/equality_test.rb +14 -0
  32. data/test/spec/api/helper/should_have_test.rb +0 -29
  33. data/test/spec/api/helper/typing_test.rb +87 -87
  34. data/test/spec/api/sugar_test.rb +0 -6
  35. data/test/spec/runner/backtrace_tweaker_test.rb +8 -2
  36. data/test/spec/runner/html_formatter_test.rb +47 -0
  37. data/test/spec/runner/option_parser_test.rb +0 -5
  38. data/test/test_classes.rb +73 -0
  39. data/test/test_helper.rb +3 -0
  40. metadata +8 -49
  41. data/doc/README +0 -3
  42. data/doc/config.yaml +0 -2
  43. data/doc/plugin/syntax.rb +0 -60
  44. data/doc/plugin/version.rb +0 -19
  45. data/doc/src/core_team.page +0 -31
  46. data/doc/src/default.css +0 -199
  47. data/doc/src/default.template +0 -31
  48. data/doc/src/documentation/index.page +0 -188
  49. data/doc/src/documentation/meta.info +0 -22
  50. data/doc/src/documentation/mocks.page +0 -287
  51. data/doc/src/documentation/underscores.page +0 -21
  52. data/doc/src/examples.page +0 -9
  53. data/doc/src/images/David_and_Aslak.jpg +0 -0
  54. data/doc/src/images/Whats_That_Dude.jpg +0 -0
  55. data/doc/src/images/ducks1.png +0 -0
  56. data/doc/src/images/ul.gif +0 -0
  57. data/doc/src/index.page +0 -74
  58. data/doc/src/meta.info +0 -33
  59. data/doc/src/tools/index.page +0 -49
  60. data/doc/src/tools/meta.info +0 -18
  61. data/doc/src/tools/rails.page +0 -132
  62. data/doc/src/tools/rake.page +0 -21
  63. data/doc/src/tools/rcov.page +0 -28
  64. data/doc/src/tools/spec.page +0 -129
  65. data/doc/src/tools/test2spec.page +0 -103
  66. data/doc/src/tutorials/index.page +0 -52
  67. data/doc/src/tutorials/meta.info +0 -36
  68. data/doc/src/tutorials/notes.txt +0 -263
  69. data/doc/src/tutorials/stack.rb +0 -11
  70. data/doc/src/tutorials/stack_01.page +0 -226
  71. data/doc/src/tutorials/stack_02.page +0 -182
  72. data/doc/src/tutorials/stack_03.page +0 -283
  73. data/doc/src/tutorials/stack_04.page +0 -164
  74. data/doc/src/tutorials/stack_04.page.orig +0 -123
  75. data/doc/src/tutorials/stack_05.page +0 -90
  76. data/doc/src/tutorials/stack_05.page.orig +0 -124
  77. data/doc/src/tutorials/stack_06.page +0 -359
  78. data/doc/src/tutorials/stack_06.page.orig +0 -359
  79. data/doc/src/tutorials/stack_spec.rb +0 -25
  80. data/doc/src/ul.gif +0 -0
@@ -7,35 +7,35 @@ module Spec
7
7
  end
8
8
 
9
9
  def satisfy
10
- fail_with_message "Supplied expectation was satisfied, but should not have been" if (yield @target)
10
+ fail_with_message "Supplied expectation was satisfied, but should not have been" if (yield @target)
11
11
  end
12
12
 
13
13
  def equal(expected)
14
- fail_with_message(default_message("should not equal", expected)) if (@target == expected)
14
+ fail_with_message(default_message("should not equal", expected)) if (@target == expected)
15
15
  end
16
16
 
17
17
  def be(expected = :no_arg)
18
- return self if (expected == :no_arg)
19
- fail_with_message(default_message("should not be", expected)) if (@target.equal?(expected))
18
+ return self if (expected == :no_arg)
19
+ fail_with_message(default_message("should not be", expected)) if (@target.equal?(expected))
20
20
  end
21
21
 
22
- def a
23
- self
24
- end
25
-
26
- alias an a
27
-
28
- def instance
29
- InstanceNegator.new(@target)
30
- end
31
-
32
- def kind
33
- KindNegator.new(@target)
34
- end
22
+ def a
23
+ self
24
+ end
25
+
26
+ alias an a
27
+
28
+ def instance
29
+ InstanceNegator.new(@target)
30
+ end
31
+
32
+ def kind
33
+ KindNegator.new(@target)
34
+ end
35
35
 
36
- def respond
37
- RespondNegator.new(@target)
38
- end
36
+ def respond
37
+ RespondNegator.new(@target)
38
+ end
39
39
 
40
40
  def match(expected)
41
41
  fail_with_message(default_message("should not match", expected)) if (@target =~ expected)
@@ -52,6 +52,10 @@ module Rake
52
52
  # Array of commandline options to pass to ruby (or rcov) when running specs.
53
53
  attr_accessor :ruby_opts
54
54
 
55
+ # Whether or not to fail Rake when an error occurs (typically when specs fail).
56
+ # Default is true
57
+ attr_accessor :fail_on_error
58
+
55
59
  # Explicitly define the list of spec files to be included in a
56
60
  # spec. +list+ is expected to be an array of file names (a
57
61
  # FileList is acceptable). If both +pattern+ and +spec_files+ are
@@ -72,6 +76,7 @@ module Rake
72
76
  @rcov = false
73
77
  @ruby_opts = []
74
78
  @out = nil
79
+ @fail_on_error = true
75
80
  yield self if block_given?
76
81
  @pattern = 'spec/**/*_spec.rb' if @pattern.nil? && @spec_files.nil?
77
82
  define
@@ -93,12 +98,16 @@ module Rake
93
98
  @ruby_opts.unshift( "-I#{lib_path}" )
94
99
  @ruby_opts.unshift( "-w" ) if @warning
95
100
  @ruby_opts.unshift( '--exclude "lib\/spec\/.*"' ) if @rcov
96
- run interpreter, @ruby_opts.join(" ") +
97
- " \"#{spec}\" " +
98
- " #{@spec_opts.join(' ')} " +
99
- file_prefix +
100
- specs.collect { |fn| "\"#{fn}\"" }.join(' ') +
101
- redirect
101
+ begin
102
+ run interpreter, @ruby_opts.join(" ") +
103
+ " \"#{spec}\" " +
104
+ " #{@spec_opts.join(' ')} " +
105
+ file_prefix +
106
+ specs.collect { |fn| "\"#{fn}\"" }.join(' ') +
107
+ redirect
108
+ rescue => e
109
+ raise e if @fail_on_error
110
+ end
102
111
  end
103
112
  self
104
113
  end
@@ -10,4 +10,5 @@ require 'spec/runner/base_text_formatter'
10
10
  require 'spec/runner/progress_bar_formatter'
11
11
  require 'spec/runner/rdoc_formatter'
12
12
  require 'spec/runner/specdoc_formatter'
13
+ require 'spec/runner/html_formatter'
13
14
  require 'spec/runner/spec_matcher'
@@ -29,6 +29,8 @@ module Spec
29
29
  line = nil if line =~ /bin\/spec:/
30
30
  # TextMate's Ruby plugin
31
31
  line = nil if line =~ /Ruby\.tmbundle\/Support\/tmruby.rb:/
32
+ # RSpec on Rails
33
+ line = nil if line =~ /gems\/rspec_generator/
32
34
  line
33
35
  end
34
36
  error.backtrace.compact!
@@ -50,7 +50,7 @@ module Spec
50
50
  end
51
51
 
52
52
  # Dumps detailed information about a spec failure.
53
- # This method is invoked for each failed spec. +counter+ is the sequence number
53
+ # This method is invoked for each failed spec after all specs have run. +counter+ is the sequence number
54
54
  # of the associated spec. +failure+ is a Failure object, which contains detailed
55
55
  # information about the failure.
56
56
  def dump_failure(counter, failure)
@@ -59,6 +59,7 @@ module Spec
59
59
  @output << "#{failure.header}\n"
60
60
  @output << "#{failure.message}\n"
61
61
  @output << "#{failure.backtrace}\n"
62
+ @output.flush
62
63
  end
63
64
 
64
65
  # This method is invoked at the very end.
@@ -69,6 +70,7 @@ module Spec
69
70
  @output << "#{spec_count} specification#{'s' unless spec_count == 1}, "
70
71
  @output << "#{failure_count} failure#{'s' unless failure_count == 1}"
71
72
  @output << "\n"
73
+ @output.flush
72
74
  end
73
75
  end
74
76
  end
@@ -0,0 +1,153 @@
1
+ require 'spec/runner/base_text_formatter'
2
+
3
+ module Spec
4
+ module Runner
5
+ class HtmlFormatter < Spec::Runner::BaseTextFormatter
6
+ def initialize(output, dry_run=false)
7
+ super
8
+ @current_count = 0
9
+ end
10
+
11
+ def start(spec_count)
12
+ @spec_count = spec_count
13
+
14
+ @output.puts HEADER
15
+ @output.flush
16
+ end
17
+
18
+ def add_context(name, first)
19
+ unless first
20
+ @output.puts " </div>"
21
+ @output.puts "</div>"
22
+ end
23
+ @output.puts "<div class=\"context\">"
24
+ @output.puts " <div>#{name}</div>"
25
+ @output.puts " <div>"
26
+ end
27
+
28
+ def start_dump
29
+ @output.puts " </div>"
30
+ @output.puts "</div>"
31
+ @output.flush
32
+ end
33
+
34
+ def spec_started(name)
35
+ @current_spec = name
36
+ @current_count += 1
37
+ end
38
+
39
+ def spec_passed(name)
40
+ @output.puts "<div class=\"spec passed\">#{escape(@current_spec)}</div>"
41
+ end
42
+
43
+ def spec_failed(name, counter, failure)
44
+ @output.puts "<div class=\"spec failed\">"
45
+ @output.puts " <a href=\"#\" onclick=\"toggle('failure_#{counter}');return false;\">#{escape(@current_spec)}</a>"
46
+ @output.puts " <div class=\"failure\" id=\"failure_#{counter}\" style=\"display:none\">"
47
+ @output.puts " <div><pre>#{escape(failure.header)}</pre></div>" unless failure.header == ""
48
+ @output.puts " <div><pre>#{escape(failure.message)}</pre></div>" unless failure.message == ""
49
+ @output.puts " <div><pre>#{escape(failure.backtrace)}</pre></div>" unless failure.backtrace == ""
50
+ @output.puts " </div>"
51
+ @output.puts "</div>"
52
+ @output.flush
53
+ end
54
+
55
+ def escape(string)
56
+ string.gsub(/&/n, '&amp;').gsub(/\"/n, '&quot;').gsub(/>/n, '&gt;').gsub(/</n, '&lt;')
57
+ end
58
+
59
+ def dump_failure(counter, failure)
60
+ # @output << "\n"
61
+ # @output << counter.to_s << ")\n"
62
+ # @output << "#{failure.header}\n"
63
+ # @output << "#{failure.message}\n"
64
+ # @output << "#{failure.backtrace}\n"
65
+ # @output.flush
66
+ end
67
+
68
+ def dump_summary(duration, spec_count, failure_count)
69
+ @output << "</body>"
70
+ @output << "</html>"
71
+ @output.flush
72
+ end
73
+
74
+ HEADER = <<-HEADER
75
+ <?xml version="1.0" encoding="iso-8859-1"?>
76
+ <!DOCTYPE html
77
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
78
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
79
+
80
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
81
+ <head>
82
+ <title>RSpec results</title>
83
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
84
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
85
+ <style type="text/css">
86
+ body {
87
+ font-size: 10pt;
88
+ font: "lucida grande";
89
+ width: 85%;
90
+ }
91
+
92
+ .passed {
93
+ background-color: #DDFFDD;
94
+ }
95
+
96
+ .failed {
97
+ background-color: #FFDDDD;
98
+ font-weight: bold;
99
+ }
100
+
101
+ .failed .failure {
102
+ background-color: #FFDDDD;
103
+ font-weight: normal;
104
+ font-size: 9pt;
105
+ }
106
+
107
+ .context {
108
+ padding:4px;
109
+ border:1px solid #000000;
110
+ margin-top:4px;
111
+ }
112
+
113
+ :link, :visited {
114
+ color: #000000;
115
+ text-decoration: none;
116
+ padding-bottom: 0px;
117
+ }
118
+
119
+ :link:hover, :visited:hover {
120
+ color: #c00;
121
+ }
122
+
123
+ </style>
124
+ <script type="text/javascript">
125
+ // <![CDATA[
126
+
127
+ function toggle( id ) {
128
+ if ( document.getElementById )
129
+ elem = document.getElementById( id );
130
+ else if ( document.all )
131
+ elem = eval( "document.all." + id );
132
+ else
133
+ return false;
134
+
135
+ elemStyle = elem.style;
136
+
137
+ if ( elemStyle.display != "block" ) {
138
+ elemStyle.display = "block"
139
+ } else {
140
+ elemStyle.display = "none"
141
+ }
142
+
143
+ return true;
144
+ }
145
+ // ]]>
146
+ </script>
147
+
148
+ </head>
149
+ <body>
150
+ HEADER
151
+ end
152
+ end
153
+ end
@@ -33,11 +33,14 @@ module Spec
33
33
  require req
34
34
  end
35
35
 
36
- opts.on("-f", "--format FORMAT", "Builtin formats: specdoc|s|rdoc|r",
37
- "You can also specify a custom formatter class") do |format|
36
+ opts.on("-f", "--format FORMAT", "Builtin formats: specdoc|s|rdoc|r|html|h",
37
+ "You can also specify a custom formatter class",
38
+ "(in which case you should also specify --require)") do |format|
38
39
  case format
39
40
  when 'specdoc', 's'
40
41
  options.formatter_type = SpecdocFormatter
42
+ when 'html', 'h'
43
+ options.formatter_type = HtmlFormatter
41
44
  when 'rdoc', 'r'
42
45
  options.formatter_type = RdocFormatter
43
46
  options.dry_run = true
@@ -56,6 +59,10 @@ module Spec
56
59
  options.dry_run = true
57
60
  end
58
61
 
62
+ opts.on("--diff", "Show unified diff of Strings that are expected to be equal when they are not") do
63
+ require 'spec/api/helper/diff'
64
+ end
65
+
59
66
  opts.on("-s", "--spec SPECIFICATION_NAME", "Execute a single specification") do |spec_name|
60
67
  options.spec_name = spec_name
61
68
  end
@@ -3,18 +3,22 @@ module Spec
3
3
  class ProgressBarFormatter < BaseTextFormatter
4
4
  def add_context(name, first)
5
5
  @output << "\n" if first
6
+ @output.flush
6
7
  end
7
8
 
8
9
  def spec_failed(name, counter, failure)
9
10
  @output << 'F'
11
+ @output.flush
10
12
  end
11
13
 
12
14
  def spec_passed(name)
13
15
  @output << '.'
16
+ @output.flush
14
17
  end
15
18
 
16
19
  def start_dump
17
20
  @output << "\n"
21
+ @output.flush
18
22
  end
19
23
  end
20
24
  end
@@ -3,14 +3,17 @@ module Spec
3
3
  class RdocFormatter < BaseTextFormatter
4
4
  def add_context(name, first)
5
5
  @output << "# #{name}\n"
6
+ @output.flush
6
7
  end
7
8
 
8
9
  def spec_passed(name)
9
10
  @output << "# * #{name}\n"
11
+ @output.flush
10
12
  end
11
13
 
12
14
  def spec_failed(name, counter, failure)
13
15
  @output << "# * #{name} [#{counter} - FAILED]\n"
16
+ @output.flush
14
17
  end
15
18
  end
16
19
  end
@@ -72,10 +72,10 @@ module Spec
72
72
  end
73
73
 
74
74
  class Failure
75
- def initialize(context_name, spec_name, error)
75
+ def initialize(context_name, spec_name, exception)
76
76
  @context_name = context_name
77
77
  @spec_name = spec_name
78
- @error = error
78
+ @exception = exception
79
79
  end
80
80
 
81
81
  def header
@@ -83,17 +83,17 @@ module Spec
83
83
  end
84
84
 
85
85
  def message
86
- @error.message
86
+ @exception.message
87
87
  end
88
88
 
89
89
  def backtrace
90
- @error.backtrace.join("\n") unless @error.backtrace.nil?
90
+ @exception.backtrace.nil? ? "" : @exception.backtrace.join("\n")
91
91
  end
92
92
 
93
93
  private
94
94
 
95
95
  def class_name
96
- @error.class.name.split('::').last
96
+ @exception.class.name.split('::').last
97
97
  end
98
98
 
99
99
  end
@@ -3,14 +3,17 @@ module Spec
3
3
  class SpecdocFormatter < BaseTextFormatter
4
4
  def add_context(name, first)
5
5
  @output << "\n#{name}\n"
6
+ @output.flush
6
7
  end
7
8
 
8
9
  def spec_failed(name, counter, failure)
9
10
  @output << "- #{name} (FAILED - #{counter})\n"
11
+ @output.flush
10
12
  end
11
13
 
12
14
  def spec_passed(name)
13
15
  @output << "- #{name}\n"
16
+ @output.flush
14
17
  end
15
18
  end
16
19
  end
@@ -1,3 +1,4 @@
1
+ require 'rubygems'
1
2
  require 'sexp_processor'
2
3
 
3
4
  module Spec
@@ -32,8 +32,8 @@ module Spec
32
32
  end
33
33
  rescue => e
34
34
  log "Failed to translate #{klass}"
35
- log "Message: #{e.message}"
36
- log e.backtrace.join("\n")
35
+ verbose "Message: #{e.message}"
36
+ verbose e.backtrace.join("\n")
37
37
  end
38
38
  end
39
39
  end
@@ -64,6 +64,14 @@ module Spec
64
64
  $test2spec_options[:quiet] == true
65
65
  end
66
66
 
67
+ def verbose(msg)
68
+ puts msg if verbose?
69
+ end
70
+
71
+ def verbose?
72
+ !quiet? && $test2spec_options[:verbose] == true
73
+ end
74
+
67
75
  def destination_path(relative_destination)
68
76
  File.join($test2spec_options[:specdir], relative_destination)
69
77
  end