rspec-core 2.14.8 → 2.99.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +8 -8
  2. data/Changelog.md +54 -8
  3. data/features/command_line/order.feature +5 -8
  4. data/features/configuration/custom_settings.feature +10 -10
  5. data/features/configuration/deprecation_stream.feature +3 -3
  6. data/features/configuration/read_options_from_file.feature +1 -1
  7. data/features/example_groups/shared_examples.feature +2 -2
  8. data/features/hooks/around_hooks.feature +1 -1
  9. data/features/metadata/current_example.feature +43 -4
  10. data/features/metadata/user_defined.feature +12 -12
  11. data/lib/autotest/rspec2.rb +60 -56
  12. data/lib/rspec/core.rb +40 -2
  13. data/lib/rspec/core/caller_filter.rb +55 -0
  14. data/lib/rspec/core/command_line.rb +2 -2
  15. data/lib/rspec/core/configuration.rb +201 -13
  16. data/lib/rspec/core/deprecation.rb +2 -7
  17. data/lib/rspec/core/example.rb +5 -8
  18. data/lib/rspec/core/example_group.rb +101 -17
  19. data/lib/rspec/core/filter_manager.rb +2 -2
  20. data/lib/rspec/core/formatters/deprecation_formatter.rb +173 -15
  21. data/lib/rspec/core/formatters/text_mate_formatter.rb +0 -12
  22. data/lib/rspec/core/hooks.rb +1 -1
  23. data/lib/rspec/core/memoized_helpers.rb +49 -17
  24. data/lib/rspec/core/metadata.rb +1 -1
  25. data/lib/rspec/core/option_parser.rb +8 -3
  26. data/lib/rspec/core/pending.rb +14 -10
  27. data/lib/rspec/core/rake_task.rb +30 -6
  28. data/lib/rspec/core/runner.rb +9 -0
  29. data/lib/rspec/core/shared_example_group.rb +11 -9
  30. data/lib/rspec/core/shared_example_group/collection.rb +3 -1
  31. data/lib/rspec/core/version.rb +1 -2
  32. data/spec/command_line/order_spec.rb +4 -4
  33. data/spec/rspec/core/backtrace_cleaner_spec.rb +10 -10
  34. data/spec/rspec/core/caller_filter_spec.rb +58 -0
  35. data/spec/rspec/core/command_line_spec.rb +1 -0
  36. data/spec/rspec/core/configuration_options_spec.rb +6 -6
  37. data/spec/rspec/core/configuration_spec.rb +285 -52
  38. data/spec/rspec/core/deprecation_spec.rb +10 -29
  39. data/spec/rspec/core/deprecations_spec.rb +0 -14
  40. data/spec/rspec/core/example_group_spec.rb +74 -56
  41. data/spec/rspec/core/example_spec.rb +54 -17
  42. data/spec/rspec/core/filter_manager_spec.rb +2 -2
  43. data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +156 -52
  44. data/spec/rspec/core/formatters/html_formatter_spec.rb +1 -1
  45. data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +1 -2
  46. data/spec/rspec/core/hooks_spec.rb +2 -0
  47. data/spec/rspec/core/memoized_helpers_spec.rb +154 -113
  48. data/spec/rspec/core/metadata_spec.rb +25 -25
  49. data/spec/rspec/core/option_parser_spec.rb +19 -1
  50. data/spec/rspec/core/project_initializer_spec.rb +4 -4
  51. data/spec/rspec/core/rake_task_spec.rb +25 -4
  52. data/spec/rspec/core/shared_context_spec.rb +4 -4
  53. data/spec/rspec/core/shared_example_group_spec.rb +1 -1
  54. data/spec/rspec/core_spec.rb +36 -2
  55. data/spec/spec_helper.rb +3 -0
  56. data/spec/support/helper_methods.rb +16 -1
  57. data/spec/support/shared_example_groups.rb +1 -0
  58. data/spec/support/silence_dsl_deprecations.rb +32 -0
  59. metadata +10 -7
  60. data/spec/rspec/core/formatters/text_mate_formatted-2.1.0.html +0 -425
@@ -6,18 +6,6 @@ module RSpec
6
6
  module Formatters
7
7
  # Formats backtraces so they're clickable by TextMate
8
8
  class TextMateFormatter < HtmlFormatter
9
- class NonEscapingHtmlPrinter < RSpec::Core::Formatters::HtmlPrinter
10
- def print_example_failed(pending_fixed, description, run_time, failure_id, exception, extra_content, escape_backtrace = false)
11
- # Call implementation from superclass, but ignore `escape_backtrace` and always pass `false` instead.
12
- super(pending_fixed, description, run_time, failure_id, exception, extra_content, false)
13
- end
14
- end
15
-
16
- def initialize(output)
17
- super
18
- @printer = NonEscapingHtmlPrinter.new(output)
19
- end
20
-
21
9
  def backtrace_line(line, skip_textmate_conversion=false)
22
10
  if skip_textmate_conversion
23
11
  super(line)
@@ -18,7 +18,7 @@ module RSpec
18
18
 
19
19
  class BeforeHook < Hook
20
20
  def run(example)
21
- example.instance_eval(&block)
21
+ example.instance_eval_with_args(example, &block)
22
22
  end
23
23
 
24
24
  def display_name
@@ -93,15 +93,12 @@ module RSpec
93
93
  # memoized hash when used in a `before(:all)` hook.
94
94
  #
95
95
  # @private
96
- class BeforeAllMemoizedHash
97
- def initialize(example_group_instance)
98
- @example_group_instance = example_group_instance
99
- @hash = {}
100
- end
96
+ class AllHookMemoizedHash
97
+ def self.isolate_for_all_hook(example_group_instance)
98
+ hash_type = self
101
99
 
102
- def self.isolate_for_before_all(example_group_instance)
103
100
  example_group_instance.instance_eval do
104
- @__memoized = BeforeAllMemoizedHash.new(self)
101
+ @__memoized = hash_type.new(example_group_instance)
105
102
 
106
103
  begin
107
104
  yield
@@ -112,6 +109,11 @@ module RSpec
112
109
  end
113
110
  end
114
111
 
112
+ def initialize(example_group_instance)
113
+ @example_group_instance = example_group_instance
114
+ @hash = {}
115
+ end
116
+
115
117
  def fetch(key, &block)
116
118
  description = if key == :subject
117
119
  "subject"
@@ -120,17 +122,16 @@ module RSpec
120
122
  end
121
123
 
122
124
  ::RSpec.warn_deprecation <<-EOS
123
- WARNING: #{description} accessed in a `before(:all)` hook at:
124
- #{caller[1]}
125
-
126
- This is deprecated behavior that will not be supported in RSpec 3.
125
+ DEPRECATION: #{description} accessed in #{article} #{hook_expression} hook at:
126
+ #{CallerFilter.first_non_rspec_line}
127
127
 
128
128
  `let` and `subject` declarations are not intended to be called
129
- in a `before(:all)` hook, as they exist to define state that
130
- is reset between each example, while `before(:all)` exists to
131
- define state that is shared across examples in an example group.
132
- EOS
129
+ in #{article} #{hook_expression} hook, as they exist to define state that
130
+ is reset between each example, while #{hook_expression} exists to
131
+ #{hook_intention}.
133
132
 
133
+ This is deprecated behavior that will not be supported in RSpec 3.
134
+ EOS
134
135
  @hash.fetch(key, &block)
135
136
  end
136
137
 
@@ -148,6 +149,34 @@ EOS
148
149
  end
149
150
  end
150
151
  end
152
+
153
+ class Before < self
154
+ def hook_expression
155
+ "`before(:all)`"
156
+ end
157
+
158
+ def article
159
+ "a"
160
+ end
161
+
162
+ def hook_intention
163
+ "define state that is shared across examples in an example group"
164
+ end
165
+ end
166
+
167
+ class After < self
168
+ def hook_expression
169
+ "`after(:all)`"
170
+ end
171
+
172
+ def article
173
+ "an"
174
+ end
175
+
176
+ def hook_intention
177
+ "cleanup state that is shared across examples in an example group"
178
+ end
179
+ end
151
180
  end
152
181
 
153
182
  def self.included(mod)
@@ -195,8 +224,10 @@ EOS
195
224
 
196
225
  # Apply the memoization. The method has been defined in an ancestor
197
226
  # module so we can use `super` here to get the value.
198
- define_method(name) do
199
- __memoized.fetch(name) { |k| __memoized[k] = super(&nil) }
227
+ if block.arity == 1
228
+ define_method(name) { __memoized.fetch(name) { |k| __memoized[k] = super(RSpec.current_example, &nil) } }
229
+ else
230
+ define_method(name) { __memoized.fetch(name) { |k| __memoized[k] = super(&nil) } }
200
231
  end
201
232
  end
202
233
 
@@ -424,6 +455,7 @@ EOS
424
455
  # its(:age) { should eq(25) }
425
456
  # end
426
457
  def its(attribute, &block)
458
+ RSpec.deprecate("Use of rspec-core's `its` method", :replacement => 'the rspec-its gem')
427
459
  describe(attribute) do
428
460
  if Array === attribute
429
461
  let(:__its_subject) { subject[*attribute] }
@@ -273,7 +273,7 @@ module RSpec
273
273
  RSpec reserves some hash keys for its own internal use,
274
274
  including :#{key}, which is used on:
275
275
 
276
- #{caller(0)[4]}.
276
+ #{CallerFilter.first_non_rspec_line}.
277
277
 
278
278
  Here are all of RSpec's reserved hash keys:
279
279
 
@@ -63,12 +63,17 @@ module RSpec::Core
63
63
  end
64
64
 
65
65
  parser.on('--order TYPE[:SEED]', 'Run examples by the specified order type.',
66
- ' [default] files are ordered based on the underlying file',
67
- ' system\'s order',
66
+ ' [defined] groups and examples are run in the order they are defined',
67
+ ' [default] deprecated alias for defined',
68
68
  ' [rand] randomize the order of files, groups and examples',
69
69
  ' [random] alias for rand',
70
70
  ' [random:SEED] e.g. --order random:123') do |o|
71
- options[:order] = o
71
+ options[:order] = if o == 'default'
72
+ RSpec.deprecate("RSpec's `--order default` CLI option", :replacement => "`--order defined`", :call_site => nil)
73
+ 'defined'
74
+ else
75
+ o
76
+ end
72
77
  end
73
78
 
74
79
  parser.on('--seed SEED', Integer, 'Equivalent of --order rand:SEED.') do |seed|
@@ -72,7 +72,7 @@ module RSpec
72
72
  # # ...
73
73
  # end
74
74
  def pending(*args)
75
- return self.class.before(:each) { pending(*args) } unless example
75
+ return self.class.before(:each) { pending(*args) } unless RSpec.current_example
76
76
 
77
77
  options = args.last.is_a?(Hash) ? args.pop : {}
78
78
  message = args.first || NO_REASON_GIVEN
@@ -81,24 +81,23 @@ module RSpec
81
81
  return block_given? ? yield : nil
82
82
  end
83
83
 
84
- example.metadata[:pending] = true
85
- example.metadata[:execution_result][:pending_message] = message
86
- example.execution_result[:pending_fixed] = false
84
+ RSpec.current_example.metadata[:pending] = true
85
+ RSpec.current_example.metadata[:execution_result][:pending_message] = message
86
+ RSpec.current_example.execution_result[:pending_fixed] = false
87
87
  if block_given?
88
88
  begin
89
89
  result = begin
90
90
  yield
91
- example.example_group_instance.instance_eval { verify_mocks_for_rspec }
92
- true
91
+ RSpec.current_example.example_group_instance.instance_eval { verify_mocks_for_rspec }
93
92
  end
94
- example.metadata[:pending] = false
93
+ RSpec.current_example.metadata[:pending] = false
95
94
  rescue Exception => e
96
- example.execution_result[:exception] = e
95
+ RSpec.current_example.execution_result[:exception] = e
97
96
  ensure
98
97
  teardown_mocks_for_rspec
99
98
  end
100
99
  if result
101
- example.execution_result[:pending_fixed] = true
100
+ RSpec.current_example.execution_result[:pending_fixed] = true
102
101
  raise PendingExampleFixedError.new
103
102
  end
104
103
  end
@@ -108,6 +107,11 @@ module RSpec
108
107
 
109
108
  # Alias the error for compatibility with extension gems (e.g. formatters)
110
109
  # that depend on the const name of the error in RSpec <= 2.8.
111
- PendingExampleFixedError = Pending::PendingExampleFixedError
110
+ def self.const_missing(name)
111
+ return super unless name == :PendingExampleFixedError
112
+
113
+ RSpec.deprecate("RSpec::Core::PendingExampleFixedError", :replacement => "RSpec::Core::Pending::PendingExampleFixedError")
114
+ Pending::PendingExampleFixedError
115
+ end
112
116
  end
113
117
  end
@@ -68,19 +68,43 @@ module RSpec
68
68
  #
69
69
  # default:
70
70
  # false
71
- attr_accessor :rcov
71
+ def rcov
72
+ deprecate("RSpec::Core::RakeTask#rcov")
73
+ @rcov
74
+ end
75
+
76
+ def rcov=(true_or_false)
77
+ deprecate("RSpec::Core::RakeTask#rcov=")
78
+ @rcov = true_or_false
79
+ end
72
80
 
73
81
  # Path to rcov.
74
82
  #
75
83
  # default:
76
84
  # 'rcov'
77
- attr_accessor :rcov_path
85
+ def rcov_path
86
+ deprecate("RSpec::Core::RakeTask#rcov_path")
87
+ @rcov_path
88
+ end
89
+
90
+ def rcov_path=(path)
91
+ deprecate("RSpec::Core::RakeTask#rcov_path=")
92
+ @rcov_path = path
93
+ end
78
94
 
79
95
  # Command line options to pass to rcov.
80
96
  #
81
97
  # default:
82
98
  # nil
83
- attr_accessor :rcov_opts
99
+ def rcov_opts
100
+ deprecate("RSpec::Core::RakeTask#rcov_opts")
101
+ @rcov_opts
102
+ end
103
+
104
+ def rcov_opts=(opts)
105
+ deprecate("RSpec::Core::RakeTask#rcov_opts=")
106
+ @rcov_opts = opts
107
+ end
84
108
 
85
109
  # Command line options to pass to ruby.
86
110
  #
@@ -174,15 +198,15 @@ module RSpec
174
198
  cmd_parts << ruby_opts
175
199
  cmd_parts << "-w" if @warning
176
200
  cmd_parts << "-S" << runner
177
- cmd_parts << "-Ispec:lib" << rcov_opts if rcov
201
+ cmd_parts << "-Ispec:lib" << @rcov_opts if @rcov
178
202
  cmd_parts << files_to_run
179
- cmd_parts << "--" if rcov && rspec_opts
203
+ cmd_parts << "--" if @rcov && rspec_opts
180
204
  cmd_parts << rspec_opts
181
205
  cmd_parts.flatten.reject(&blank).join(" ")
182
206
  end
183
207
 
184
208
  def runner
185
- rcov ? rcov_path : rspec_path
209
+ @rcov ? @rcov_path : rspec_path
186
210
  end
187
211
 
188
212
  def blank
@@ -68,6 +68,15 @@ module RSpec
68
68
  options = ConfigurationOptions.new(args)
69
69
  options.parse_options
70
70
 
71
+ major, minor, point = RUBY_VERSION.split('.').map { |v| v.to_i }
72
+
73
+ if major == 1 && ( (minor == 9 && point < 2) || (minor == 8 && point < 7) )
74
+ RSpec.deprecate "RSpec support for Ruby #{RUBY_VERSION}",
75
+ :replacement => "1.8.7 or >= 1.9.2",
76
+ :call_site => nil
77
+ end
78
+
79
+
71
80
  if options.options[:drb]
72
81
  require 'rspec/core/drb_command_line'
73
82
  begin
@@ -80,7 +80,7 @@ module RSpec
80
80
  # objects.
81
81
  class Registry
82
82
  def add_group(source, *args, &block)
83
- ensure_block_has_source_location(block, caller[1])
83
+ ensure_block_has_source_location(block, CallerFilter.first_non_rspec_line)
84
84
 
85
85
  if key? args.first
86
86
  key = args.shift
@@ -167,14 +167,16 @@ module RSpec
167
167
  shared_example_groups[source][key]
168
168
  end
169
169
 
170
- def ensure_block_has_source_location(block, caller_line)
171
- return if block.respond_to?(:source_location)
172
-
173
- block.extend Module.new {
174
- define_method :source_location do
175
- caller_line.split(':')
176
- end
177
- }
170
+ if Proc.method_defined?(:source_location)
171
+ def ensure_block_has_source_location(block, caller_line); end
172
+ else # for 1.8.7
173
+ def ensure_block_has_source_location(block, caller_line)
174
+ block.extend Module.new {
175
+ define_method :source_location do
176
+ caller_line.split(':')
177
+ end
178
+ }
179
+ end
178
180
  end
179
181
  end
180
182
  end
@@ -27,12 +27,14 @@ module RSpec
27
27
 
28
28
  def warn_deprecation_and_fetch_anyway(key)
29
29
  if (example = fetch_anyway key)
30
- backtrace_line = caller.find { |line| !line.include?('lib/rspec/core') }
30
+ backtrace_line = CallerFilter.first_non_rspec_line
31
+
31
32
  RSpec.warn_deprecation <<-WARNING.gsub(/^ /, '')
32
33
  Accessing shared_examples defined across contexts is deprecated.
33
34
  Please declare shared_examples within a shared context, or at the top level.
34
35
  This message was generated at: #{backtrace_line}
35
36
  WARNING
37
+
36
38
  example
37
39
  end
38
40
  end
@@ -1,8 +1,7 @@
1
1
  module RSpec
2
2
  module Core
3
3
  module Version
4
- STRING = '2.14.8'
4
+ STRING = '2.99.0.beta1'
5
5
  end
6
6
  end
7
7
  end
8
-
@@ -130,11 +130,11 @@ describe 'command line', :ui do
130
130
  end
131
131
  end
132
132
 
133
- describe '--order default on CLI with --order rand in .rspec' do
134
- it "overrides --order rand with --order default" do
133
+ describe '--order defined on CLI with --order rand in .rspec' do
134
+ it "overrides --order rand with --order defined" do
135
135
  write_file '.rspec', '--order rand'
136
136
 
137
- run_command 'tmp/aruba/spec/order_spec.rb --order default -f doc'
137
+ run_command 'tmp/aruba/spec/order_spec.rb --order defined -f doc'
138
138
 
139
139
  expect(stdout.string).not_to match(/Randomized/)
140
140
 
@@ -148,7 +148,7 @@ describe 'command line', :ui do
148
148
  before do
149
149
  write_file 'spec/custom_order_spec.rb', """
150
150
  RSpec.configure do |config|
151
- config.order_groups_and_examples do |list|
151
+ config.register_ordering(:global) do |list|
152
152
  list.sort_by { |item| item.description }
153
153
  end
154
154
  end
@@ -6,55 +6,55 @@ module RSpec::Core
6
6
  it "keeps all lines" do
7
7
  lines = ["/tmp/a_file", "some_random_text", "hello\330\271!"]
8
8
  cleaner = BacktraceCleaner.new([], [])
9
- expect(lines.all? {|line| cleaner.exclude? line}).to be_false
9
+ expect(lines.all? {|line| cleaner.exclude? line}).to be_falsey
10
10
  end
11
11
 
12
12
  it 'is considered a full backtrace' do
13
- expect(BacktraceCleaner.new([], []).full_backtrace?).to be_true
13
+ expect(BacktraceCleaner.new([], []).full_backtrace?).to be_truthy
14
14
  end
15
15
  end
16
16
 
17
17
  context "with an exclusion pattern but no inclusion patterns" do
18
18
  it "excludes lines that match the exclusion pattern" do
19
19
  cleaner = BacktraceCleaner.new([], [/remove/])
20
- expect(cleaner.exclude? "remove me").to be_true
20
+ expect(cleaner.exclude? "remove me").to be_truthy
21
21
  end
22
22
 
23
23
  it "keeps lines that do not match the exclusion pattern" do
24
24
  cleaner = BacktraceCleaner.new([], [/remove/])
25
- expect(cleaner.exclude? "apple").to be_false
25
+ expect(cleaner.exclude? "apple").to be_falsey
26
26
  end
27
27
 
28
28
  it 'is considered a partial backtrace' do
29
- expect(BacktraceCleaner.new([], [/remove/]).full_backtrace?).to be_false
29
+ expect(BacktraceCleaner.new([], [/remove/]).full_backtrace?).to be_falsey
30
30
  end
31
31
  end
32
32
 
33
33
  context "with an exclusion pattern and an inclusion pattern" do
34
34
  it "excludes lines that match the exclusion pattern but not the inclusion pattern" do
35
35
  cleaner = BacktraceCleaner.new([/keep/], [/discard/])
36
- expect(cleaner.exclude? "discard").to be_true
36
+ expect(cleaner.exclude? "discard").to be_truthy
37
37
  end
38
38
 
39
39
  it "keeps lines that match the inclusion pattern and the exclusion pattern" do
40
40
  cleaner = BacktraceCleaner.new([/hi/], [/.*/])
41
- expect(cleaner.exclude? "hi").to be_false
41
+ expect(cleaner.exclude? "hi").to be_falsey
42
42
  end
43
43
 
44
44
  it "keeps lines that match neither pattern" do
45
45
  cleaner = BacktraceCleaner.new([/hi/], [/delete/])
46
- expect(cleaner.exclude? "fish").to be_false
46
+ expect(cleaner.exclude? "fish").to be_falsey
47
47
  end
48
48
 
49
49
  it 'is considered a partial backtrace' do
50
- expect(BacktraceCleaner.new([], [/remove/]).full_backtrace?).to be_false
50
+ expect(BacktraceCleaner.new([], [/remove/]).full_backtrace?).to be_falsey
51
51
  end
52
52
  end
53
53
 
54
54
  context "with an exclusion pattern that matches the current working directory" do
55
55
  it "defaults to having one inclusion pattern, the current working directory" do
56
56
  cleaner = BacktraceCleaner.new(nil, [/.*/])
57
- expect(Dir.getwd =~ cleaner.inclusion_patterns.first).to be_true
57
+ expect(Dir.getwd =~ cleaner.inclusion_patterns.first).to be_truthy
58
58
  end
59
59
  end
60
60