rspec 1.2.6 → 1.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/History.rdoc +22 -0
  2. data/Manifest.txt +9 -4
  3. data/Rakefile +13 -12
  4. data/Upgrade.rdoc +1 -1
  5. data/features/command_line/line_number_option.feature +56 -0
  6. data/features/command_line/line_number_option_with_example_with_no_name.feature +22 -0
  7. data/features/mocks/stub_implementation.feature +26 -0
  8. data/lib/autotest/rspec.rb +7 -7
  9. data/lib/spec/autorun.rb +1 -1
  10. data/lib/spec/deprecation.rb +3 -3
  11. data/lib/spec/dsl.rb +0 -1
  12. data/lib/spec/dsl/main.rb +6 -6
  13. data/lib/spec/example.rb +28 -29
  14. data/lib/spec/example/args_and_options.rb +1 -1
  15. data/lib/spec/example/before_and_after_hooks.rb +10 -10
  16. data/lib/spec/example/errors.rb +8 -3
  17. data/lib/spec/example/example_group.rb +0 -1
  18. data/lib/spec/example/example_group_factory.rb +3 -3
  19. data/lib/spec/example/example_group_hierarchy.rb +10 -10
  20. data/lib/spec/example/example_group_methods.rb +37 -29
  21. data/lib/spec/example/example_group_proxy.rb +9 -10
  22. data/lib/spec/example/example_matcher.rb +3 -3
  23. data/lib/spec/example/example_methods.rb +11 -11
  24. data/lib/spec/example/example_proxy.rb +5 -5
  25. data/lib/spec/example/module_reopening_fix.rb +7 -7
  26. data/lib/spec/example/pending.rb +1 -1
  27. data/lib/spec/example/predicate_matchers.rb +0 -1
  28. data/lib/spec/example/shared_example_group.rb +5 -5
  29. data/lib/spec/example/subject.rb +12 -16
  30. data/lib/spec/expectations/extensions/kernel.rb +1 -1
  31. data/lib/spec/expectations/fail_with.rb +4 -0
  32. data/lib/spec/matchers/generated_descriptions.rb +4 -16
  33. data/lib/spec/matchers/match.rb +5 -4
  34. data/lib/spec/matchers/matcher.rb +21 -3
  35. data/lib/spec/matchers/operator_matcher.rb +1 -1
  36. data/lib/spec/mocks/errors.rb +1 -1
  37. data/lib/spec/mocks/message_expectation.rb +3 -2
  38. data/lib/spec/mocks/methods.rb +8 -5
  39. data/lib/spec/mocks/proxy.rb +2 -2
  40. data/lib/spec/rake/spectask.rb +9 -3
  41. data/lib/spec/runner.rb +1 -1
  42. data/lib/spec/runner/{spec_parser.rb → line_number_query.rb} +20 -9
  43. data/lib/spec/runner/options.rb +10 -2
  44. data/lib/spec/version.rb +3 -2
  45. data/spec/autotest/failed_results_re_spec.rb +7 -0
  46. data/spec/spec/example/example_group_methods_spec.rb +61 -0
  47. data/spec/spec/example/example_matcher_spec.rb +7 -0
  48. data/spec/spec/example/example_methods_spec.rb +35 -7
  49. data/spec/spec/expectations/fail_with_spec.rb +18 -1
  50. data/spec/spec/matchers/match_spec.rb +20 -0
  51. data/spec/spec/matchers/matcher_spec.rb +27 -28
  52. data/spec/spec/matchers/operator_matcher_spec.rb +1 -1
  53. data/spec/spec/mocks/bug_report_10263_spec.rb +4 -1
  54. data/spec/spec/mocks/bug_report_830_spec.rb +21 -0
  55. data/spec/spec/mocks/options_hash_spec.rb +1 -1
  56. data/spec/spec/mocks/stub_chain_spec.rb +7 -0
  57. data/spec/spec/mocks/stub_implementation_spec.rb +31 -0
  58. data/spec/spec/rake/spectask_spec.rb +150 -0
  59. data/spec/spec/runner/{spec_parser/spec_parser_fixture.rb → line_number_query/line_number_query_fixture.rb} +4 -4
  60. data/spec/spec/runner/{spec_parser_spec.rb → line_number_query_spec.rb} +31 -10
  61. data/spec/spec/runner/option_parser_spec.rb +1 -1
  62. data/spec/spec/runner/options_spec.rb +33 -25
  63. metadata +15 -10
  64. data/.autotest +0 -5
@@ -12,7 +12,7 @@ module Spec
12
12
  args.options.merge!(options)
13
13
  args.options
14
14
  end
15
-
15
+
16
16
  def set_location(options, location) # :nodoc:
17
17
  options[:location] ||= location
18
18
  end
@@ -5,12 +5,12 @@ module Spec
5
5
  def before_suite_parts # :nodoc:
6
6
  @before_suite_parts ||= []
7
7
  end
8
-
8
+
9
9
  def after_suite_parts # :nodoc:
10
10
  @after_suite_parts ||= []
11
11
  end
12
12
  end
13
-
13
+
14
14
  # Registers a block to be executed before examples. <tt>scope</tt> can be
15
15
  # <tt>:each</tt> (default), <tt>:all</tt>, or <tt>:suite</tt>. When
16
16
  # <tt>:each</tt>, the block is executed before each example. When
@@ -23,7 +23,7 @@ module Spec
23
23
 
24
24
  # Registers a block to be executed before each example.
25
25
  # This method prepends +block+ to existing before blocks.
26
- #
26
+ #
27
27
  # See <tt>append_before</tt> for scoping semantics.
28
28
  def prepend_before(scope = :each, &block)
29
29
  before_parts(scope).unshift(block)
@@ -31,7 +31,7 @@ module Spec
31
31
 
32
32
  # Registers a block to be executed after each example.
33
33
  # This method prepends +block+ to existing after blocks.
34
- #
34
+ #
35
35
  # See <tt>append_before</tt> for scoping semantics.
36
36
  def prepend_after(scope = :each, &block)
37
37
  after_parts(scope).unshift(block)
@@ -40,7 +40,7 @@ module Spec
40
40
 
41
41
  # Registers a block to be executed after each example.
42
42
  # This method appends +block+ to existing after blocks.
43
- #
43
+ #
44
44
  # See <tt>append_before</tt> for scoping semantics.
45
45
  def append_after(scope = :each, &block)
46
46
  after_parts(scope) << block
@@ -53,7 +53,7 @@ module Spec
53
53
  def after_each_parts # :nodoc:
54
54
  @after_each_parts ||= []
55
55
  end
56
-
56
+
57
57
  def before_all_parts # :nodoc:
58
58
  @before_all_parts ||= []
59
59
  end
@@ -65,13 +65,13 @@ module Spec
65
65
  def before_suite_parts # :nodoc:
66
66
  BeforeAndAfterHooks.before_suite_parts
67
67
  end
68
-
68
+
69
69
  def after_suite_parts # :nodoc:
70
70
  BeforeAndAfterHooks.after_suite_parts
71
71
  end
72
-
72
+
73
73
  private
74
-
74
+
75
75
  def before_parts(scope)
76
76
  case scope
77
77
  when :each; before_each_parts
@@ -90,4 +90,4 @@ module Spec
90
90
 
91
91
  end
92
92
  end
93
- end
93
+ end
@@ -1,7 +1,7 @@
1
1
  module Spec
2
2
  module Example
3
3
  class ExamplePendingError < StandardError; end
4
-
4
+
5
5
  class NotYetImplementedError < ExamplePendingError
6
6
  MESSAGE = "Not Yet Implemented"
7
7
  def initialize
@@ -10,10 +10,15 @@ module Spec
10
10
  end
11
11
 
12
12
  class PendingExampleFixedError < StandardError; end
13
-
13
+
14
14
  class NoDescriptionError < ArgumentError
15
+ class << self
16
+ def message(kind, location)
17
+ "No description supplied for #{kind} declared on #{location}"
18
+ end
19
+ end
15
20
  def initialize(kind, location)
16
- super("No description supplied for #{kind} declared on #{location}")
21
+ super(self.class.message(kind, location))
17
22
  end
18
23
  end
19
24
  end
@@ -8,4 +8,3 @@ module Spec
8
8
  end
9
9
  end
10
10
  end
11
-
@@ -1,10 +1,10 @@
1
1
  module Spec
2
2
  module Example
3
-
3
+
4
4
  class ExampleGroupFactory
5
5
  module ClassMethods
6
6
  include Spec::Example::ArgsAndOptions
7
-
7
+
8
8
  def reset
9
9
  @example_group_types = nil
10
10
  default(ExampleGroup)
@@ -23,7 +23,7 @@ module Spec
23
23
  def create_shared_example_group(*args, &example_group_block) # :nodoc:
24
24
  ::Spec::Example::SharedExampleGroup.register(*args, &example_group_block)
25
25
  end
26
-
26
+
27
27
  def create_example_group(*args, &block)
28
28
  raise ArgumentError if args.empty? || block.nil?
29
29
  add_options(args)
@@ -8,43 +8,43 @@ module Spec
8
8
  flatten!
9
9
  end
10
10
  end
11
-
11
+
12
12
  def run_before_all(example)
13
13
  example.eval_each_fail_fast(before_all_parts)
14
14
  end
15
-
15
+
16
16
  def run_before_each(example)
17
17
  example.eval_each_fail_fast(before_each_parts)
18
18
  end
19
-
19
+
20
20
  def run_after_each(example)
21
21
  example.eval_each_fail_slow(after_each_parts)
22
22
  end
23
-
23
+
24
24
  def run_after_all(example)
25
25
  example.eval_each_fail_slow(after_all_parts)
26
26
  end
27
-
27
+
28
28
  def before_all_parts
29
29
  @before_all_parts ||= collect {|klass| klass.before_all_parts}.flatten
30
30
  end
31
-
31
+
32
32
  def before_each_parts
33
33
  @before_each_parts ||= collect {|klass| klass.before_each_parts}.flatten
34
34
  end
35
-
35
+
36
36
  def after_each_parts
37
37
  @after_each_parts ||= reverse.collect {|klass| klass.after_each_parts}.flatten
38
38
  end
39
-
39
+
40
40
  def after_all_parts
41
41
  @after_all_parts ||= reverse.collect {|klass| klass.after_all_parts}.flatten
42
42
  end
43
-
43
+
44
44
  def nested_descriptions
45
45
  @nested_descriptions ||= collect {|eg| nested_description_from(eg) == "" ? nil : nested_description_from(eg) }.compact
46
46
  end
47
-
47
+
48
48
  def nested_description_from(example_group)
49
49
  example_group.description_args.join
50
50
  end
@@ -1,7 +1,7 @@
1
1
  module Spec
2
2
  module Example
3
3
 
4
- module ExampleGroupMethods
4
+ module ExampleGroupMethods
5
5
  class << self
6
6
  attr_accessor :matcher_class
7
7
 
@@ -20,16 +20,16 @@ module Spec
20
20
  include Spec::Example::ArgsAndOptions
21
21
 
22
22
  attr_reader :location
23
-
23
+
24
24
  def options # :nodoc:
25
25
  @options ||= {}
26
26
  end
27
-
27
+
28
28
  def inherited(klass) # :nodoc:
29
29
  super
30
30
  ExampleGroupFactory.register_example_group(klass)
31
31
  end
32
-
32
+
33
33
  # Makes the describe/it syntax available from a class. For example:
34
34
  #
35
35
  # class StackSpec < Spec::ExampleGroup
@@ -59,14 +59,14 @@ module Spec
59
59
  end
60
60
  end
61
61
  alias :context :describe
62
-
62
+
63
63
  # Use this to pull in examples from shared example groups.
64
64
  def it_should_behave_like(*shared_example_groups)
65
65
  shared_example_groups.each do |group|
66
66
  include_shared_example_group(group)
67
67
  end
68
68
  end
69
-
69
+
70
70
  # Creates an instance of the current example group class and adds it to
71
71
  # a collection of examples of the current example group.
72
72
  def example(description=nil, options={}, backtrace=nil, &implementation)
@@ -75,7 +75,7 @@ module Spec
75
75
  example_implementations[example_proxy] = implementation || pending_implementation
76
76
  example_proxy
77
77
  end
78
-
78
+
79
79
  def pending_implementation
80
80
  lambda { raise(Spec::Example::NotYetImplementedError) }
81
81
  end
@@ -87,10 +87,10 @@ module Spec
87
87
  def xexample(description=nil, opts={}, &block)
88
88
  Kernel.warn("Example disabled: #{description}")
89
89
  end
90
-
90
+
91
91
  alias_method :xit, :xexample
92
92
  alias_method :xspecify, :xexample
93
-
93
+
94
94
  def run(run_options)
95
95
  examples = examples_to_run(run_options)
96
96
  notify(run_options.reporter) unless examples.empty?
@@ -110,7 +110,7 @@ module Spec
110
110
  @location = File.expand_path(options[:location]) if options[:location]
111
111
  self
112
112
  end
113
-
113
+
114
114
  def notify(reporter) # :nodoc:
115
115
  reporter.example_group_started(ExampleGroupProxy.new(self))
116
116
  end
@@ -118,33 +118,33 @@ module Spec
118
118
  def description
119
119
  @description ||= ExampleGroupMethods.build_description_from(*description_parts) || to_s
120
120
  end
121
-
121
+
122
122
  def described_type
123
123
  @described_type ||= description_parts.reverse.find {|part| part.is_a?(Module)}
124
124
  end
125
-
125
+
126
126
  def described_class
127
127
  @described_class ||= Class === described_type ? described_type : nil
128
128
  end
129
-
129
+
130
130
  def description_args
131
131
  @description_args ||= []
132
132
  end
133
-
133
+
134
134
  def description_parts #:nodoc:
135
135
  @description_parts ||= example_group_hierarchy.inject([]) do |parts, example_group_class|
136
136
  [parts << example_group_class.description_args].flatten
137
137
  end
138
138
  end
139
-
139
+
140
140
  def example_proxies # :nodoc:
141
141
  @example_proxies ||= []
142
142
  end
143
-
143
+
144
144
  def example_implementations # :nodoc:
145
145
  @example_implementations ||= {}
146
146
  end
147
-
147
+
148
148
  def examples(run_options=nil) #:nodoc:
149
149
  (run_options && run_options.reverse) ? example_proxies.reverse : example_proxies
150
150
  end
@@ -156,15 +156,15 @@ module Spec
156
156
  def example_group_hierarchy
157
157
  @example_group_hierarchy ||= ExampleGroupHierarchy.new(self)
158
158
  end
159
-
159
+
160
160
  def nested_descriptions
161
161
  example_group_hierarchy.nested_descriptions
162
162
  end
163
-
163
+
164
164
  def include_constants_in(mod)
165
165
  include mod if (Spec::Ruby.version.to_f >= 1.9) & (Module === mod) & !(Class === mod)
166
166
  end
167
-
167
+
168
168
  private
169
169
 
170
170
  def subclass(*args, &example_group_block)
@@ -201,16 +201,16 @@ module Spec
201
201
  return [success, instance_variables] unless success
202
202
 
203
203
  after_all_instance_variables = instance_variables
204
-
204
+
205
205
  examples.each do |example|
206
206
  example_group_instance = new(example, &example_implementations[example])
207
207
  success &= example_group_instance.execute(run_options, instance_variables)
208
208
  after_all_instance_variables = example_group_instance.instance_variable_hash
209
209
  end
210
-
210
+
211
211
  return [success, after_all_instance_variables]
212
212
  end
213
-
213
+
214
214
  def run_after_all(success, instance_variables, run_options)
215
215
  return success if example_group_hierarchy.after_all_parts.empty?
216
216
  example_proxy = ExampleProxy.new("after(:all)")
@@ -222,13 +222,21 @@ module Spec
222
222
  run_options.reporter.example_failed(example_proxy, e)
223
223
  false
224
224
  end
225
-
225
+
226
226
  def examples_to_run(run_options)
227
227
  return example_proxies unless examples_were_specified?(run_options)
228
- example_proxies.reject do |proxy|
229
- matcher = ExampleGroupMethods.matcher_class.
230
- new(description.to_s, proxy.description)
231
- !matcher.matches?(run_options.examples)
228
+ if run_options.line_number_requested?
229
+ if location =~ /:#{run_options.example_line}$/
230
+ example_proxies
231
+ else
232
+ example_proxies.select {|proxy| proxy.location =~ /:#{run_options.example_line}$/}
233
+ end
234
+ else
235
+ example_proxies.reject do |proxy|
236
+ matcher = ExampleGroupMethods.matcher_class.
237
+ new(description.to_s, proxy.description)
238
+ !matcher.matches?(run_options.examples)
239
+ end
232
240
  end
233
241
  end
234
242
 
@@ -239,7 +247,7 @@ module Spec
239
247
  def method_added(name) # :nodoc:
240
248
  example(name.to_s, {}, caller(0)[1]) {__send__ name.to_s} if example_method?(name.to_s)
241
249
  end
242
-
250
+
243
251
  def example_method?(method_name)
244
252
  should_method?(method_name)
245
253
  end
@@ -3,7 +3,7 @@ module Spec
3
3
  # Lightweight proxy for an example group. This is the object that is passed
4
4
  # to Spec::Runner::Formatter::BaseFormatter#example_group_started
5
5
  class ExampleGroupProxy
6
-
6
+
7
7
  def initialize(example_group) # :nodoc:
8
8
  @description = example_group.description
9
9
  @nested_descriptions = example_group.nested_descriptions
@@ -14,35 +14,35 @@ module Spec
14
14
  @options.delete(:location)
15
15
  @options.delete(:scope)
16
16
  end
17
-
17
+
18
18
  # Optional hash passed to the example group declaration. Note that RSpec uses
19
19
  # this hash internally and reserves the keys :location and :scope for its own
20
20
  # use (and removes them from this hash)
21
21
  attr_reader :options
22
-
22
+
23
23
  # This is the description passed to the <tt>describe()</tt> method or any
24
24
  # of its aliases
25
25
  attr_reader :description
26
-
26
+
27
27
  # Used by Spec::Runner::Formatter::NestedTextFormatter to access the
28
28
  # description of each example group in a nested group separately.
29
29
  attr_reader :nested_descriptions
30
-
30
+
31
31
  # A collection of ExampleGroupProxy objects, one for each example
32
32
  # declared in this group.
33
33
  attr_reader :examples
34
-
34
+
35
35
  # The file and line number at which the proxied example group
36
36
  # was declared. This is extracted from <tt>caller</tt>, and is therefore
37
37
  # formatted as an individual line in a backtrace.
38
38
  attr_reader :location
39
-
39
+
40
40
  # Deprecated - use location() instead
41
41
  def backtrace
42
42
  Spec::deprecate("ExampleGroupProxy#backtrace","ExampleGroupProxy#location")
43
43
  @backtrace
44
44
  end
45
-
45
+
46
46
  # Deprecated - just use gsub on the description instead.
47
47
  def filtered_description(regexp)
48
48
  Spec::deprecate("ExampleGroupProxy#filtered_description","gsub (or similar) to modify ExampleGroupProxy#description")
@@ -52,11 +52,10 @@ module Spec
52
52
  end
53
53
  )
54
54
  end
55
-
55
+
56
56
  def ==(other) # :nodoc:
57
57
  other.description == description
58
58
  end
59
59
  end
60
60
  end
61
61
  end
62
-
@@ -5,13 +5,13 @@ module Spec
5
5
  @example_group_description = example_group_description
6
6
  @example_name = example_name
7
7
  end
8
-
8
+
9
9
  def matches?(specified_examples)
10
10
  specified_examples.any? do |specified_example|
11
11
  matches_literal_example?(specified_example) || matches_example_not_considering_modules?(specified_example)
12
12
  end
13
13
  end
14
-
14
+
15
15
  protected
16
16
  def matches_literal_example?(specified_example)
17
17
  specified_example =~ /(^#{example_group_regex} #{example_regexp}$|^#{example_group_regex}$|^#{example_group_with_before_all_regexp}$|^#{example_regexp}$)/
@@ -34,7 +34,7 @@ module Spec
34
34
  end
35
35
 
36
36
  def example_regexp
37
- Regexp.escape(@example_name)
37
+ Regexp.escape(@example_name) if @example_name
38
38
  end
39
39
  end
40
40