rspec 0.6.4 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. data/CHANGES +90 -1
  2. data/EXAMPLES.rd +28 -6
  3. data/MIT-LICENSE +20 -0
  4. data/README +18 -12
  5. data/Rakefile +60 -54
  6. data/examples/custom_formatter.rb +4 -4
  7. data/examples/helper_method_example.rb +11 -0
  8. data/examples/mocking_example.rb +19 -2
  9. data/examples/partial_mock_example.rb +28 -0
  10. data/examples/stack_spec.rb +8 -8
  11. data/examples/stubbing_example.rb +50 -9
  12. data/examples/test_case_spec.rb +6 -6
  13. data/lib/spec.rb +1 -2
  14. data/lib/spec/callback.rb +0 -0
  15. data/lib/spec/expectations.rb +3 -6
  16. data/lib/spec/expectations/diff.rb +23 -47
  17. data/lib/spec/expectations/differs/default.rb +62 -0
  18. data/lib/spec/expectations/{exceptions.rb → errors.rb} +0 -0
  19. data/lib/spec/expectations/extensions.rb +4 -0
  20. data/lib/spec/expectations/extensions/inspect_for_expectation_not_met_error.rb +14 -0
  21. data/lib/spec/expectations/extensions/numeric.rb +5 -0
  22. data/lib/spec/expectations/{expectations.rb → extensions/object.rb} +3 -6
  23. data/lib/spec/expectations/extensions/symbol.rb +5 -0
  24. data/lib/spec/expectations/should.rb +4 -0
  25. data/lib/spec/expectations/should/base.rb +42 -0
  26. data/lib/spec/expectations/should/have.rb +79 -0
  27. data/lib/spec/expectations/should/not.rb +72 -0
  28. data/lib/spec/expectations/should/should.rb +83 -0
  29. data/lib/spec/expectations/sugar.rb +6 -25
  30. data/lib/spec/mocks.rb +5 -1
  31. data/lib/spec/mocks/argument_expectation.rb +15 -1
  32. data/lib/spec/mocks/error_generator.rb +72 -0
  33. data/lib/spec/mocks/{exceptions.rb → errors.rb} +0 -0
  34. data/lib/spec/mocks/extensions/object.rb +3 -0
  35. data/lib/spec/mocks/message_expectation.rb +80 -73
  36. data/lib/spec/mocks/mock.rb +4 -69
  37. data/lib/spec/mocks/mock_handler.rb +158 -0
  38. data/lib/spec/mocks/mock_methods.rb +44 -0
  39. data/lib/spec/mocks/order_group.rb +10 -2
  40. data/lib/spec/rake/spectask.rb +20 -18
  41. data/lib/spec/rake/{rcov_verify.rb → verify_rcov.rb} +2 -2
  42. data/lib/spec/runner.rb +3 -1
  43. data/lib/spec/runner/backtrace_tweaker.rb +2 -1
  44. data/lib/spec/runner/context.rb +10 -16
  45. data/lib/spec/runner/context_eval.rb +40 -40
  46. data/lib/spec/runner/execution_context.rb +1 -12
  47. data/lib/spec/runner/{kernel_ext.rb → extensions/kernel.rb} +2 -2
  48. data/lib/spec/runner/{instance_exec.rb → extensions/object.rb} +0 -0
  49. data/lib/spec/runner/formatter/base_text_formatter.rb +25 -18
  50. data/lib/spec/runner/formatter/html_formatter.rb +81 -101
  51. data/lib/spec/runner/formatter/progress_bar_formatter.rb +9 -9
  52. data/lib/spec/runner/formatter/rdoc_formatter.rb +6 -6
  53. data/lib/spec/runner/formatter/specdoc_formatter.rb +7 -6
  54. data/lib/spec/runner/option_parser.rb +41 -5
  55. data/lib/spec/runner/reporter.rb +3 -15
  56. data/lib/spec/runner/spec_should_raise_handler.rb +74 -0
  57. data/lib/spec/runner/specification.rb +33 -14
  58. data/lib/spec/version.rb +6 -3
  59. data/vendor/watir/README.txt +1 -1
  60. metadata +34 -68
  61. data/bin/test2spec +0 -112
  62. data/examples/helper_method_spec.rb +0 -12
  63. data/lib/spec/expectations/have_helper.rb +0 -41
  64. data/lib/spec/expectations/helper.rb +0 -4
  65. data/lib/spec/expectations/should_base.rb +0 -52
  66. data/lib/spec/expectations/should_helper.rb +0 -93
  67. data/lib/spec/expectations/should_negator.rb +0 -71
  68. data/lib/spec/test_to_spec/ruby2ruby.rb +0 -492
  69. data/lib/spec/test_to_spec/sexp_transformer.rb +0 -196
  70. data/lib/spec/test_to_spec/test_case_ext.rb +0 -22
  71. data/lib/spec/test_to_spec/translation_test_runner.rb +0 -147
  72. data/test/spec/expectations/arbitrary_operator_test.rb +0 -55
  73. data/test/spec/expectations/arbitrary_predicate_test.rb +0 -163
  74. data/test/spec/expectations/containment_test.rb +0 -129
  75. data/test/spec/expectations/diff_test.rb +0 -62
  76. data/test/spec/expectations/identity_test.rb +0 -75
  77. data/test/spec/expectations/object_equality_test.rb +0 -65
  78. data/test/spec/expectations/raising_test.rb +0 -106
  79. data/test/spec/expectations/regex_matching_test.rb +0 -36
  80. data/test/spec/expectations/should_have_test.rb +0 -169
  81. data/test/spec/expectations/should_satisfy_test.rb +0 -37
  82. data/test/spec/expectations/sugar_test.rb +0 -93
  83. data/test/spec/expectations/supported_symbols_test.rb +0 -33
  84. data/test/spec/expectations/throwing_test.rb +0 -55
  85. data/test/spec/expectations/true_false_special_case_test.rb +0 -85
  86. data/test/spec/expectations/typing_test.rb +0 -108
  87. data/test/spec/mocks/mock_arg_constraints_test.rb +0 -113
  88. data/test/spec/mocks/mock_counts_test.rb +0 -431
  89. data/test/spec/mocks/mock_ordering_test.rb +0 -109
  90. data/test/spec/mocks/mock_test.rb +0 -220
  91. data/test/spec/mocks/null_object_test.rb +0 -37
  92. data/test/spec/runner/backtrace_tweaker_test.rb +0 -90
  93. data/test/spec/runner/context_matching_test.rb +0 -35
  94. data/test/spec/runner/context_runner_test.rb +0 -62
  95. data/test/spec/runner/context_test.rb +0 -191
  96. data/test/spec/runner/execution_context_test.rb +0 -45
  97. data/test/spec/runner/formatter/failure_dump_test.rb +0 -94
  98. data/test/spec/runner/formatter/html_formatter_test.rb +0 -48
  99. data/test/spec/runner/formatter/progress_bar_formatter_test.rb +0 -56
  100. data/test/spec/runner/formatter/rdoc_formatter_test.rb +0 -51
  101. data/test/spec/runner/formatter/specdoc_formatter_test.rb +0 -57
  102. data/test/spec/runner/kernel_ext_test.rb +0 -13
  103. data/test/spec/runner/option_parser_test.rb +0 -141
  104. data/test/spec/runner/reporter_test.rb +0 -128
  105. data/test/spec/runner/spec_matcher_test.rb +0 -47
  106. data/test/spec/runner/specification_test.rb +0 -121
  107. data/test/spec/test_to_spec/ruby_to_ruby_test.rb +0 -79
  108. data/test/spec/test_to_spec/sexp_transformer_assertion_test.rb +0 -207
  109. data/test/spec/test_to_spec/sexp_transformer_test.rb +0 -303
  110. data/test/spec/test_to_spec/test_case_ext_test.rb +0 -25
  111. data/test/spec/test_to_spec/testfiles/test_unit_api_spec.rb +0 -75
  112. data/test/spec/test_to_spec/testfiles/test_unit_api_test.rb +0 -70
  113. data/test/test_classes.rb +0 -102
  114. data/test/test_helper.rb +0 -32
@@ -19,8 +19,8 @@ module Spec
19
19
  teardown_parts << block
20
20
  end
21
21
 
22
- def specify(spec_name, &block)
23
- specifications << Specification.new(spec_name, &block)
22
+ def specify(spec_name, opts={}, &block)
23
+ specifications << Specification.new(spec_name, opts, &block)
24
24
  end
25
25
 
26
26
  def methods
@@ -37,6 +37,38 @@ module Spec
37
37
  super
38
38
  end
39
39
 
40
+ private
41
+ def setup_block
42
+ parts = setup_parts.dup
43
+ add_context_superclass_method(:setup, parts)
44
+ create_block_from_parts(parts)
45
+ end
46
+
47
+ def teardown_block
48
+ parts = teardown_parts.dup
49
+ add_context_superclass_method(:teardown, parts)
50
+ create_block_from_parts(parts)
51
+ end
52
+
53
+ def execution_context_class
54
+ @execution_context_class ||= derive_execution_context_class_from_context_superclass
55
+ end
56
+
57
+ def derive_execution_context_class_from_context_superclass
58
+ @execution_context_class = Class.new(context_superclass)
59
+ @execution_context_class.class_eval do
60
+ include ::Spec::Runner::ExecutionContext::InstanceMethods
61
+ end
62
+ end
63
+
64
+ def context_superclass
65
+ @context_superclass ||= Object
66
+ end
67
+
68
+ def context_modules
69
+ @context_modules ||= []
70
+ end
71
+
40
72
  def specifications
41
73
  @specifications ||= []
42
74
  end
@@ -49,28 +81,13 @@ module Spec
49
81
  @teardown_parts ||= []
50
82
  end
51
83
 
52
- def setup_block
53
- parts = setup_parts.dup
54
-
55
- setup_method = begin
56
- context_superclass.instance_method(:setup)
57
- rescue
58
- nil
59
- end
60
- parts.unshift setup_method if setup_method
61
- create_block_from_parts(parts)
62
- end
63
-
64
- def teardown_block
65
- parts = teardown_parts.dup
66
-
67
- teardown_method = begin
68
- context_superclass.instance_method(:teardown)
84
+ def add_context_superclass_method sym, parts
85
+ superclass_method = begin
86
+ context_superclass.instance_method(sym)
69
87
  rescue
70
88
  nil
71
89
  end
72
- parts.unshift teardown_method if teardown_method
73
- create_block_from_parts(parts)
90
+ parts.unshift superclass_method if superclass_method
74
91
  end
75
92
 
76
93
  def create_block_from_parts(parts)
@@ -84,28 +101,11 @@ module Spec
84
101
  end
85
102
  end
86
103
  end
87
-
88
- def execution_context_class
89
- @execution_context_class ||= derive_execution_context_class_from_context_superclass
90
- end
91
-
92
- def derive_execution_context_class_from_context_superclass
93
- @execution_context_class = Class.new(context_superclass)
94
- @execution_context_class.class_eval do
95
- include ::Spec::Runner::ExecutionContext::InstanceMethods
96
- end
97
- end
98
-
99
- def context_superclass
100
- @context_superclass ||= Object
101
- end
102
-
103
- def context_modules
104
- @context_modules ||= []
105
- end
106
104
  end
105
+
107
106
  module InstanceMethods
108
107
  end
108
+
109
109
  end
110
110
  end
111
111
  end
@@ -7,13 +7,7 @@ module Spec
7
7
  end
8
8
 
9
9
  def mock(name, options={})
10
- mock = Spec::Mocks::Mock.new(name, options)
11
- @spec.add_mock(mock)
12
- mock
13
- end
14
-
15
- def stub(object, name="")
16
- stub_space.create_stub(object, name)
10
+ Spec::Mocks::Mock.new(name, options)
17
11
  end
18
12
 
19
13
  def duck_type(*args)
@@ -23,11 +17,6 @@ module Spec
23
17
  def violated(message="")
24
18
  raise Spec::Expectations::ExpectationNotMetError.new(message)
25
19
  end
26
-
27
- private
28
- def stub_space
29
- @spec.stub_space
30
- end
31
20
  end
32
21
  include InstanceMethods
33
22
  end
@@ -3,12 +3,12 @@ module Kernel
3
3
  context = Spec::Runner::Context.new(name, &block)
4
4
  runner = context_runner
5
5
  runner.add_context(context)
6
- runner.run(false) if runner.standalone
7
6
  end
8
7
 
9
8
  private
10
9
 
11
10
  def context_runner
12
- $context_runner ||= ::Spec::Runner::OptionParser.create_context_runner(ARGV.dup, true, STDERR, STDOUT)
11
+ if $context_runner.nil?; $context_runner = ::Spec::Runner::OptionParser.create_context_runner(ARGV.dup, true, STDERR, STDOUT); at_exit { $context_runner.run(false) }; end
12
+ $context_runner
13
13
  end
14
14
  end
@@ -9,11 +9,7 @@ module Spec
9
9
  @output = output
10
10
  @dry_run = dry_run
11
11
  @colour = colour
12
- begin
13
- require 'Win32/Console/ANSI' if @colour && PLATFORM =~ /win32/
14
- rescue LoadError
15
- raise "You must gem install win32console to use --color on Windows"
16
- end
12
+ begin ; require 'Win32/Console/ANSI' if @colour && PLATFORM =~ /win32/ ; rescue LoadError ; raise "You must gem install win32console to use colour on Windows" ; end
17
13
  end
18
14
 
19
15
  # This method is invoked before any specs are run, right after
@@ -64,28 +60,39 @@ module Spec
64
60
  @output.puts
65
61
  @output.puts "#{counter.to_s})"
66
62
  @output.puts failure.header
67
- @output.puts failure.message
68
- @output.puts failure.backtrace
69
- @output.flush
63
+ @output.puts failure.exception.message
64
+ @output.puts failure.exception.backtrace.join("\n")
65
+ STDOUT.flush
70
66
  end
71
67
 
72
68
  # This method is invoked at the very end.
73
69
  def dump_summary(duration, spec_count, failure_count)
74
70
  return if @dry_run
75
- if @colour && @output == STDOUT
76
- colour_prefix = (failure_count == 0 ? "\e[32m" : "\e[31m")
77
- colour_postfix = "\e[0m"
78
- summary_output = Kernel
79
- else
80
- colour_prefix = colour_postfix = ""
81
- summary_output = @output
82
- end
83
71
  @output.puts
84
72
  @output.puts "Finished in #{duration} seconds"
85
73
  @output.puts
86
- summary_output.puts "#{colour_prefix}#{spec_count} specification#{'s' unless spec_count == 1}, #{failure_count} failure#{'s' unless failure_count == 1}#{colour_postfix}"
87
- @output.flush
74
+ summary = "#{spec_count} specification#{'s' unless spec_count == 1}, #{failure_count} failure#{'s' unless failure_count == 1}"
75
+ if failure_count == 0
76
+ @output.puts green(summary)
77
+ else
78
+ @output.puts red(summary)
79
+ end
88
80
  end
81
+
82
+ protected
83
+
84
+ def colour(text, colour_code)
85
+ return text unless @colour && @output == Kernel
86
+ "#{colour_code}#{text}\e[0m"
87
+ end
88
+
89
+ def red(text); colour(text, "\e[31m"); end
90
+ def green(text); colour(text, "\e[32m"); end
91
+
92
+ def format_backtrace(backtrace)
93
+ backtrace.nil? ? "" : backtrace.join("\n")
94
+ end
95
+
89
96
  end
90
97
  end
91
98
  end
@@ -11,7 +11,7 @@ module Spec
11
11
  @spec_count = spec_count
12
12
 
13
13
  @output.puts HEADER
14
- @output.flush
14
+ STDOUT.flush
15
15
  end
16
16
 
17
17
  def add_context(name, first)
@@ -20,14 +20,14 @@ module Spec
20
20
  @output.puts "</div>"
21
21
  end
22
22
  @output.puts "<div class=\"context\">"
23
- @output.puts " <div>#{name}</div>"
23
+ @output.puts " <h2>#{name}</h2>"
24
24
  @output.puts " <ul>"
25
25
  end
26
26
 
27
27
  def start_dump
28
28
  @output.puts " </ul>"
29
29
  @output.puts "</div>"
30
- @output.flush
30
+ STDOUT.flush
31
31
  end
32
32
 
33
33
  def spec_started(name)
@@ -36,120 +36,100 @@ module Spec
36
36
  end
37
37
 
38
38
  def spec_passed(name)
39
- @output.puts "<li class=\"spec passed\">#{escape(@current_spec)}</li>"
39
+ @output.puts "<li class=\"spec passed\"><div class=\"name\">#{escape(@current_spec)}</div></li>"
40
40
  end
41
41
 
42
42
  def spec_failed(name, counter, failure)
43
- @output.puts "<li class=\"spec failed\" onclick=\"toggle('failure_#{counter}');return false;\">"
44
- @output.puts " <div>#{escape(@current_spec)}</div>"
45
- @output.puts " <div class=\"failure\" id=\"failure_#{counter}\" style=\"display:none\">"
46
- @output.puts " <div><pre>#{escape(failure.header)}</pre></div>" unless failure.header == ""
47
- @output.puts " <div><pre>#{escape(failure.message)}</pre></div>" unless failure.message == ""
48
- @output.puts " <div><pre>#{escape(failure.backtrace)}</pre></div>" unless failure.backtrace == ""
43
+ @output.puts "<li class=\"spec failed\">"
44
+ @output.puts " <div class=\"name\">#{escape(@current_spec)}</div>"
45
+ @output.puts " <div class=\"failure\" id=\"failure_#{counter}\">"
46
+ @output.puts " <div class=\"message\"><pre>#{escape(failure.exception.message)}</pre></div>" unless failure.exception.nil?
47
+ @output.puts " <div class=\"backtrace\"><pre>#{format_backtrace(failure.exception.backtrace)}</pre></div>" unless failure.exception.nil?
49
48
  @output.puts " </div>"
50
49
  @output.puts "</li>"
51
- @output.flush
50
+ STDOUT.flush
52
51
  end
53
-
52
+
54
53
  def escape(string)
55
54
  string.gsub(/&/n, '&amp;').gsub(/\"/n, '&quot;').gsub(/>/n, '&gt;').gsub(/</n, '&lt;')
56
55
  end
57
56
 
58
57
  def dump_failure(counter, failure)
59
- # @output << "\n"
60
- # @output << counter.to_s << ")\n"
61
- # @output << "#{failure.header}\n"
62
- # @output << "#{failure.message}\n"
63
- # @output << "#{failure.backtrace}\n"
64
- # @output.flush
65
58
  end
66
59
 
67
60
  def dump_summary(duration, spec_count, failure_count)
68
- @output << "</body>"
69
- @output << "</html>"
70
- @output.flush
61
+ @output.print "</body>"
62
+ @output.print "</html>"
63
+ STDOUT.flush
71
64
  end
72
-
65
+
73
66
  HEADER = <<-HEADER
74
- <?xml version="1.0" encoding="iso-8859-1"?>
75
- <!DOCTYPE html
76
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
77
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
78
-
79
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
80
- <head>
81
- <title>RSpec results</title>
82
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
83
- <meta http-equiv="Content-Script-Type" content="text/javascript" />
84
- <style type="text/css">
85
- body {
86
- font-size: 10pt;
87
- font: "lucida grande";
88
- width: 85%;
89
- }
90
-
91
- ul {
92
- padding-left: 8px;
93
- }
94
-
95
- li.passed {
96
- background-color: #DDFFDD;
97
- }
98
-
99
- li {
100
- list-style-type: none;
101
- margin: 0;
102
- }
103
-
104
- li.failed {
105
- background-color: #FFBBBB;
106
- font-weight: bold;
107
- }
108
-
109
- li.failed:hover {
110
- color: #FFFFFF;
111
- background-color: #FF0000;
112
- }
113
-
114
- li.failed .failure {
115
- font-weight: normal;
116
- font-size: 9pt;
117
- }
118
-
119
- div.context {
120
- padding:4px;
121
- border:1px solid #000000;
122
- margin-top:4px;
123
- }
124
-
125
- </style>
126
- <script type="text/javascript">
127
- // <![CDATA[
128
-
129
- function toggle( id ) {
130
- if ( document.getElementById )
131
- elem = document.getElementById( id );
132
- else if ( document.all )
133
- elem = eval( "document.all." + id );
134
- else
135
- return false;
136
-
137
- elemStyle = elem.style;
138
-
139
- if ( elemStyle.display != "block" ) {
140
- elemStyle.display = "block"
141
- } else {
142
- elemStyle.display = "none"
143
- }
144
-
145
- return true;
146
- }
147
- // ]]>
148
- </script>
149
-
150
- </head>
151
- <body>
152
- HEADER
67
+ <?xml version="1.0" encoding="iso-8859-1"?>
68
+ <!DOCTYPE html
69
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
70
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
71
+
72
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
73
+ <head>
74
+ <title>RSpec results</title>
75
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
76
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
77
+ <style type="text/css">
78
+ body {
79
+ font-size: 10pt;
80
+ font: "lucida grande";
81
+ width: 85%;
82
+ }
83
+
84
+ h2 {
85
+ color: #589CCF;
86
+ }
87
+
88
+ div.context {
89
+ padding: 0px;
90
+ background: #fff;
91
+ margin-top: 0px;
92
+ }
93
+
94
+ ul {
95
+ padding-left: 0px;
96
+ }
97
+
98
+ li {
99
+ list-style-type: none;
100
+ margin: 0;
101
+ border: 2px solid #fff;
102
+ }
103
+
104
+ li.passed {
105
+ display: block;
106
+ background: #46A002;
107
+ color: #fff;
108
+ padding: 2px 4px;
109
+ font-weight: bold
110
+ }
111
+
112
+ li.failed {
113
+ display: block;
114
+ background: red;
115
+ color: #fff;
116
+ padding: 2px 4px;
117
+ font-weight: bold
118
+ }
119
+
120
+ li.failed .failure {
121
+ font-weight: normal;
122
+ font-size: 9pt;
123
+ }
124
+
125
+ div.backtrace {
126
+ color: #000;
127
+ }
128
+
129
+ </style>
130
+ </head>
131
+ <body>
132
+ HEADER
153
133
  end
154
134
  end
155
135
  end
@@ -3,23 +3,23 @@ module Spec
3
3
  module Formatter
4
4
  class ProgressBarFormatter < BaseTextFormatter
5
5
  def add_context(name, first)
6
- @output << "\n" if first
7
- @output.flush
6
+ @output.puts if first
7
+ STDOUT.flush
8
8
  end
9
9
 
10
10
  def spec_failed(name, counter, failure)
11
- @output << 'F'
12
- @output.flush
11
+ @output.print red('F')
12
+ STDOUT.flush
13
13
  end
14
-
14
+
15
15
  def spec_passed(name)
16
- @output << '.'
17
- @output.flush
16
+ @output.print green('.')
17
+ STDOUT.flush
18
18
  end
19
19
 
20
20
  def start_dump
21
- @output << "\n"
22
- @output.flush
21
+ @output.puts
22
+ STDOUT.flush
23
23
  end
24
24
  end
25
25
  end