dchelimsky-rspec 1.1.12 → 1.1.99.1

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 (147) hide show
  1. data/History.txt +35 -0
  2. data/License.txt +1 -1
  3. data/Manifest.txt +22 -73
  4. data/README.txt +2 -2
  5. data/Rakefile +32 -7
  6. data/TODO.txt +9 -4
  7. data/bin/spec +1 -1
  8. data/cucumber.yml +2 -0
  9. data/examples/failing/spec_helper.rb +1 -1
  10. data/examples/passing/filtered_formatter.rb +18 -0
  11. data/examples/passing/filtered_formatter_example.rb +31 -0
  12. data/examples/passing/spec_helper.rb +1 -1
  13. data/examples/ruby1.9.compatibility/access_to_constants_spec.rb +17 -18
  14. data/features/before_and_after_blocks/before_and_after_blocks.feature +4 -4
  15. data/features/example_groups/autogenerated_docstrings.feature +2 -2
  16. data/features/example_groups/example_group_with_should_methods.feature +1 -1
  17. data/features/example_groups/nested_groups.feature +1 -1
  18. data/features/interop/examples_and_tests_together.feature +1 -1
  19. data/features/interop/test_but_not_test_unit.feature +1 -1
  20. data/features/interop/test_case_with_should_methods.feature +1 -1
  21. data/features/mock_framework_integration/use_flexmock.feature +22 -4
  22. data/features/mock_framework_integration/use_mocha.feature +27 -0
  23. data/features/mock_framework_integration/use_rr.feature +27 -0
  24. data/features/step_definitions/running_rspec.rb +5 -3
  25. data/features/support/env.rb +1 -1
  26. data/features-pending/cli/conditional_exclusion.feature +39 -0
  27. data/lib/{adapters → spec/adapters}/mock_frameworks/flexmock.rb +1 -0
  28. data/lib/{adapters → spec/adapters}/mock_frameworks/mocha.rb +1 -0
  29. data/lib/{adapters → spec/adapters}/mock_frameworks/rr.rb +1 -0
  30. data/lib/{adapters → spec/adapters}/mock_frameworks/rspec.rb +0 -1
  31. data/lib/spec/autorun.rb +3 -0
  32. data/lib/spec/example/before_and_after_hooks.rb +5 -20
  33. data/lib/spec/example/example_description.rb +15 -0
  34. data/lib/spec/example/example_group.rb +0 -15
  35. data/lib/spec/example/example_group_factory.rb +34 -46
  36. data/lib/spec/example/example_group_hierarchy.rb +53 -0
  37. data/lib/spec/example/example_group_methods.rb +96 -211
  38. data/lib/spec/example/example_methods.rb +62 -81
  39. data/lib/spec/example/module_reopening_fix.rb +23 -1
  40. data/lib/spec/example/predicate_matchers.rb +47 -0
  41. data/lib/spec/example/subject.rb +91 -0
  42. data/lib/spec/example.rb +4 -0
  43. data/lib/spec/expectations/extensions.rb +0 -1
  44. data/lib/spec/expectations/handler.rb +6 -1
  45. data/lib/spec/expectations.rb +1 -1
  46. data/lib/spec/interop/test/unit/testcase.rb +5 -22
  47. data/lib/spec/interop/test.rb +1 -0
  48. data/lib/spec/matchers/be.rb +2 -7
  49. data/lib/spec/matchers/be_close.rb +20 -5
  50. data/lib/spec/matchers/change.rb +5 -3
  51. data/lib/spec/matchers/eql.rb +24 -6
  52. data/lib/spec/matchers/equal.rb +24 -6
  53. data/lib/spec/matchers/exist.rb +21 -5
  54. data/lib/spec/matchers/generated_descriptions.rb +2 -2
  55. data/lib/spec/matchers/has.rb +28 -11
  56. data/lib/spec/matchers/match.rb +25 -7
  57. data/lib/spec/matchers/match_array.rb +1 -1
  58. data/lib/spec/matchers/method_missing.rb +2 -2
  59. data/lib/spec/matchers/operator_matcher.rb +12 -5
  60. data/lib/spec/matchers/raise_error.rb +1 -1
  61. data/lib/spec/matchers/respond_to.rb +1 -1
  62. data/lib/spec/matchers/satisfy.rb +5 -5
  63. data/lib/spec/matchers/throw_symbol.rb +1 -3
  64. data/lib/spec/mocks/argument_expectation.rb +1 -1
  65. data/lib/spec/mocks/argument_matchers.rb +233 -0
  66. data/lib/spec/mocks/error_generator.rb +2 -6
  67. data/lib/spec/mocks/message_expectation.rb +3 -11
  68. data/lib/spec/mocks/mock.rb +1 -1
  69. data/lib/spec/mocks/proxy.rb +5 -1
  70. data/lib/spec/runner/configuration.rb +3 -3
  71. data/lib/spec/runner/drb_command_line.rb +2 -1
  72. data/lib/spec/runner/example_group_runner.rb +2 -1
  73. data/lib/spec/runner/formatter/base_text_formatter.rb +28 -17
  74. data/lib/spec/runner/formatter/failing_example_groups_formatter.rb +3 -5
  75. data/lib/spec/runner/formatter/html_formatter.rb +2 -3
  76. data/lib/spec/runner/formatter/nested_text_formatter.rb +7 -25
  77. data/lib/spec/runner/formatter/progress_bar_formatter.rb +1 -1
  78. data/lib/spec/runner/formatter/specdoc_formatter.rb +1 -7
  79. data/lib/spec/runner/heckle_runner_unsupported.rb +1 -1
  80. data/lib/spec/runner/option_parser.rb +16 -19
  81. data/lib/spec/runner/options.rb +28 -26
  82. data/lib/spec/runner/reporter.rb +8 -9
  83. data/lib/spec/runner.rb +6 -28
  84. data/lib/spec/test/unit.rb +10 -0
  85. data/lib/spec/version.rb +2 -2
  86. data/{features/support → resources}/helpers/cmdline.rb +2 -2
  87. data/resources/rake/verify_rcov.rake +1 -1
  88. data/resources/spec/example_group_with_should_methods.rb +1 -1
  89. data/resources/spec/simple_spec.rb +1 -1
  90. data/resources/test/spec_and_test_together.rb +2 -3
  91. data/resources/test/spec_including_test_but_not_unit.rb +1 -1
  92. data/resources/test/test_case_with_should_methods.rb +2 -3
  93. data/rspec.gemspec +5 -5
  94. data/spec/spec/dsl/main_spec.rb +3 -3
  95. data/spec/spec/example/example_group_class_definition_spec.rb +11 -14
  96. data/spec/spec/example/example_group_factory_spec.rb +31 -44
  97. data/spec/spec/example/example_group_methods_spec.rb +86 -52
  98. data/spec/spec/example/example_group_spec.rb +16 -75
  99. data/spec/spec/example/example_matcher_spec.rb +10 -10
  100. data/spec/spec/example/example_methods_spec.rb +101 -241
  101. data/spec/spec/example/nested_example_group_spec.rb +2 -2
  102. data/spec/spec/example/pending_module_spec.rb +1 -1
  103. data/spec/spec/example/shared_example_group_spec.rb +2 -2
  104. data/spec/spec/interop/test/unit/resources/spec_that_fails.rb +2 -2
  105. data/spec/spec/interop/test/unit/resources/spec_that_passes.rb +2 -2
  106. data/spec/spec/interop/test/unit/resources/spec_with_errors.rb +2 -2
  107. data/spec/spec/interop/test/unit/resources/spec_with_options_hash.rb +2 -2
  108. data/spec/spec/interop/test/unit/resources/test_case_that_fails.rb +2 -2
  109. data/spec/spec/interop/test/unit/resources/test_case_that_passes.rb +2 -2
  110. data/spec/spec/interop/test/unit/resources/test_case_with_errors.rb +2 -2
  111. data/spec/spec/interop/test/unit/resources/testsuite_adapter_spec_with_test_unit.rb +2 -2
  112. data/spec/spec/matchers/change_spec.rb +8 -0
  113. data/spec/spec/matchers/exist_spec.rb +8 -4
  114. data/spec/spec/matchers/handler_spec.rb +8 -1
  115. data/spec/spec/matchers/matcher_methods_spec.rb +1 -1
  116. data/spec/spec/mocks/{bug_report_496.rb → bug_report_496_spec.rb} +0 -0
  117. data/spec/spec/mocks/failing_argument_matchers_spec.rb +95 -0
  118. data/spec/spec/mocks/nil_expectation_warning_spec.rb +1 -1
  119. data/spec/spec/mocks/passing_argument_matchers_spec.rb +145 -0
  120. data/spec/spec/runner/configuration_spec.rb +12 -12
  121. data/spec/spec/runner/formatter/base_text_formatter_spec.rb +72 -1
  122. data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +8 -8
  123. data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +4 -4
  124. data/spec/spec/runner/formatter/html_formatted-1.8.6.html +8 -8
  125. data/spec/spec/runner/formatter/html_formatted-1.8.7.html +38 -26
  126. data/spec/spec/runner/formatter/html_formatted-1.9.1.html +61 -53
  127. data/spec/spec/runner/formatter/html_formatter_spec.rb +100 -48
  128. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +20 -34
  129. data/spec/spec/runner/formatter/profile_formatter_spec.rb +1 -1
  130. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +8 -6
  131. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +6 -6
  132. data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +20 -20
  133. data/spec/spec/runner/formatter/text_mate_formatted-1.8.7.html +38 -26
  134. data/spec/spec/runner/formatter/{spec_mate_formatter_spec.rb → text_mate_formatter_spec.rb} +10 -8
  135. data/spec/spec/runner/heckle_runner_spec.rb +1 -1
  136. data/spec/spec/runner/option_parser_spec.rb +15 -13
  137. data/spec/spec/runner/options_spec.rb +34 -0
  138. data/spec/spec/runner/reporter_spec.rb +65 -61
  139. data/spec/spec/runner/spec_drb.opts +1 -0
  140. data/spec/spec/runner_spec.rb +7 -5
  141. data/spec/spec_helper.rb +23 -0
  142. metadata +25 -76
  143. data/examples/passing/legacy_spec.rb +0 -11
  144. data/features/support/helpers/story_helper.rb +0 -13
  145. data/lib/spec/expectations/extensions/string_and_symbol.rb +0 -17
  146. data/resources/spec/spec_with_flexmock.rb +0 -19
  147. data/spec/spec/spec_spec.rb +0 -21
@@ -6,18 +6,18 @@ module Spec
6
6
  @block = block
7
7
  end
8
8
 
9
- def matches?(given, &block)
9
+ def matches?(actual, &block)
10
10
  @block = block if block
11
- @given = given
12
- @block.call(given)
11
+ @actual = actual
12
+ @block.call(actual)
13
13
  end
14
14
 
15
15
  def failure_message
16
- "expected #{@given} to satisfy block"
16
+ "expected #{@actual} to satisfy block"
17
17
  end
18
18
 
19
19
  def negative_failure_message
20
- "expected #{@given} not to satisfy block"
20
+ "expected #{@actual} not to satisfy block"
21
21
  end
22
22
  end
23
23
 
@@ -35,9 +35,7 @@ module Spec
35
35
  if @expected_arg.nil?
36
36
  return @caught_symbol == @expected_symbol
37
37
  else
38
- # puts [@caught_symbol, @expected_symbol].inspect
39
- # puts [@caught_arg, @expected_arg].inspect
40
- return @caught_symbol == @expected_symbol && @caught_arg == @expected_arg
38
+ return (@caught_symbol == @expected_symbol) & (@caught_arg == @expected_arg)
41
39
  end
42
40
  end
43
41
  end
@@ -24,7 +24,7 @@ module Spec
24
24
  end
25
25
 
26
26
  def is_matcher?(obj)
27
- return obj.respond_to?(:matches?) && obj.respond_to?(:description)
27
+ return obj.respond_to?(:matches?) & obj.respond_to?(:description)
28
28
  end
29
29
 
30
30
  def args_match?(given_args)
@@ -0,0 +1,233 @@
1
+ module Spec
2
+ module Mocks
3
+
4
+ # ArgumentMatchers are messages that you can include in message
5
+ # expectations to match arguments against a broader check than simple
6
+ # equality.
7
+ #
8
+ # With the exception of any_args() and no_args(), the matchers
9
+ # are all positional - they match against the arg in the given position.
10
+ module ArgumentMatchers
11
+
12
+ class AnyArgsMatcher
13
+ def description
14
+ "any args"
15
+ end
16
+ end
17
+
18
+ class AnyArgMatcher
19
+ def initialize(ignore)
20
+ end
21
+
22
+ def ==(other)
23
+ true
24
+ end
25
+ end
26
+
27
+ class NoArgsMatcher
28
+ def description
29
+ "no args"
30
+ end
31
+ end
32
+
33
+ class RegexpMatcher
34
+ def initialize(regexp)
35
+ @regexp = regexp
36
+ end
37
+
38
+ def ==(value)
39
+ return value =~ @regexp unless value.is_a?(Regexp)
40
+ value == @regexp
41
+ end
42
+ end
43
+
44
+ class BooleanMatcher
45
+ def initialize(ignore)
46
+ end
47
+
48
+ def ==(value)
49
+ TrueClass === value || FalseClass === value
50
+ end
51
+ end
52
+
53
+ class HashIncludingMatcher
54
+ def initialize(expected)
55
+ @expected = expected
56
+ end
57
+
58
+ def ==(actual)
59
+ @expected.each do | key, value |
60
+ return false unless actual.has_key?(key) && value == actual[key]
61
+ end
62
+ true
63
+ rescue NoMethodError => ex
64
+ return false
65
+ end
66
+
67
+ def description
68
+ "hash_including(#{@expected.inspect.sub(/^\{/,"").sub(/\}$/,"")})"
69
+ end
70
+ end
71
+
72
+ class HashNotIncludingMatcher
73
+ def initialize(expected)
74
+ @expected = expected
75
+ end
76
+
77
+ def ==(actual)
78
+ @expected.each do | key, value |
79
+ return false if actual.has_key?(key) && value == actual[key]
80
+ end
81
+ true
82
+ rescue NoMethodError => ex
83
+ return false
84
+ end
85
+
86
+ def description
87
+ "hash_not_including(#{@expected.inspect.sub(/^\{/,"").sub(/\}$/,"")})"
88
+ end
89
+ end
90
+
91
+ class DuckTypeMatcher
92
+ def initialize(*methods_to_respond_to)
93
+ @methods_to_respond_to = methods_to_respond_to
94
+ end
95
+
96
+ def ==(value)
97
+ @methods_to_respond_to.all? { |sym| value.respond_to?(sym) }
98
+ end
99
+ end
100
+
101
+ class MatcherMatcher
102
+ def initialize(matcher)
103
+ @matcher = matcher
104
+ end
105
+
106
+ def ==(value)
107
+ @matcher.matches?(value)
108
+ end
109
+ end
110
+
111
+ class EqualityProxy
112
+ def initialize(given)
113
+ @given = given
114
+ end
115
+
116
+ def ==(expected)
117
+ @given == expected
118
+ end
119
+ end
120
+
121
+ class InstanceOf
122
+ def initialize(klass)
123
+ @klass = klass
124
+ end
125
+
126
+ def ==(actual)
127
+ actual.instance_of?(@klass)
128
+ end
129
+ end
130
+
131
+ class KindOf
132
+ def initialize(klass)
133
+ @klass = klass
134
+ end
135
+
136
+ def ==(actual)
137
+ actual.kind_of?(@klass)
138
+ end
139
+ end
140
+
141
+ # :call-seq:
142
+ # object.should_receive(:message).with(any_args())
143
+ #
144
+ # Passes if object receives :message with any args at all. This is
145
+ # really a more explicit variation of object.should_receive(:message)
146
+ def any_args
147
+ AnyArgsMatcher.new
148
+ end
149
+
150
+ # :call-seq:
151
+ # object.should_receive(:message).with(anything())
152
+ #
153
+ # Passes as long as there is an argument.
154
+ def anything
155
+ AnyArgMatcher.new(nil)
156
+ end
157
+
158
+ # :call-seq:
159
+ # object.should_receive(:message).with(no_args)
160
+ #
161
+ # Passes if no arguments are passed along with the message
162
+ def no_args
163
+ NoArgsMatcher.new
164
+ end
165
+
166
+ # :call-seq:
167
+ # object.should_receive(:message).with(duck_type(:hello))
168
+ # object.should_receive(:message).with(duck_type(:hello, :goodbye))
169
+ #
170
+ # Passes if the argument responds to the specified messages.
171
+ #
172
+ # == Examples
173
+ #
174
+ # array = []
175
+ # display = mock('display')
176
+ # display.should_receive(:present_names).with(duck_type(:length, :each))
177
+ # => passes
178
+ def duck_type(*args)
179
+ DuckTypeMatcher.new(*args)
180
+ end
181
+
182
+ # :call-seq:
183
+ # object.should_receive(:message).with(boolean())
184
+ #
185
+ # Passes if the argument is boolean.
186
+ def boolean
187
+ BooleanMatcher.new(nil)
188
+ end
189
+
190
+ # :call-seq:
191
+ # object.should_receive(:message).with(hash_including(:key => val))
192
+ # object.should_receive(:message).with(hash_including(:key))
193
+ # object.should_receive(:message).with(hash_including(:key, :key2 => val2))
194
+ # Passes if the argument is a hash that includes the specified key(s) or key/value
195
+ # pairs. If the hash includes other keys, it will still pass.
196
+ def hash_including(*args)
197
+ HashIncludingMatcher.new(anythingize_lonely_keys(*args))
198
+ end
199
+
200
+ # :call-seq:
201
+ # object.should_receive(:message).with(hash_not_including(:key => val))
202
+ # object.should_receive(:message).with(hash_not_including(:key))
203
+ # object.should_receive(:message).with(hash_not_including(:key, :key2 => :val2))
204
+ #
205
+ # Passes if the argument is a hash that doesn't include the specified key(s) or key/value
206
+ def hash_not_including(*args)
207
+ HashNotIncludingMatcher.new(anythingize_lonely_keys(*args))
208
+ end
209
+
210
+ # Passes if arg.instance_of?(klass)
211
+ def instance_of(klass)
212
+ InstanceOf.new(klass)
213
+ end
214
+
215
+ alias_method :an_instance_of, :instance_of
216
+
217
+ # Passes if arg.kind_of?(klass)
218
+ def kind_of(klass)
219
+ KindOf.new(klass)
220
+ end
221
+
222
+ alias_method :a_kind_of, :kind_of
223
+
224
+ private
225
+
226
+ def anythingize_lonely_keys(*args)
227
+ hash = args.last.class == Hash ? args.delete_at(-1) : {}
228
+ args.each { | arg | hash[arg] = anything }
229
+ hash
230
+ end
231
+ end
232
+ end
233
+ end
@@ -57,15 +57,11 @@ module Spec
57
57
  end
58
58
 
59
59
  def format_args(*args)
60
- return "(no args)" if args.empty? || args == [:no_args]
61
- return "(any args)" if args == [:any_args]
62
- "(" + arg_list(*args) + ")"
60
+ args.empty? ? "(no args)" : "(" + arg_list(*args) + ")"
63
61
  end
64
62
 
65
63
  def arg_list(*args)
66
- args.collect do |arg|
67
- arg.respond_to?(:description) ? arg.description : arg.inspect
68
- end.join(", ")
64
+ args.collect {|arg| arg.respond_to?(:description) ? arg.description : arg.inspect}.join(", ")
69
65
  end
70
66
 
71
67
  def count_message(count)
@@ -56,8 +56,6 @@ module Spec
56
56
  @expected_received_count < values.size
57
57
  end
58
58
  @return_block = block_given? ? return_block : lambda { value }
59
- # Ruby 1.9 - see where this is used below
60
- @ignore_args = !block_given?
61
59
  end
62
60
 
63
61
  # :call-seq:
@@ -157,9 +155,7 @@ module Spec
157
155
  end
158
156
 
159
157
  def invoke_consecutive_return_block(args, block)
160
- args << block unless block.nil?
161
- value = @return_block.call(*args)
162
-
158
+ value = invoke_return_block(args, block)
163
159
  index = [@actual_received_count, value.size-1].min
164
160
  value[index]
165
161
  end
@@ -169,13 +165,9 @@ module Spec
169
165
  # Ruby 1.9 - when we set @return_block to return values
170
166
  # regardless of arguments, any arguments will result in
171
167
  # a "wrong number of arguments" error
172
- if @ignore_args
173
- @return_block.call()
174
- else
175
- @return_block.call(*args)
176
- end
168
+ @return_block.arity > 0 ? @return_block.call(*args) : @return_block.call()
177
169
  end
178
-
170
+
179
171
  def clone_args_to_yield(args)
180
172
  @args_to_yield = args.clone
181
173
  @args_to_yield_were_cloned = true
@@ -22,7 +22,7 @@ module Spec
22
22
  end
23
23
 
24
24
  def method_missing(sym, *args, &block)
25
- __mock_proxy.instance_eval {@messages_received << [sym, args, block]}
25
+ __mock_proxy.record_message_received(sym, args, block)
26
26
  begin
27
27
  return self if __mock_proxy.null_object?
28
28
  super(sym, *args, &block)
@@ -82,6 +82,10 @@ module Spec
82
82
  def has_negative_expectation?(sym)
83
83
  @expectations.detect {|expectation| expectation.negative_expectation_for?(sym)}
84
84
  end
85
+
86
+ def record_message_received(sym, args, block)
87
+ @messages_received << [sym, args, block]
88
+ end
85
89
 
86
90
  def message_received(sym, *args, &block)
87
91
  expectation = find_matching_expectation(sym, *args)
@@ -118,7 +122,7 @@ module Spec
118
122
  end
119
123
 
120
124
  def warn_if_nil_class(sym)
121
- if proxy_for_nil_class? && @@warn_about_expectations_on_nil
125
+ if proxy_for_nil_class? & @@warn_about_expectations_on_nil
122
126
  Kernel.warn("An expectation of :#{sym} was set on nil. Called from #{caller[2]}. Use allow_message_expectations_on_nil to disable warnings.")
123
127
  end
124
128
  end
@@ -143,14 +143,14 @@ module Spec
143
143
  [get_type_from_options(options)].flatten.each do |required_example_group|
144
144
  required_example_group = required_example_group.to_sym if required_example_group
145
145
  modules.each do |mod|
146
- Spec::Example::ExampleGroupFactory.get(required_example_group).__send__(action, mod)
146
+ Spec::Example::ExampleGroupFactory[required_example_group].__send__(action, mod)
147
147
  end
148
148
  end
149
149
  end
150
150
 
151
151
  def add_callback(sym, *args, &proc)
152
152
  scope, options = Spec::Example.scope_and_options(*args)
153
- example_group = Spec::Example::ExampleGroupFactory.get(get_type_from_options(options))
153
+ example_group = Spec::Example::ExampleGroupFactory[get_type_from_options(options)]
154
154
  example_group.__send__(sym, scope, &proc)
155
155
  end
156
156
 
@@ -159,7 +159,7 @@ module Spec
159
159
  end
160
160
 
161
161
  def mock_framework_path(framework_name)
162
- File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "adapters", "mock_frameworks", framework_name))
162
+ File.expand_path(File.join(File.dirname(__FILE__), "/../adapters/mock_frameworks/#{framework_name}"))
163
163
  end
164
164
  end
165
165
  end
@@ -8,7 +8,8 @@ module Spec
8
8
  # CommandLine - making it possible for clients to use both interchangeably.
9
9
  def self.run(options)
10
10
  begin
11
- DRb.start_service
11
+ # See http://redmine.ruby-lang.org/issues/show/496 as to why we specify localhost:0
12
+ DRb.start_service("druby://localhost:0")
12
13
  spec_server = DRbObject.new_with_uri("druby://127.0.0.1:8989")
13
14
  spec_server.run(options.argv, options.error_stream, options.output_stream)
14
15
  rescue DRb::DRbConnError => e
@@ -27,7 +27,8 @@ module Spec
27
27
  finish
28
28
  end
29
29
 
30
- protected
30
+ protected
31
+
31
32
  def prepare
32
33
  reporter.start(number_of_examples)
33
34
  example_groups.reverse! if reverse
@@ -1,4 +1,5 @@
1
1
  require 'spec/runner/formatter/base_formatter'
2
+ require 'fileutils'
2
3
 
3
4
  module Spec
4
5
  module Runner
@@ -23,27 +24,31 @@ module Spec
23
24
  end
24
25
 
25
26
  def example_pending(example, message, pending_caller)
26
- @pending_examples << [example.full_description, message, pending_caller]
27
+ @pending_examples << ["#{@example_group.description} #{example.description}", message, pending_caller]
27
28
  end
28
29
 
29
30
  def dump_failure(counter, failure)
30
31
  @output.puts
31
32
  @output.puts "#{counter.to_s})"
32
- @output.puts colourise("#{failure.header}\n#{failure.exception.message}", failure)
33
+ @output.puts colorize_failure("#{failure.header}\n#{failure.exception.message}", failure)
33
34
  @output.puts format_backtrace(failure.exception.backtrace)
34
35
  @output.flush
35
36
  end
36
37
 
37
- def colourise(s, failure)
38
- if(failure.expectation_not_met?)
39
- red(s)
40
- elsif(failure.pending_fixed?)
41
- blue(s)
42
- else
43
- magenta(s)
44
- end
38
+ def colorize_failure(message, failure)
39
+ failure.pending_fixed? ? blue(message) : red(message)
45
40
  end
46
-
41
+
42
+ def colourise(message, failure)
43
+ Kernel.warn <<-NOTICE
44
+ DEPRECATED: BaseTextFormatter#colourise is deprecated and will be
45
+ removed from a future version of RSpec.
46
+
47
+ Please use colorize_failure instead.
48
+ NOTICE
49
+ colorize_failure(message, failure)
50
+ end
51
+
47
52
  def dump_summary(duration, example_count, failure_count, pending_count)
48
53
  return if dry_run?
49
54
  @output.puts
@@ -78,9 +83,7 @@ module Spec
78
83
  end
79
84
 
80
85
  def close
81
- if IO === @output && @output != $stdout
82
- @output.close
83
- end
86
+ @output.close if (IO === @output) & (@output != $stdout)
84
87
  end
85
88
 
86
89
  def format_backtrace(backtrace)
@@ -103,7 +106,7 @@ module Spec
103
106
  end
104
107
 
105
108
  def colour(text, colour_code)
106
- return text unless colour? && output_to_tty?
109
+ return text unless ENV['RSPEC_COLOR'] || (colour? & output_to_tty?)
107
110
  "#{colour_code}#{text}\e[0m"
108
111
  end
109
112
 
@@ -117,10 +120,18 @@ module Spec
117
120
 
118
121
  def green(text); colour(text, "\e[32m"); end
119
122
  def red(text); colour(text, "\e[31m"); end
120
- def magenta(text); colour(text, "\e[35m"); end
121
123
  def yellow(text); colour(text, "\e[33m"); end
122
124
  def blue(text); colour(text, "\e[34m"); end
123
-
125
+
126
+ def magenta(text)
127
+ Kernel.warn <<-NOTICE
128
+ DEPRECATED: BaseTextFormatter#magenta is deprecated and will be
129
+ removed from a future version of RSpec.
130
+
131
+ Please use red instead (it is red/green/refactor after all).
132
+ NOTICE
133
+ red(text)
134
+ end
124
135
  end
125
136
  end
126
137
  end
@@ -6,21 +6,19 @@ module Spec
6
6
  class FailingExampleGroupsFormatter < BaseTextFormatter
7
7
  def example_failed(example, counter, failure)
8
8
  if @example_group
9
- description_parts = @example_group.description_parts.collect do |description|
10
- description =~ /(.*) \(druby.*\)$/ ? $1 : description
11
- end
12
- @output.puts ::Spec::Example::ExampleGroupMethods.description_text(*description_parts)
9
+ @output.puts @example_group.filtered_description(/(.*) \(druby.*\)$/)
13
10
 
14
11
  @output.flush
15
12
  @example_group = nil
16
13
  end
17
14
  end
18
-
15
+
19
16
  def dump_failure(counter, failure)
20
17
  end
21
18
 
22
19
  def dump_summary(duration, example_count, failure_count, pending_count)
23
20
  end
21
+
24
22
  end
25
23
  end
26
24
  end
@@ -38,7 +38,6 @@ module Spec
38
38
  def add_example_group(example_group)
39
39
  super
40
40
  @example_group_red = false
41
- @example_group_red = false
42
41
  @example_group_number += 1
43
42
  unless example_group_number == 1
44
43
  @output.puts " </dl>"
@@ -214,7 +213,7 @@ EOF
214
213
  def global_styles
215
214
  <<-EOF
216
215
  #rspec-header {
217
- background: #65C400; color: #fff; height: 42px;
216
+ background: #65C400; color: #fff; height: 4em;
218
217
  }
219
218
 
220
219
  .rspec-report h1 {
@@ -222,7 +221,7 @@ EOF
222
221
  padding: 10px;
223
222
  font-family: "Lucida Grande", Helvetica, sans-serif;
224
223
  font-size: 1.8em;
225
- float: left;
224
+ position: absolute;
226
225
  }
227
226
 
228
227
  #summary {
@@ -4,33 +4,25 @@ module Spec
4
4
  module Runner
5
5
  module Formatter
6
6
  class NestedTextFormatter < BaseTextFormatter
7
- attr_reader :previous_nested_example_groups
8
7
  def initialize(options, where)
9
8
  super
10
- @previous_nested_example_groups = []
9
+ @last_nested_descriptions = []
11
10
  end
12
11
 
13
12
  def add_example_group(example_group)
14
13
  super
15
14
 
16
- current_nested_example_groups = described_example_group_chain
17
- current_nested_example_groups.each_with_index do |nested_example_group, i|
18
- unless nested_example_group == previous_nested_example_groups[i]
19
- output.puts "#{' ' * i}#{nested_example_group.description_args.join}"
15
+ example_group.nested_descriptions.each_with_index do |nested_description, i|
16
+ unless nested_description == @last_nested_descriptions[i]
17
+ output.puts "#{' ' * i}#{nested_description}"
20
18
  end
21
19
  end
22
20
 
23
- @previous_nested_example_groups = described_example_group_chain
21
+ @last_nested_descriptions = example_group.nested_descriptions
24
22
  end
25
23
 
26
24
  def example_failed(example, counter, failure)
27
- message = if failure.expectation_not_met?
28
- "#{current_indentation}#{example.description} (FAILED - #{counter})"
29
- else
30
- "#{current_indentation}#{example.description} (ERROR - #{counter})"
31
- end
32
-
33
- output.puts(failure.expectation_not_met? ? red(message) : magenta(message))
25
+ output.puts(red("#{current_indentation}#{example.description} (FAILED - #{counter})"))
34
26
  output.flush
35
27
  end
36
28
 
@@ -47,17 +39,7 @@ module Spec
47
39
  end
48
40
 
49
41
  def current_indentation
50
- ' ' * previous_nested_example_groups.length
51
- end
52
-
53
- def described_example_group_chain
54
- example_group_chain = []
55
- example_group.__send__(:example_group_hierarchy).each do |example_group_class|
56
- unless example_group_class.description_args.empty?
57
- example_group_chain << example_group_class
58
- end
59
- end
60
- example_group_chain
42
+ ' ' * @last_nested_descriptions.length
61
43
  end
62
44
  end
63
45
  end
@@ -5,7 +5,7 @@ module Spec
5
5
  module Formatter
6
6
  class ProgressBarFormatter < BaseTextFormatter
7
7
  def example_failed(example, counter, failure)
8
- @output.print colourise('F', failure)
8
+ @output.print colorize_failure('F', failure)
9
9
  @output.flush
10
10
  end
11
11
 
@@ -12,13 +12,7 @@ module Spec
12
12
  end
13
13
 
14
14
  def example_failed(example, counter, failure)
15
- message = if failure.expectation_not_met?
16
- "- #{example.description} (FAILED - #{counter})"
17
- else
18
- "- #{example.description} (ERROR - #{counter})"
19
- end
20
-
21
- output.puts(failure.expectation_not_met? ? red(message) : magenta(message))
15
+ output.puts(red("- #{example.description} (FAILED - #{counter})"))
22
16
  output.flush
23
17
  end
24
18
 
@@ -3,7 +3,7 @@ module Spec
3
3
  # Dummy implementation for Windows that just fails (Heckle is not supported on Windows)
4
4
  class HeckleRunner
5
5
  def initialize(filter)
6
- raise "Heckle not supported on Windows"
6
+ raise "Heckle is not supported on Windows or Ruby 1.9"
7
7
  end
8
8
  end
9
9
  end