rspec-core 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/Gemfile +16 -11
  2. data/History.markdown +22 -0
  3. data/License.txt +2 -1
  4. data/{README.markdown → README.md} +11 -3
  5. data/Rakefile +1 -0
  6. data/Upgrade.markdown +35 -2
  7. data/features/hooks/around_hooks.feature +18 -2
  8. data/lib/rspec/core/configuration.rb +38 -36
  9. data/lib/rspec/core/configuration_options.rb +2 -1
  10. data/lib/rspec/core/deprecation.rb +1 -1
  11. data/lib/rspec/core/example.rb +19 -9
  12. data/lib/rspec/core/example_group.rb +14 -26
  13. data/lib/rspec/core/extensions/kernel.rb +23 -3
  14. data/lib/rspec/core/formatters/base_text_formatter.rb +43 -30
  15. data/lib/rspec/core/formatters/documentation_formatter.rb +1 -1
  16. data/lib/rspec/core/formatters/html_formatter.rb +10 -8
  17. data/lib/rspec/core/hooks.rb +2 -2
  18. data/lib/rspec/core/metadata.rb +46 -34
  19. data/lib/rspec/core/option_parser.rb +2 -2
  20. data/lib/rspec/core/rake_task.rb +1 -1
  21. data/lib/rspec/core/ruby_project.rb +2 -2
  22. data/lib/rspec/core/runner.rb +2 -2
  23. data/lib/rspec/core/subject.rb +4 -3
  24. data/lib/rspec/core/version.rb +1 -1
  25. data/rspec-core.gemspec +1 -1
  26. data/spec/rspec/core/configuration_options_spec.rb +7 -5
  27. data/spec/rspec/core/configuration_spec.rb +58 -69
  28. data/spec/rspec/core/example_group_spec.rb +22 -7
  29. data/spec/rspec/core/example_spec.rb +1 -1
  30. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +2 -2
  31. data/spec/rspec/core/kernel_extensions_spec.rb +6 -3
  32. data/spec/rspec/core/metadata_spec.rb +13 -0
  33. data/spec/rspec/core/pending_example_spec.rb +1 -1
  34. data/spec/rspec/core/rake_task_spec.rb +2 -3
  35. data/spec/spec_helper.rb +1 -0
  36. metadata +9 -11
  37. data/.treasure_map.rb +0 -23
  38. data/specs.watchr +0 -58
data/Gemfile CHANGED
@@ -1,14 +1,18 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  %w[rspec-core rspec-expectations rspec-mocks].each do |lib|
4
- gem lib, :path => File.expand_path("../../#{lib}", __FILE__)
4
+ library_path = File.expand_path("../../#{lib}", __FILE__)
5
+ if File.exist?(library_path)
6
+ gem lib, :path => library_path
7
+ else
8
+ gem lib
9
+ end
5
10
  end
6
11
 
7
12
  gem "rake"
8
- gem "cucumber", "0.8.5"
13
+ gem "cucumber", "0.9.4"
9
14
  gem "aruba", "0.2.2"
10
15
  gem "autotest"
11
- gem "watchr"
12
16
  gem "rcov"
13
17
  gem "mocha"
14
18
  gem "rr"
@@ -18,14 +22,15 @@ gem "syntax"
18
22
  gem "relish", "~> 0.0.3"
19
23
  gem "guard-rspec"
20
24
  gem "growl"
21
- gem "rb-fsevent"
22
25
 
23
- unless RUBY_PLATFORM == "java"
26
+ gem "ruby-debug", :platforms => :ruby_18
27
+ gem "ruby-debug19", :platforms => :ruby_19
28
+
29
+ platforms :ruby_18, :ruby_19 do
30
+ gem "rb-fsevent"
24
31
  gem "ruby-prof"
25
- case RUBY_VERSION
26
- when /^1.9.2/
27
- gem "ruby-debug19"
28
- when /^1.8/
29
- gem "ruby-debug"
30
- end
32
+ end
33
+
34
+ platforms :jruby do
35
+ gem "jruby-openssl"
31
36
  end
data/History.markdown CHANGED
@@ -1,5 +1,27 @@
1
1
  ## rspec-core release history (incomplete)
2
2
 
3
+ ### 2.2.0 / 2010-11-28
4
+
5
+ [full changelog](http://github.com/rspec/rspec-core/compare/v2.1.0...v2.2.0)
6
+
7
+ * Deprecations/changes
8
+ * --debug/-d on command line is deprecated and now has no effect
9
+ * win32console is now ignored; Windows users must use ANSICON for color support
10
+ (Bosko Ivanisevic)
11
+
12
+ * Enhancements
13
+ * When developing locally rspec-core now works with the rspec-dev setup or your local gems
14
+ * Raise exception with helpful message when rspec-1 is loaded alongside
15
+ rspec-2 (Justin Ko)
16
+ * debugger statements _just work_ as long as ruby-debug is installed
17
+ * otherwise you get warned, but not fired
18
+ * Expose example.metadata in around hooks
19
+ * Performance improvments (see [Upgrade.markdown](https://github.com/rspec/rspec-core/blob/master/Upgrade.markdown))
20
+
21
+ * Bug fixes
22
+ * Make sure --fail-fast makes it across drb
23
+ * Pass -Ilib:spec to rcov
24
+
3
25
  ### 2.1.0 / 2010-11-07
4
26
 
5
27
  [full changelog](http://github.com/rspec/rspec-core/compare/v2.0.1...v2.1.0)
data/License.txt CHANGED
@@ -1,6 +1,7 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2009 David Chelimsky, Chad Humphries
3
+ Copyright (c) 2009 Chad Humphries, David Chelimsky
4
+ Copyright (c) 2005 The RSpec Development Team
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining
6
7
  a copy of this software and associated documentation files (the
@@ -4,8 +4,16 @@ Behaviour Driven Development for Ruby
4
4
 
5
5
  ## Documentation
6
6
 
7
- * [Cucumber features](http://relishapp.com/rspec/rspec-core/v/2-0)
8
- * [RDoc](http://rubydoc.info/gems/rspec-core/2.0.1/frames)
7
+ The [Cucumber features](http://relishapp.com/rspec/rspec-core/v/2-1) are the
8
+ most comprehensive and up-to-date docs for end-users.
9
+
10
+ The [RDoc](http://rubydoc.info/gems/rspec-core/2.1/frames) provides
11
+ additional information for contributors and/or extenders.
12
+
13
+ All of the documentation is open source and a work in progress. If you find it
14
+ lacking or confusing, you can help improve it by submitting requests and
15
+ patches to the [rspec-core issue
16
+ tracker](https://github.com/rspec/rspec-core/issues).
9
17
 
10
18
  ## Install
11
19
 
@@ -54,7 +62,7 @@ Be sure to require the implementation file in the spec:
54
62
  require "calculator"
55
63
 
56
64
  Now run the spec again, and watch it pass:
57
-
65
+
58
66
  $ rspec spec/calculator_spec.rb
59
67
  .
60
68
 
data/Rakefile CHANGED
@@ -22,6 +22,7 @@ desc "Run all examples"
22
22
  RSpec::Core::RakeTask.new(:spec) do |t|
23
23
  t.rspec_path = 'bin/rspec'
24
24
  t.rspec_opts = %w[--color]
25
+ t.verbose = false
25
26
  end
26
27
 
27
28
  Cucumber::Rake::Task.new(:cucumber)
data/Upgrade.markdown CHANGED
@@ -1,4 +1,37 @@
1
- # New features in rspec-core-2.1
1
+ # rspec-core-2.2 (in development)
2
+
3
+ ## FASTER!
4
+
5
+ Made several small optimizations that all add up to a considerable improvement
6
+ in performance. Using a simple benchmark:
7
+
8
+ generate 5000 example groups,
9
+ each with one example,
10
+ each with one passing expectation
11
+
12
+ Run using ruby-1.9.2 on Mac OS X w/ 3.06 G
13
+
14
+ * rspec-2.1
15
+ * loaded in 0.85 on avg
16
+ * ran in 2.61 on avg
17
+ * rspec-2.2
18
+ * loaded in 0.73 on avg (~15% improvement)
19
+ * ran in 0.94 on avg (~64% improvement**)
20
+
21
+ ** this does _not_ mean your suite will be 64% faster, but it does mean that
22
+ the overhead incurred by RSpec in your suite should be roughly 64% less.
23
+
24
+ ## Command line
25
+
26
+ ### --debug/-d is now deprecated
27
+
28
+ This command line option is now has no effect (other than a deprecation
29
+ warning). To use the debugger, just add a `debugger` statement anywhere in your
30
+ code. As long as you have ruby-debug installed, it will just work. If you
31
+ don't, then you'll get a friendly warning telling you what's going on, but
32
+ execution will continue.
33
+
34
+ # rspec-core-2.1
2
35
 
3
36
  ## Command line
4
37
 
@@ -61,7 +94,7 @@ JRuby installation to a newer release that allows the example to pass, RSpec
61
94
  will report it as a failure (`Expected pending '...' to fail. No Error was raised.`),
62
95
  so that know that you can remove the call to `pending`.
63
96
 
64
- # New features in rspec-core-2.0
97
+ # rspec-core-2.0
65
98
 
66
99
  ### Runner
67
100
 
@@ -9,7 +9,7 @@ Feature: around hooks
9
9
  example, if your database library offers a transaction method that receives
10
10
  a block, you can use an around hook as described in the first scenario:
11
11
 
12
- Scenario: use the example as a block within the block passed to around()
12
+ Scenario: use the example as a proc within the block passed to around()
13
13
  Given a file named "example_spec.rb" with:
14
14
  """
15
15
  class Database
@@ -41,7 +41,7 @@ Feature: around hooks
41
41
  Scenario: invoke the example using run()
42
42
  Given a file named "example_spec.rb" with:
43
43
  """
44
- describe "around filter" do
44
+ describe "around hook" do
45
45
  around(:each) do |example|
46
46
  puts "around each before"
47
47
  example.run
@@ -61,6 +61,22 @@ Feature: around hooks
61
61
  around each after
62
62
  """
63
63
 
64
+ Scenario: access the example metadata
65
+ Given a file named "example_spec.rb" with:
66
+ """
67
+ describe "something" do
68
+ around(:each) do |example|
69
+ puts example.metadata[:foo]
70
+ example.run
71
+ end
72
+
73
+ it "does something", :foo => "this should show up in the output" do
74
+ end
75
+ end
76
+ """
77
+ When I run "rspec example_spec.rb"
78
+ Then the output should contain "this should show up in the output"
79
+
64
80
  Scenario: define a global around hook
65
81
  Given a file named "example_spec.rb" with:
66
82
  """
@@ -13,7 +13,7 @@ module RSpec
13
13
  else
14
14
  define_method("#{name}=") {|val| settings[name] = val}
15
15
  define_method(name) { settings.has_key?(name) ? settings[name] : opts[:default] }
16
- define_method("#{name}?") { !!(send name) }
16
+ define_method("#{name}?") { send name }
17
17
  end
18
18
  end
19
19
 
@@ -34,7 +34,7 @@ module RSpec
34
34
  add_setting :files_to_run
35
35
  add_setting :include_or_extend_modules
36
36
  add_setting :backtrace_clean_patterns
37
- add_setting :autotest
37
+ add_setting :tty
38
38
 
39
39
  def initialize
40
40
  @color_enabled = false
@@ -68,7 +68,7 @@ module RSpec
68
68
  #
69
69
  # RSpec.configuration.foo=(value)
70
70
  # RSpec.configuration.foo()
71
- # RSpec.configuration.foo?() # returns !!foo
71
+ # RSpec.configuration.foo?() # returns true if foo returns anything but nil or false
72
72
  #
73
73
  # Intended for extension frameworks like rspec-rails, so they can add config
74
74
  # settings that are domain specific. For example:
@@ -149,25 +149,19 @@ module RSpec
149
149
  end
150
150
 
151
151
  def color_enabled
152
- @color_enabled && (output_to_tty? || autotest?)
152
+ @color_enabled && output_to_tty?
153
153
  end
154
154
 
155
155
  def color_enabled?
156
- !!color_enabled
156
+ color_enabled
157
157
  end
158
158
 
159
159
  def color_enabled=(bool)
160
160
  return unless bool
161
161
  @color_enabled = true
162
162
  if bool && ::RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
163
- using_stdout = settings[:output_stream] == $stdout
164
- using_stderr = settings[:error_stream] == $stderr
165
- begin
166
- require 'Win32/Console/ANSI'
167
- settings[:output_stream] = $stdout if using_stdout
168
- settings[:error_stream] = $stderr if using_stderr
169
- rescue LoadError
170
- warn "You must 'gem install win32console' to use colour on Windows"
163
+ unless ENV['ANSICON']
164
+ warn "You must use ANSICON 1.31 or later (http://adoxa.110mb.com/ansicon/) to use colour on Windows"
171
165
  @color_enabled = false
172
166
  end
173
167
  end
@@ -182,21 +176,11 @@ module RSpec
182
176
  end
183
177
 
184
178
  def debug=(bool)
185
- return unless bool
186
- begin
187
- require 'ruby-debug'
188
- rescue LoadError
189
- raise <<-EOM
190
-
191
- #{'*'*50}
192
- You must install ruby-debug to run rspec with the --debug option.
193
-
194
- If you have ruby-debug installed as a ruby gem, then you need to either
195
- require 'rubygems' or configure the RUBYOPT environment variable with
196
- the value 'rubygems'.
197
- #{'*'*50}
198
- EOM
199
- end
179
+ RSpec.warn_deprecation <<-WARNING
180
+ The debug option (config.debug = true or --debug/-d on the command line)
181
+ is deprecated and no longer has any effect. This message will be removed
182
+ from future versions of RSpec.
183
+ WARNING
200
184
  end
201
185
 
202
186
  def line_number=(line_number)
@@ -217,7 +201,7 @@ EOM
217
201
  end
218
202
 
219
203
  def formatter=(formatter_to_use)
220
- self.formatter_class =
204
+ self.formatter_class =
221
205
  built_in_formatter(formatter_to_use) ||
222
206
  custom_formatter(formatter_to_use) ||
223
207
  (raise ArgumentError, "Formatter '#{formatter_to_use}' unknown - maybe you meant 'documentation' or 'progress'?.")
@@ -308,14 +292,13 @@ EOM
308
292
 
309
293
  def configure_group(group)
310
294
  modules = {
311
- :include => [] + group.included_modules,
312
- :extend => [] + group.ancestors
295
+ :include => group.included_modules.dup,
296
+ :extend => group.ancestors.dup
313
297
  }
314
298
 
315
299
  include_or_extend_modules.each do |include_or_extend, mod, filters|
316
- next unless group.apply?(:all?, filters)
317
- next if modules[include_or_extend].include?(mod)
318
- modules[include_or_extend] << mod
300
+ next unless filters.empty? || group.apply?(:any?, filters)
301
+ next if self.class < mod
319
302
  group.send(include_or_extend, mod)
320
303
  end
321
304
  end
@@ -332,13 +315,32 @@ EOM
332
315
 
333
316
  def load_spec_files
334
317
  files_to_run.map {|f| load File.expand_path(f) }
318
+ raise_if_rspec_1_is_loaded
319
+ end
320
+
321
+ private
322
+
323
+ def raise_if_rspec_1_is_loaded
324
+ if defined?(Spec) && defined?(Spec::VERSION::MAJOR) && Spec::VERSION::MAJOR == 1
325
+ raise <<-MESSAGE
326
+
327
+ #{'*'*80}
328
+ You are running rspec-2, but it seems as though rspec-1 has been loaded as
329
+ well. This is likely due to a statement like this somewhere in the specs:
330
+
331
+ require 'spec'
332
+
333
+ Please locate that statement, remove it, and try again.
334
+ #{'*'*80}
335
+ MESSAGE
336
+ end
335
337
  end
336
338
 
337
339
  private
338
340
 
339
341
  def output_to_tty?
340
342
  begin
341
- settings[:output_stream].tty?
343
+ output_stream.tty? || tty?
342
344
  rescue NoMethodError
343
345
  false
344
346
  end
@@ -383,7 +385,7 @@ EOM
383
385
  end
384
386
 
385
387
  def underscore_with_fix_for_non_standard_rspec_naming(string)
386
- underscore(string).sub(%r{(^|/)r_spec($|/)}, '\\1rspec\\2')
388
+ underscore(string).sub(%r{(^|/)r_spec($|/)}, '\\1rspec\\2')
387
389
  end
388
390
 
389
391
  # activesupport/lib/active_support/inflector/methods.rb, line 48
@@ -28,7 +28,8 @@ module RSpec
28
28
  argv << "--color" if options[:color_enabled]
29
29
  argv << "--profile" if options[:profile_examples]
30
30
  argv << "--backtrace" if options[:full_backtrace]
31
- argv << "--autotest" if options[:autotest]
31
+ argv << "--tty" if options[:tty]
32
+ argv << "--fail-fast" if options[:fail_fast]
32
33
  argv << "--format" << options[:formatter] if options[:formatter]
33
34
  argv << "--line_number" << options[:line_number] if options[:line_number]
34
35
  argv << "--example" << options[:full_description].source if options[:full_description]
@@ -31,7 +31,7 @@ ADDITIONAL
31
31
 
32
32
  class HashWithDeprecationNotice < Hash
33
33
 
34
- def initialize(method, alternate_method=nil, &block)
34
+ def initialize(method, alternate_method=nil)
35
35
  @method, @alternate_method = method, alternate_method
36
36
  end
37
37
 
@@ -10,7 +10,7 @@ module RSpec
10
10
  end
11
11
  end
12
12
 
13
- delegate_to_metadata :description, :full_description, :execution_result, :file_path, :pending
13
+ delegate_to_metadata :description, :full_description, :execution_result, :file_path, :pending, :location
14
14
 
15
15
  def initialize(example_group_class, desc, options, example_block=nil)
16
16
  @example_group_class, @options, @example_block = example_group_class, options, example_block
@@ -23,9 +23,7 @@ module RSpec
23
23
  @example_group_class
24
24
  end
25
25
 
26
- def pending?
27
- !!pending
28
- end
26
+ alias_method :pending?, :pending
29
27
 
30
28
  def run(example_group_instance, reporter)
31
29
  @example_group_instance = example_group_instance
@@ -68,17 +66,29 @@ module RSpec
68
66
  finish(reporter)
69
67
  end
70
68
 
69
+ class Procsy < Proc
70
+ attr_reader :metadata
71
+ alias_method :run, :call
72
+ def initialize(metadata)
73
+ @metadata = metadata
74
+ end
75
+ end
76
+
71
77
  private
72
78
 
73
- def with_pending_capture(&block)
79
+ def with_pending_capture
74
80
  @pending_declared_in_example = catch(:pending_declared_in_example) do
75
- block.call
81
+ yield
76
82
  throw :pending_declared_in_example, false
77
83
  end
78
84
  end
79
85
 
80
- def with_around_hooks(&wrapped_example)
81
- @example_group_class.eval_around_eachs(@example_group_instance, wrapped_example).call
86
+ def with_around_hooks
87
+ if @example_group_class.around_hooks.empty?
88
+ yield
89
+ else
90
+ @example_group_class.eval_around_eachs(@example_group_instance, Procsy.new(metadata)).call
91
+ end
82
92
  end
83
93
 
84
94
  def start(reporter)
@@ -88,7 +98,7 @@ module RSpec
88
98
 
89
99
  def finish(reporter)
90
100
  if @exception
91
- record_finished 'failed', :exception_encountered => @exception
101
+ record_finished 'failed', :exception => @exception
92
102
  reporter.example_failed self
93
103
  false
94
104
  elsif @pending_declared_in_example
@@ -177,10 +177,11 @@ module RSpec
177
177
  store_before_all_ivars(example_group_instance)
178
178
  end
179
179
 
180
- def self.eval_around_eachs(example_group_instance, wrapped_example)
181
- around_hooks.reverse.inject(wrapped_example) do |wrapper, hook|
182
- def wrapper.run; call; end
183
- lambda { example_group_instance.instance_eval_with_args(wrapper, &hook) }
180
+ def self.eval_around_eachs(example_group_instance, procsy)
181
+ around_hooks.reverse.inject(procsy) do |procsy, around_hook|
182
+ Example::Procsy.new(procsy.metadata) do
183
+ example_group_instance.instance_eval_with_args(procsy, &around_hook)
184
+ end
184
185
  end
185
186
  end
186
187
 
@@ -223,18 +224,17 @@ An error occurred in an after(:all) hook.
223
224
  RSpec.clear_remaining_example_groups if top_level?
224
225
  return
225
226
  end
226
- example_group_instance = new
227
227
  reporter.example_group_started(self)
228
228
 
229
229
  begin
230
- eval_before_alls(example_group_instance)
231
- result_for_this_group = run_examples(example_group_instance, reporter)
230
+ eval_before_alls(new)
231
+ result_for_this_group = run_examples(reporter)
232
232
  results_for_descendants = children.map {|child| child.run(reporter)}.all?
233
233
  result_for_this_group && results_for_descendants
234
234
  rescue Exception => ex
235
235
  fail_filtered_examples(ex, reporter)
236
236
  ensure
237
- eval_after_alls(example_group_instance)
237
+ eval_after_alls(new)
238
238
  reporter.example_group_finished(self)
239
239
  end
240
240
  end
@@ -253,18 +253,14 @@ An error occurred in an after(:all) hook.
253
253
  RSpec.configuration.fail_fast?
254
254
  end
255
255
 
256
- def self.run_examples(instance, reporter)
256
+ def self.run_examples(reporter)
257
257
  filtered_examples.map do |example|
258
258
  next if RSpec.wants_to_quit
259
- begin
260
- set_ivars(instance, before_all_ivars)
261
- succeeded = example.run(instance, reporter)
262
- RSpec.wants_to_quit = true if fail_fast? && !succeeded
263
- succeeded
264
- ensure
265
- clear_ivars(instance)
266
- clear_memoized(instance)
267
- end
259
+ instance = new
260
+ set_ivars(instance, before_all_ivars)
261
+ succeeded = example.run(instance, reporter)
262
+ RSpec.wants_to_quit = true if fail_fast? && !succeeded
263
+ succeeded
268
264
  end.all?
269
265
  end
270
266
 
@@ -286,14 +282,6 @@ An error occurred in an after(:all) hook.
286
282
  ivars.each {|name, value| instance.instance_variable_set(name, value)}
287
283
  end
288
284
 
289
- def self.clear_ivars(instance)
290
- instance.instance_variables.each { |ivar| instance.send(:remove_instance_variable, ivar) }
291
- end
292
-
293
- def self.clear_memoized(instance)
294
- instance.__memoized.clear
295
- end
296
-
297
285
  def described_class
298
286
  self.class.described_class
299
287
  end