rspec-core 3.0.0.beta1 → 3.0.0.beta2

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 (145) hide show
  1. data.tar.gz.sig +0 -0
  2. data/Changelog.md +137 -0
  3. data/README.md +2 -2
  4. data/exe/rspec +2 -23
  5. data/features/README.md +1 -5
  6. data/features/command_line/README.md +7 -10
  7. data/features/command_line/exit_status.feature +1 -1
  8. data/features/command_line/format_option.feature +1 -1
  9. data/features/command_line/init.feature +40 -1
  10. data/features/command_line/line_number_option.feature +2 -2
  11. data/features/command_line/ruby.feature +5 -4
  12. data/features/configuration/enable_global_dsl.feature +54 -0
  13. data/features/example_groups/aliasing.feature +48 -0
  14. data/features/example_groups/basic_structure.feature +1 -1
  15. data/features/expectation_framework_integration/configure_expectation_framework.feature +1 -1
  16. data/features/filtering/if_and_unless.feature +0 -30
  17. data/features/formatters/custom_formatter.feature +32 -0
  18. data/features/formatters/regression_tests.feature +95 -0
  19. data/features/hooks/around_hooks.feature +1 -0
  20. data/features/hooks/before_and_after_hooks.feature +2 -2
  21. data/features/mock_framework_integration/use_flexmock.feature +11 -13
  22. data/features/mock_framework_integration/use_mocha.feature +11 -13
  23. data/features/mock_framework_integration/use_rr.feature +11 -13
  24. data/features/mock_framework_integration/use_rspec.feature +11 -13
  25. data/features/pending_and_skipped_examples/README.md +3 -0
  26. data/features/pending_and_skipped_examples/pending_examples.feature +118 -0
  27. data/features/pending_and_skipped_examples/skipped_examples.feature +106 -0
  28. data/features/step_definitions/additional_cli_steps.rb +34 -0
  29. data/features/subject/explicit_subject.feature +1 -1
  30. data/features/subject/one_liner_syntax.feature +71 -0
  31. data/lib/rspec/core.rb +6 -14
  32. data/lib/rspec/core/backtrace_formatter.rb +16 -4
  33. data/lib/rspec/core/command_line.rb +2 -3
  34. data/lib/rspec/core/configuration.rb +114 -125
  35. data/lib/rspec/core/configuration_options.rb +32 -18
  36. data/lib/rspec/core/dsl.rb +80 -18
  37. data/lib/rspec/core/example.rb +84 -33
  38. data/lib/rspec/core/example_group.rb +95 -43
  39. data/lib/rspec/core/filter_manager.rb +31 -40
  40. data/lib/rspec/core/formatters.rb +137 -0
  41. data/lib/rspec/core/formatters/base_formatter.rb +28 -41
  42. data/lib/rspec/core/formatters/base_text_formatter.rb +26 -37
  43. data/lib/rspec/core/formatters/deprecation_formatter.rb +48 -27
  44. data/lib/rspec/core/formatters/documentation_formatter.rb +27 -22
  45. data/lib/rspec/core/formatters/html_formatter.rb +48 -56
  46. data/lib/rspec/core/formatters/html_printer.rb +11 -18
  47. data/lib/rspec/core/formatters/json_formatter.rb +18 -22
  48. data/lib/rspec/core/formatters/legacy_formatter.rb +227 -0
  49. data/lib/rspec/core/formatters/progress_formatter.rb +7 -10
  50. data/lib/rspec/core/hooks.rb +250 -217
  51. data/lib/rspec/core/memoized_helpers.rb +43 -9
  52. data/lib/rspec/core/mocking_adapters/flexmock.rb +29 -0
  53. data/lib/rspec/core/{mocking/with_mocha.rb → mocking_adapters/mocha.rb} +19 -16
  54. data/lib/rspec/core/mocking_adapters/null.rb +12 -0
  55. data/lib/rspec/core/mocking_adapters/rr.rb +28 -0
  56. data/lib/rspec/core/mocking_adapters/rspec.rb +30 -0
  57. data/lib/rspec/core/notifications.rb +100 -0
  58. data/lib/rspec/core/option_parser.rb +11 -18
  59. data/lib/rspec/core/pending.rb +78 -47
  60. data/lib/rspec/core/project_initializer.rb +2 -49
  61. data/lib/rspec/core/project_initializer/dot_rspec +3 -0
  62. data/lib/rspec/core/project_initializer/spec_helper.rb +82 -0
  63. data/lib/rspec/core/rake_task.rb +5 -14
  64. data/lib/rspec/core/reporter.rb +24 -32
  65. data/lib/rspec/core/ruby_project.rb +1 -1
  66. data/lib/rspec/core/runner.rb +14 -4
  67. data/lib/rspec/core/shared_example_group.rb +40 -13
  68. data/lib/rspec/core/version.rb +1 -1
  69. data/spec/command_line/order_spec.rb +15 -15
  70. data/spec/rspec/core/backtrace_formatter_spec.rb +15 -1
  71. data/spec/rspec/core/command_line_spec.rb +18 -17
  72. data/spec/rspec/core/configuration_options_spec.rb +57 -34
  73. data/spec/rspec/core/configuration_spec.rb +162 -184
  74. data/spec/rspec/core/drb_command_line_spec.rb +5 -7
  75. data/spec/rspec/core/drb_options_spec.rb +2 -2
  76. data/spec/rspec/core/dsl_spec.rb +79 -15
  77. data/spec/rspec/core/example_group_spec.rb +253 -39
  78. data/spec/rspec/core/example_spec.rb +149 -33
  79. data/spec/rspec/core/filter_manager_spec.rb +9 -26
  80. data/spec/rspec/core/formatters/base_formatter_spec.rb +2 -5
  81. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +42 -145
  82. data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +64 -34
  83. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +15 -28
  84. data/spec/rspec/core/formatters/helpers_spec.rb +2 -2
  85. data/spec/rspec/core/formatters/{html_formatted-1.8.7.html → html_formatted-2.1.0.html} +22 -44
  86. data/spec/rspec/core/formatters/{html_formatted-1.8.7-jruby.html → html_formatted.html} +30 -49
  87. data/spec/rspec/core/formatters/html_formatter_spec.rb +35 -19
  88. data/spec/rspec/core/formatters/json_formatter_spec.rb +42 -40
  89. data/spec/rspec/core/formatters/legacy_formatter_spec.rb +137 -0
  90. data/spec/rspec/core/formatters/progress_formatter_spec.rb +38 -25
  91. data/spec/rspec/core/formatters/snippet_extractor_spec.rb +1 -1
  92. data/spec/rspec/core/formatters_spec.rb +120 -0
  93. data/spec/rspec/core/hooks_filtering_spec.rb +1 -1
  94. data/spec/rspec/core/hooks_spec.rb +13 -2
  95. data/spec/rspec/core/memoized_helpers_spec.rb +17 -8
  96. data/spec/rspec/core/metadata_spec.rb +3 -3
  97. data/spec/rspec/core/option_parser_spec.rb +53 -46
  98. data/spec/rspec/core/ordering_spec.rb +4 -4
  99. data/spec/rspec/core/pending_example_spec.rb +23 -126
  100. data/spec/rspec/core/pending_spec.rb +8 -0
  101. data/spec/rspec/core/project_initializer_spec.rb +8 -41
  102. data/spec/rspec/core/rake_task_spec.rb +15 -4
  103. data/spec/rspec/core/random_spec.rb +1 -1
  104. data/spec/rspec/core/reporter_spec.rb +50 -37
  105. data/spec/rspec/core/resources/formatter_specs.rb +9 -11
  106. data/spec/rspec/core/rspec_matchers_spec.rb +1 -1
  107. data/spec/rspec/core/ruby_project_spec.rb +3 -3
  108. data/spec/rspec/core/runner_spec.rb +65 -23
  109. data/spec/rspec/core/shared_context_spec.rb +4 -4
  110. data/spec/rspec/core/shared_example_group/collection_spec.rb +1 -1
  111. data/spec/rspec/core/shared_example_group_spec.rb +20 -11
  112. data/spec/rspec/core/warnings_spec.rb +1 -1
  113. data/spec/rspec/core/world_spec.rb +10 -10
  114. data/spec/rspec/core_spec.rb +2 -2
  115. data/spec/spec_helper.rb +12 -24
  116. data/spec/support/config_options_helper.rb +1 -3
  117. data/spec/support/formatter_support.rb +83 -0
  118. data/spec/support/isolate_load_path_mutation.rb +1 -2
  119. data/spec/support/isolated_directory.rb +1 -1
  120. data/spec/support/isolated_home_directory.rb +1 -1
  121. data/spec/support/legacy_formatter_using_sub_classing_example.rb +87 -0
  122. data/spec/support/matchers.rb +20 -0
  123. data/spec/support/mathn_integration_support.rb +2 -2
  124. data/spec/support/old_style_formatter_example.rb +69 -0
  125. data/spec/support/shared_example_groups.rb +1 -1
  126. data/spec/support/spec_files.rb +3 -3
  127. metadata +192 -69
  128. metadata.gz.sig +3 -1
  129. checksums.yaml +0 -15
  130. checksums.yaml.gz.sig +0 -2
  131. data/features/configuration/show_failures_in_pending_blocks.feature +0 -61
  132. data/features/pending/pending_examples.feature +0 -229
  133. data/features/subject/implicit_receiver.feature +0 -29
  134. data/lib/rspec/core/mocking/with_absolutely_nothing.rb +0 -11
  135. data/lib/rspec/core/mocking/with_flexmock.rb +0 -27
  136. data/lib/rspec/core/mocking/with_rr.rb +0 -27
  137. data/lib/rspec/core/mocking/with_rspec.rb +0 -27
  138. data/spec/rspec/core/formatters/html_formatted-1.8.7-rbx.html +0 -477
  139. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +0 -425
  140. data/spec/rspec/core/formatters/html_formatted-1.9.3-jruby.html +0 -416
  141. data/spec/rspec/core/formatters/html_formatted-1.9.3-rbx.html +0 -477
  142. data/spec/rspec/core/formatters/html_formatted-1.9.3.html +0 -419
  143. data/spec/rspec/core/formatters/html_formatted-2.0.0.html +0 -425
  144. data/spec/support/in_sub_process.rb +0 -37
  145. data/spec/support/sandboxed_mock_space.rb +0 -100
@@ -1,18 +1,9 @@
1
1
  module RSpec
2
2
  module Core
3
3
  class ProjectInitializer
4
- def initialize(arg=nil)
5
- @arg = arg
6
- end
7
-
8
4
  def run
9
5
  create_spec_helper_file
10
6
  create_dot_rspec_file
11
-
12
- delete_if_confirmed("lib/tasks/rspec.rake", <<-MESSAGE)
13
- If the file in lib/tasks/rspec.rake is the one generated by rspec-rails-1x,
14
- you can get rid of it, as it is no longer needed with rspec-2.
15
- MESSAGE
16
7
  end
17
8
 
18
9
  def create_dot_rspec_file
@@ -21,10 +12,7 @@ module RSpec
21
12
  else
22
13
  report_creating('.rspec')
23
14
  File.open('.rspec','w') do |f|
24
- f.write <<-CONTENT
25
- --color
26
- --format progress
27
- CONTENT
15
+ f.write File.read(File.expand_path("../project_initializer/dot_rspec", __FILE__))
28
16
  end
29
17
  end
30
18
  end
@@ -36,45 +24,11 @@ CONTENT
36
24
  report_creating('spec/spec_helper.rb')
37
25
  FileUtils.mkdir_p('spec')
38
26
  File.open('spec/spec_helper.rb','w') do |f|
39
- f.write <<-CONTENT
40
- # This file was generated by the `rspec --init` command. Conventionally, all
41
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
42
- # Require this file using `require "spec_helper"` to ensure that it is only
43
- # loaded once.
44
- #
45
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
46
- RSpec.configure do |config|
47
- # Limit the spec run to only specs with the focus metadata. If no specs have
48
- # the filtering metadata and `run_all_when_everything_filtered = true` then
49
- # all specs will run.
50
- #config.filter_run :focus
51
-
52
- # Run all specs when none match the provided filter. This works well in
53
- # conjunction with `config.filter_run :focus`, as it will run the entire
54
- # suite when no specs have `:filter` metadata.
55
- #config.run_all_when_everything_filtered = true
56
-
57
- # Run specs in random order to surface order dependencies. If you find an
58
- # order dependency and want to debug it, you can fix the order by providing
59
- # the seed, which is printed after each run.
60
- # --seed 1234
61
- #config.order = 'random'
62
- end
63
- CONTENT
27
+ f.write File.read(File.expand_path("../project_initializer/spec_helper.rb", __FILE__))
64
28
  end
65
29
  end
66
30
  end
67
31
 
68
- def delete_if_confirmed(path, message)
69
- if File.exist?(path)
70
- puts
71
- puts message
72
- puts
73
- puts " delete #{path}? [y/n]"
74
- FileUtils.rm_rf(path) if gets =~ /y/i
75
- end
76
- end
77
-
78
32
  def report_exists(file)
79
33
  puts " exist #{file}"
80
34
  end
@@ -82,7 +36,6 @@ CONTENT
82
36
  def report_creating(file)
83
37
  puts " create #{file}"
84
38
  end
85
-
86
39
  end
87
40
  end
88
41
  end
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
@@ -0,0 +1,82 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # (such as loading up an entire rails app) will add to the boot time of your
9
+ # test suite on EVERY test run, even for an individual file that may not need
10
+ # all of that loaded.
11
+ #
12
+ # The `.rspec` file also contains a few flags that are not defaults but that
13
+ # users commonly want.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+ RSpec.configure do |config|
17
+ # The settings below are suggested to provide a good initial experience
18
+ # with RSpec, but feel free to customize to your heart's content.
19
+ =begin
20
+ # These two settings work together to allow you to limit a spec run
21
+ # to individual examples or groups you care about by tagging them with
22
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
23
+ # get run.
24
+ config.filter_run :focus
25
+ config.run_all_when_everything_filtered = true
26
+
27
+ # Many RSpec users commonly either run the entire suite or an individual
28
+ # file, and it's useful to allow more verbose output when running an
29
+ # individual spec file.
30
+ if config.files_to_run.one?
31
+ # RSpec filters the backtrace by default so as not to be so noisy.
32
+ # This causes the full backtrace to be printed when running a single
33
+ # spec file (e.g. to troubleshoot a particular spec failure).
34
+ config.full_backtrace = true
35
+
36
+ # Use the documentation formatter for detailed output,
37
+ # unless a formatter has already been configured
38
+ # (e.g. via a command-line flag).
39
+ config.formatter = 'doc' if config.formatters.none?
40
+ end
41
+
42
+ # Print the 10 slowest examples and example groups at the
43
+ # end of the spec run, to help surface which specs are running
44
+ # particularly slow.
45
+ config.profile_examples = 10
46
+
47
+ # Run specs in random order to surface order dependencies. If you find an
48
+ # order dependency and want to debug it, you can fix the order by providing
49
+ # the seed, which is printed after each run.
50
+ # --seed 1234
51
+ config.order = :random
52
+
53
+ # Seed global randomization in this process using the `--seed` CLI option.
54
+ # Setting this allows you to use `--seed` to deterministically reproduce
55
+ # test failures related to randomization by passing the same `--seed` value
56
+ # as the one that triggered the failure.
57
+ Kernel.srand config.seed
58
+
59
+ # rspec-expectations config goes here. You can use an alternate
60
+ # assertion/expectation library such as wrong or the stdlib/minitest
61
+ # assertions if you prefer.
62
+ config.expect_with :rspec do |expectations|
63
+ # Enable only the newer, non-monkey-patching expect syntax.
64
+ # For more details, see:
65
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
66
+ expectations.syntax = :expect
67
+ end
68
+
69
+ # rspec-mocks config goes here. You can use an alternate test double
70
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
71
+ config.mock_with :rspec do |mocks|
72
+ # Enable only the newer, non-monkey-patching expect syntax.
73
+ # For more details, see:
74
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
75
+ mocks.syntax = :expect
76
+
77
+ # Prevents you from mocking or stubbing a method that does not exist on
78
+ # a real object. This is generally recommended.
79
+ mocks.verify_partial_doubles = true
80
+ end
81
+ =end
82
+ end
@@ -54,25 +54,13 @@ module RSpec
54
54
  # nil
55
55
  attr_accessor :rspec_opts
56
56
 
57
- # @deprecated
58
- # Use rspec_opts instead.
59
- #
60
- # Command line options to pass to rspec.
61
- #
62
- # default:
63
- # nil
64
- def spec_opts=(opts)
65
- RSpec.deprecate('RSpec::Core::RakeTask#spec_opts=', :replacement => 'rspec_opts=')
66
- @rspec_opts = opts
67
- end
68
-
69
57
  def initialize(*args, &task_block)
70
58
  setup_ivars(args)
71
59
 
72
60
  desc "Run RSpec code examples" unless ::Rake.application.last_comment
73
61
 
74
62
  task name, *args do |_, task_args|
75
- RakeFileUtils.send(:verbose, verbose) do
63
+ RakeFileUtils.__send__(:verbose, verbose) do
76
64
  task_block.call(*[self, task_args].slice(0, task_block.arity)) if task_block
77
65
  run_task verbose
78
66
  end
@@ -97,7 +85,10 @@ module RSpec
97
85
  rescue
98
86
  puts failure_message if failure_message
99
87
  end
100
- abort("#{command} failed") if fail_on_error unless success
88
+ if fail_on_error && !success
89
+ $stderr.puts "#{command} failed"
90
+ exit $?.exitstatus
91
+ end
101
92
  end
102
93
 
103
94
  private
@@ -1,15 +1,9 @@
1
1
  module RSpec::Core
2
2
  class Reporter
3
- NOTIFICATIONS = %W[start message example_group_started example_group_finished example_started
4
- example_passed example_failed example_pending start_dump dump_pending
5
- dump_failures dump_summary seed close stop deprecation deprecation_summary].map(&:to_sym)
6
3
 
7
- def initialize(configuration, *formatters)
4
+ def initialize(configuration)
8
5
  @configuration = configuration
9
- @listeners = Hash.new { |h,k| h[k] = [] }
10
- formatters.each do |formatter|
11
- register_listener(formatter, *NOTIFICATIONS)
12
- end
6
+ @listeners = Hash.new { |h,k| h[k] = Set.new }
13
7
  @example_count = @failure_count = @pending_count = 0
14
8
  @duration = @start = nil
15
9
  end
@@ -22,13 +16,13 @@ module RSpec::Core
22
16
  # events to all registered listeners
23
17
  def register_listener(listener, *notifications)
24
18
  notifications.each do |notification|
25
- @listeners[notification.to_sym] << listener if listener.respond_to?(notification)
19
+ @listeners[notification.to_sym] << listener
26
20
  end
27
21
  true
28
22
  end
29
23
 
30
24
  def registered_listeners(notification)
31
- @listeners[notification]
25
+ @listeners[notification].to_a
32
26
  end
33
27
 
34
28
  # @api
@@ -58,68 +52,66 @@ module RSpec::Core
58
52
 
59
53
  def start(expected_example_count)
60
54
  @start = RSpec::Core::Time.now
61
- notify :start, expected_example_count
55
+ notify :start, Notifications::CountNotification.new(expected_example_count)
62
56
  end
63
57
 
64
58
  def message(message)
65
- notify :message, message
59
+ notify :message, Notifications::MessageNotification.new(message)
66
60
  end
67
61
 
68
62
  def example_group_started(group)
69
- notify :example_group_started, group unless group.descendant_filtered_examples.empty?
63
+ notify :example_group_started, Notifications::GroupNotification.new(group) unless group.descendant_filtered_examples.empty?
70
64
  end
71
65
 
72
66
  def example_group_finished(group)
73
- notify :example_group_finished, group unless group.descendant_filtered_examples.empty?
67
+ notify :example_group_finished, Notifications::GroupNotification.new(group) unless group.descendant_filtered_examples.empty?
74
68
  end
75
69
 
76
70
  def example_started(example)
77
71
  @example_count += 1
78
- notify :example_started, example
72
+ notify :example_started, Notifications::ExampleNotification.new(example)
79
73
  end
80
74
 
81
75
  def example_passed(example)
82
- notify :example_passed, example
76
+ notify :example_passed, Notifications::ExampleNotification.new(example)
83
77
  end
84
78
 
85
79
  def example_failed(example)
86
80
  @failure_count += 1
87
- notify :example_failed, example
81
+ notify :example_failed, Notifications::ExampleNotification.new(example)
88
82
  end
89
83
 
90
84
  def example_pending(example)
91
85
  @pending_count += 1
92
- notify :example_pending, example
86
+ notify :example_pending, Notifications::ExampleNotification.new(example)
93
87
  end
94
88
 
95
- def deprecation(message)
96
- notify :deprecation, message
89
+ def deprecation(hash)
90
+ notify :deprecation, Notifications::DeprecationNotification.from_hash(hash)
97
91
  end
98
92
 
99
93
  def finish
100
94
  begin
101
95
  stop
102
- notify :start_dump
103
- notify :dump_pending
104
- notify :dump_failures
105
- notify :dump_summary, @duration, @example_count, @failure_count, @pending_count
106
- notify :deprecation_summary
107
- notify :seed, @configuration.seed if seed_used?
96
+ notify :start_dump, Notifications::NullNotification
97
+ notify :dump_pending, Notifications::NullNotification
98
+ notify :dump_failures, Notifications::NullNotification
99
+ notify :dump_summary, Notifications::SummaryNotification.new(@duration, @example_count, @failure_count, @pending_count)
100
+ notify :deprecation_summary, Notifications::NullNotification
101
+ notify :seed, Notifications::SeedNotification.new(@configuration.seed, seed_used?)
108
102
  ensure
109
- notify :close
103
+ notify :close, Notifications::NullNotification
110
104
  end
111
105
  end
112
106
 
113
- alias_method :abort, :finish
114
-
115
107
  def stop
116
108
  @duration = (RSpec::Core::Time.now - @start).to_f if @start
117
- notify :stop
109
+ notify :stop, Notifications::NullNotification
118
110
  end
119
111
 
120
- def notify(event, *args, &block)
112
+ def notify(event, notification)
121
113
  registered_listeners(event).each do |formatter|
122
- formatter.send(event, *args, &block)
114
+ formatter.__send__(event, notification)
123
115
  end
124
116
  end
125
117
 
@@ -24,7 +24,7 @@ module RSpec
24
24
  end
25
25
 
26
26
  def find_first_parent_containing(dir)
27
- ascend_until {|path| File.exists?(File.join(path, dir))}
27
+ ascend_until {|path| File.exist?(File.join(path, dir))}
28
28
  end
29
29
 
30
30
  def ascend_until
@@ -4,7 +4,13 @@ module RSpec
4
4
 
5
5
  # Register an at_exit hook that runs the suite.
6
6
  def self.autorun
7
- return if autorun_disabled? || installed_at_exit? || running_in_drb?
7
+ if autorun_disabled?
8
+ RSpec.deprecate("Requiring `rspec/autorun` when running RSpec via the `rspec` command")
9
+ return
10
+ elsif installed_at_exit? || running_in_drb?
11
+ return
12
+ end
13
+
8
14
  at_exit do
9
15
  # Don't bother running any specs and just let the program terminate
10
16
  # if we got here due to an unrescued exception (anything other than
@@ -14,13 +20,18 @@ module RSpec
14
20
  # We got here because either the end of the program was reached or
15
21
  # somebody called Kernel#exit. Run the specs and then override any
16
22
  # existing exit status with RSpec's exit status if any specs failed.
17
- status = run(ARGV, $stderr, $stdout).to_i
18
- exit status if status != 0
23
+ invoke
19
24
  end
20
25
  @installed_at_exit = true
21
26
  end
22
27
  AT_EXIT_HOOK_BACKTRACE_LINE = "#{__FILE__}:#{__LINE__ - 2}:in `autorun'"
23
28
 
29
+ def self.invoke
30
+ disable_autorun!
31
+ status = run(ARGV, $stderr, $stdout).to_i
32
+ exit(status) if status != 0
33
+ end
34
+
24
35
  def self.disable_autorun!
25
36
  @autorun_disabled = true
26
37
  end
@@ -76,7 +87,6 @@ module RSpec
76
87
  def self.run(args, err=$stderr, out=$stdout)
77
88
  trap_interrupt
78
89
  options = ConfigurationOptions.new(args)
79
- options.parse_options
80
90
 
81
91
  if options.options[:drb]
82
92
  require 'rspec/core/drb_command_line'
@@ -41,17 +41,45 @@ module RSpec
41
41
  end
42
42
 
43
43
  module TopLevelDSL
44
- def shared_examples(*args, &block)
45
- SharedExampleGroup.registry.add_group('main', *args, &block)
44
+ def self.definitions
45
+ proc do
46
+ def shared_examples(*args, &block)
47
+ SharedExampleGroup.registry.add_group('main', *args, &block)
48
+ end
49
+ alias :shared_context :shared_examples
50
+ alias :share_examples_for :shared_examples
51
+ alias :shared_examples_for :shared_examples
52
+ def shared_example_groups
53
+ SharedExampleGroup.registry.shared_example_groups_for('main')
54
+ end
55
+ end
46
56
  end
47
57
 
48
- alias_method :shared_context, :shared_examples
49
- alias_method :share_examples_for, :shared_examples
50
- alias_method :shared_examples_for, :shared_examples
58
+ # @private
59
+ def self.exposed_globally?
60
+ @exposed_globally ||= false
61
+ end
51
62
 
52
- def shared_example_groups
53
- SharedExampleGroup.registry.shared_example_groups_for('main')
63
+ def self.expose_globally!
64
+ return if exposed_globally?
65
+ Core::DSL.change_global_dsl(&definitions)
66
+ @exposed_globally = true
54
67
  end
68
+
69
+ def self.remove_globally!
70
+ return unless exposed_globally?
71
+
72
+ Core::DSL.change_global_dsl do
73
+ undef shared_examples
74
+ undef shared_context
75
+ undef share_examples_for
76
+ undef shared_examples_for
77
+ undef shared_example_groups
78
+ end
79
+
80
+ @exposed_globally = false
81
+ end
82
+
55
83
  end
56
84
 
57
85
  def self.registry
@@ -77,10 +105,10 @@ module RSpec
77
105
 
78
106
  unless args.empty?
79
107
  mod = Module.new
80
- (class << mod; self; end).send :define_method, :extended do |host|
108
+ (class << mod; self; end).__send__(:define_method, :included) do |host|
81
109
  host.class_eval(&block)
82
110
  end
83
- RSpec.configuration.extend mod, *args
111
+ RSpec.configuration.include mod, *args
84
112
  end
85
113
  end
86
114
 
@@ -89,7 +117,7 @@ module RSpec
89
117
  end
90
118
 
91
119
  def shared_example_groups
92
- @shared_example_groups ||= Hash.new { |hash,key| hash[key] = Hash.new }
120
+ @shared_example_groups ||= Hash.new { |hash, key| hash[key] = Hash.new }
93
121
  end
94
122
 
95
123
  def clear
@@ -140,7 +168,6 @@ module RSpec
140
168
  end
141
169
  end
142
170
  end
143
- end
144
171
 
145
- extend RSpec::Core::SharedExampleGroup::TopLevelDSL
146
- Module.send(:include, RSpec::Core::SharedExampleGroup::TopLevelDSL)
172
+ instance_eval(&Core::SharedExampleGroup::TopLevelDSL.definitions)
173
+ end