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
@@ -5,6 +5,8 @@ module RSpec
5
5
  # syntax embraced by shoulda matchers:
6
6
  #
7
7
  # describe Widget do
8
+ # it { is_expected.to validate_presence_of(:name) }
9
+ # # or
8
10
  # it { should validate_presence_of(:name) }
9
11
  # end
10
12
  #
@@ -31,8 +33,10 @@ module RSpec
31
33
  # end
32
34
  # end
33
35
  #
34
- # # one-liner syntax - should is invoked on subject
36
+ # # one-liner syntax - expectation is set on the subject
35
37
  # describe Person do
38
+ # it { is_expected.to be_eligible_to_vote }
39
+ # # or
36
40
  # it { should be_eligible_to_vote }
37
41
  # end
38
42
  #
@@ -64,6 +68,11 @@ module RSpec
64
68
  # end
65
69
  #
66
70
  # @see #subject
71
+ # @see #is_expected
72
+ #
73
+ # @note This only works if you are using rspec-expectations.
74
+ # @note If you are using RSpec's newer expect-based syntax you may
75
+ # want to use `is_expected.to` instead of `should`.
67
76
  def should(matcher=nil, message=nil)
68
77
  RSpec::Expectations::PositiveExpectationHandler.handle_matcher(subject, matcher, message)
69
78
  end
@@ -78,10 +87,34 @@ module RSpec
78
87
  # end
79
88
  #
80
89
  # @see #subject
90
+ # @see #is_expected
91
+ #
92
+ # @note This only works if you are using rspec-expectations.
93
+ # @note If you are using RSpec's newer expect-based syntax you may
94
+ # want to use `is_expected.to_not` instead of `should_not`.
81
95
  def should_not(matcher=nil, message=nil)
82
96
  RSpec::Expectations::NegativeExpectationHandler.handle_matcher(subject, matcher, message)
83
97
  end
84
98
 
99
+ # Wraps the `subject` in `expect` to make it the target of an expectation.
100
+ # Designed to read nicely for one-liners.
101
+ #
102
+ # @example
103
+ #
104
+ # describe [1, 2, 3] do
105
+ # it { is_expected.to be_an Array }
106
+ # it { is_expected.not_to include 4 }
107
+ # end
108
+ #
109
+ # @see #subject
110
+ # @see #should
111
+ # @see #should_not
112
+ #
113
+ # @note This only works if you are using rspec-expectations.
114
+ def is_expected
115
+ expect(subject)
116
+ end
117
+
85
118
  private
86
119
 
87
120
  # @private
@@ -196,7 +229,7 @@ EOS
196
229
  # We have to pass the block directly to `define_method` to
197
230
  # allow it to use method constructs like `super` and `return`.
198
231
  raise "#let or #subject called without a block" if block.nil?
199
- MemoizedHelpers.module_for(self).send(:define_method, name, &block)
232
+ MemoizedHelpers.module_for(self).__send__(:define_method, name, &block)
200
233
 
201
234
  # Apply the memoization. The method has been defined in an ancestor
202
235
  # module so we can use `super` here to get the value.
@@ -265,8 +298,9 @@ EOS
265
298
  before { __send__(name) }
266
299
  end
267
300
 
268
- # Declares a `subject` for an example group which can then be the
269
- # implicit receiver (through delegation) of calls to `should`.
301
+ # Declares a `subject` for an example group which can then be wrapped
302
+ # with `expect` using `is_expected` to make it the target of an expectation
303
+ # in a concise, one-line example.
270
304
  #
271
305
  # Given a `name`, defines a method with that name which returns the
272
306
  # `subject`. This lets you declare the subject once and access it
@@ -281,13 +315,13 @@ EOS
281
315
  #
282
316
  # describe CheckingAccount, "with $50" do
283
317
  # subject { CheckingAccount.new(Money.new(50, :USD)) }
284
- # it { should have_a_balance_of(Money.new(50, :USD)) }
285
- # it { should_not be_overdrawn }
318
+ # it { is_expected.to have_a_balance_of(Money.new(50, :USD)) }
319
+ # it { is_expected.not_to be_overdrawn }
286
320
  # end
287
321
  #
288
322
  # describe CheckingAccount, "with a non-zero starting balance" do
289
323
  # subject(:account) { CheckingAccount.new(Money.new(50, :USD)) }
290
- # it { should_not be_overdrawn }
324
+ # it { is_expected.not_to be_overdrawn }
291
325
  # it "has a balance equal to the starting balance" do
292
326
  # account.balance.should eq(Money.new(50, :USD))
293
327
  # end
@@ -299,7 +333,7 @@ EOS
299
333
  let(name, &block)
300
334
  alias_method :subject, name
301
335
 
302
- self::NamedSubjectPreventSuper.send(:define_method, name) do
336
+ self::NamedSubjectPreventSuper.__send__(:define_method, name) do
303
337
  raise NotImplementedError, "`super` in named subjects is not supported"
304
338
  end
305
339
  else
@@ -393,7 +427,7 @@ EOS
393
427
 
394
428
  # @api private
395
429
  def self.define_helpers_on(example_group)
396
- example_group.send(:include, module_for(example_group))
430
+ example_group.__send__(:include, module_for(example_group))
397
431
  end
398
432
 
399
433
  if Module.method(:const_defined?).arity == 1 # for 1.8
@@ -0,0 +1,29 @@
1
+ # Created by Jim Weirich on 2007-04-10.
2
+ # Copyright (c) 2007. All rights reserved.
3
+
4
+ require 'flexmock/rspec'
5
+
6
+ module RSpec
7
+ module Core
8
+ module MockingAdapters
9
+ # @api private
10
+ module Flexmock
11
+ include ::FlexMock::MockContainer
12
+
13
+ def self.framework_name; :flexmock end
14
+
15
+ def setup_mocks_for_rspec
16
+ # No setup required
17
+ end
18
+
19
+ def verify_mocks_for_rspec
20
+ flexmock_verify
21
+ end
22
+
23
+ def teardown_mocks_for_rspec
24
+ flexmock_close
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -26,26 +26,29 @@ end
26
26
 
27
27
  module RSpec
28
28
  module Core
29
- module MockFrameworkAdapter
30
- def self.framework_name; :mocha end
29
+ module MockingAdapters
30
+ # @api private
31
+ module Mocha
32
+ def self.framework_name; :mocha end
31
33
 
32
- # Mocha::Standalone was deprecated as of Mocha 0.9.7.
33
- begin
34
- include Mocha::API
35
- rescue NameError
36
- include Mocha::Standalone
37
- end
34
+ # Mocha::Standalone was deprecated as of Mocha 0.9.7.
35
+ begin
36
+ include ::Mocha::API
37
+ rescue NameError
38
+ include ::Mocha::Standalone
39
+ end
38
40
 
39
- def setup_mocks_for_rspec
40
- mocha_setup
41
- end
41
+ def setup_mocks_for_rspec
42
+ mocha_setup
43
+ end
42
44
 
43
- def verify_mocks_for_rspec
44
- mocha_verify
45
- end
45
+ def verify_mocks_for_rspec
46
+ mocha_verify
47
+ end
46
48
 
47
- def teardown_mocks_for_rspec
48
- mocha_teardown
49
+ def teardown_mocks_for_rspec
50
+ mocha_teardown
51
+ end
49
52
  end
50
53
  end
51
54
  end
@@ -0,0 +1,12 @@
1
+ module RSpec
2
+ module Core
3
+ module MockingAdapters
4
+ # @api private
5
+ module Null
6
+ def setup_mocks_for_rspec; end
7
+ def verify_mocks_for_rspec; end
8
+ def teardown_mocks_for_rspec; end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,28 @@
1
+ require 'rr'
2
+
3
+ RSpec.configuration.backtrace_exclusion_patterns.push(RR::Errors::BACKTRACE_IDENTIFIER)
4
+
5
+ module RSpec
6
+ module Core
7
+ module MockingAdapters
8
+ # @api private
9
+ module RR
10
+ def self.framework_name; :rr end
11
+
12
+ include ::RR::Extensions::InstanceMethods
13
+
14
+ def setup_mocks_for_rspec
15
+ ::RR::Space.instance.reset
16
+ end
17
+
18
+ def verify_mocks_for_rspec
19
+ ::RR::Space.instance.verify_doubles
20
+ end
21
+
22
+ def teardown_mocks_for_rspec
23
+ ::RR::Space.instance.reset
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ require 'rspec/mocks'
2
+
3
+ module RSpec
4
+ module Core
5
+ module MockingAdapters
6
+ # @api private
7
+ module RSpec
8
+ include ::RSpec::Mocks::ExampleMethods
9
+
10
+ def self.framework_name; :rspec end
11
+
12
+ def self.configuration
13
+ ::RSpec::Mocks.configuration
14
+ end
15
+
16
+ def setup_mocks_for_rspec
17
+ ::RSpec::Mocks.setup
18
+ end
19
+
20
+ def verify_mocks_for_rspec
21
+ ::RSpec::Mocks.verify
22
+ end
23
+
24
+ def teardown_mocks_for_rspec
25
+ ::RSpec::Mocks.teardown
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,100 @@
1
+ require 'rspec/core/formatters/helpers'
2
+
3
+ module RSpec::Core
4
+ module Notifications
5
+
6
+ # The `CountNotification` represents notifications sent by the formatter
7
+ # which a single numerical count attribute. Currently used to notify
8
+ # formatters of the expected number of examples.
9
+ #
10
+ # @attr [Fixnum] count the number counted
11
+ CountNotification = Struct.new(:count)
12
+
13
+ # The `ExampleNotification` represents notifications sent by the reporter
14
+ # which contain information about the current (or soon to be) example.
15
+ # It is used by formatters to access information about that example.
16
+ #
17
+ # @example
18
+ # def example_started(notification)
19
+ # puts "Hey I started #{notification.example.description}"
20
+ # end
21
+ #
22
+ # @attr [RSpec::Core::Example] example the current example
23
+ ExampleNotification = Struct.new(:example)
24
+
25
+ # The `GroupNotification` represents notifications sent by the reporter which
26
+ # contain information about the currently running (or soon to be) example group
27
+ # It is used by formatters to access information about that group.
28
+ #
29
+ # @example
30
+ # def example_group_started(notification)
31
+ # puts "Hey I started #{notification.group.description}"
32
+ # end
33
+ # @attr [RSpec::Core::ExampleGroup] group the current group
34
+ GroupNotification = Struct.new(:group)
35
+
36
+ # The `MessageNotification` encapsulates generic messages that the reporter
37
+ # sends to formatters.
38
+ #
39
+ # @attr [String] message the message
40
+ MessageNotification = Struct.new(:message)
41
+
42
+ # The `SeedNotification` holds the seed used to randomize examples and
43
+ # wether that seed has been used or not.
44
+ #
45
+ # @attr [Fixnum] seed the seed used to randomize ordering
46
+ SeedNotification = Struct.new(:seed, :used) do
47
+ # @api
48
+ # @return [Boolean] has the seed been used?
49
+ def seed_used?
50
+ !!used
51
+ end
52
+ private :used
53
+ end
54
+
55
+ # The `SummaryNotification` holds information about the results of running
56
+ # a test suite. It is used by formatters to provide information at the end
57
+ # of the test run.
58
+ #
59
+ # @attr [Float] duration the time taken (in seconds) to run the suite
60
+ # @attr [Fixnum] example_count the number of examples run
61
+ # @attr [Fixnum] failure_count the number of failed examples
62
+ # @attr [Fixnum] pending_count the number of pending examples
63
+ class SummaryNotification < Struct.new(:duration, :example_count, :failure_count, :pending_count)
64
+ include Formatters::Helpers
65
+
66
+ # @api
67
+ # @return [String] A line summarising the results of the spec run.
68
+ def summary_line
69
+ summary = pluralize(example_count, "example")
70
+ summary << ", " << pluralize(failure_count, "failure")
71
+ summary << ", #{pending_count} pending" if pending_count > 0
72
+ summary
73
+ end
74
+ end
75
+
76
+ # The `DeprecationNotification` is issued by the reporter when a deprecated
77
+ # part of RSpec is encountered. It represents information about the deprecated
78
+ # call site.
79
+ #
80
+ # @attr [String] message A custom message about the deprecation
81
+ # @attr [String] deprecated A custom message about the deprecation (alias of message)
82
+ # @attr [String] replacement An optional replacement for the deprecation
83
+ # @attr [String] call_site An optional call site from which the deprecation was issued
84
+ DeprecationNotification = Struct.new(:deprecated, :message, :replacement, :call_site) do
85
+ private_class_method :new
86
+
87
+ # @api
88
+ # Convenience way to initialize the notification
89
+ def self.from_hash(data)
90
+ new data[:deprecated], data[:message], data[:replacement], data[:call_site]
91
+ end
92
+ end
93
+
94
+ # `NullNotification` represents a placeholder value for notifications that
95
+ # currently require no information, but we may wish to extend in future.
96
+ class NullNotification
97
+ end
98
+
99
+ end
100
+ end
@@ -2,16 +2,13 @@
2
2
  require 'optparse'
3
3
 
4
4
  module RSpec::Core
5
+ # @api private
5
6
  class Parser
6
- def self.parse!(args)
7
- new.parse!(args)
7
+ def self.parse(args)
8
+ new.parse(args)
8
9
  end
9
10
 
10
- class << self
11
- alias_method :parse, :parse!
12
- end
13
-
14
- def parse!(args)
11
+ def parse(args)
15
12
  return {} if args.empty?
16
13
 
17
14
  convert_deprecated_args(args)
@@ -29,9 +26,6 @@ module RSpec::Core
29
26
  def convert_deprecated_args(args)
30
27
  args.map! { |arg|
31
28
  case arg
32
- when "--formatter"
33
- RSpec.deprecate("the --formatter option", :replacement => "-f or --format")
34
- "--format"
35
29
  when "--default_path"
36
30
  "--default-path"
37
31
  when "--line_number"
@@ -42,8 +36,6 @@ module RSpec::Core
42
36
  }
43
37
  end
44
38
 
45
- alias_method :parse, :parse!
46
-
47
39
  def parser(options)
48
40
  OptionParser.new do |parser|
49
41
  parser.banner = "Usage: rspec [options] [files or directories]\n\n"
@@ -101,12 +93,7 @@ module RSpec::Core
101
93
 
102
94
  parser.on('--init', 'Initialize your project with RSpec.') do |cmd|
103
95
  require 'rspec/core/project_initializer'
104
- ProjectInitializer.new(cmd).run
105
- exit
106
- end
107
-
108
- parser.on('--configure', 'Deprecated. Use --init instead.') do |cmd|
109
- RSpec.warning "--configure is deprecated with no effect. Use --init instead.", :call_site => nil
96
+ ProjectInitializer.new.run
110
97
  exit
111
98
  end
112
99
 
@@ -228,6 +215,12 @@ FILTERING
228
215
  exit
229
216
  end
230
217
 
218
+ %w[-d --I].each do |option|
219
+ parser.on(option) do
220
+ raise OptionParser::InvalidOption.new
221
+ end
222
+ end
223
+
231
224
  end
232
225
  end
233
226
  end
@@ -1,7 +1,13 @@
1
1
  module RSpec
2
2
  module Core
3
3
  module Pending
4
- class PendingDeclaredInExample < StandardError; end
4
+ class SkipDeclaredInExample < StandardError
5
+ attr_reader :argument
6
+
7
+ def initialize(argument)
8
+ @argument = argument
9
+ end
10
+ end
5
11
 
6
12
  # If Test::Unit is loaed, we'll use its error as baseclass, so that Test::Unit
7
13
  # will report unmet RSpec expectations as failures rather than errors.
@@ -18,12 +24,11 @@ module RSpec
18
24
  # @overload pending(message)
19
25
  # @overload pending(message, &block)
20
26
  #
21
- # Stops execution of an example, and reports it as pending. Takes an
22
- # optional message and block.
27
+ # Marks an example as pending. The rest of the example will still be
28
+ # executed, and if it passes the example will fail to indicate that the
29
+ # pending can be removed.
23
30
  #
24
31
  # @param [String] message optional message to add to the summary report.
25
- # @param [Block] block optional block. If it fails, the example is
26
- # reported as pending. If it executes cleanly the example fails.
27
32
  #
28
33
  # @example
29
34
  #
@@ -31,28 +36,13 @@ module RSpec
31
36
  # # reported as "Pending: no reason given"
32
37
  # it "is pending with no message" do
33
38
  # pending
34
- # this_does_not_get_executed
39
+ # raise "broken"
35
40
  # end
36
41
  #
37
42
  # # reported as "Pending: something else getting finished"
38
43
  # it "is pending with a custom message" do
39
44
  # pending("something else getting finished")
40
- # this_does_not_get_executed
41
- # end
42
- #
43
- # # reported as "Pending: something else getting finished"
44
- # it "is pending with a failing block" do
45
- # pending("something else getting finished") do
46
- # raise "this is the failure"
47
- # end
48
- # end
49
- #
50
- # # reported as failure, saying we expected the block to fail but
51
- # # it passed.
52
- # it "is pending with a passing block" do
53
- # pending("something else getting finished") do
54
- # true.should be(true)
55
- # end
45
+ # raise "broken"
56
46
  # end
57
47
  # end
58
48
  #
@@ -74,36 +64,77 @@ module RSpec
74
64
  def pending(*args)
75
65
  current_example = RSpec.current_example
76
66
 
77
- return self.class.before(:each) { pending(*args) } unless current_example
67
+ if current_example
68
+ Pending.mark_pending! current_example, args.first
69
+ else
70
+ raise "`pending` may not be used outside of examples, such as in " +
71
+ "before(:all). Maybe you want `skip`?"
72
+ end
73
+ end
78
74
 
79
- options = args.last.is_a?(Hash) ? args.pop : {}
80
- message = args.first || NO_REASON_GIVEN
75
+ # @overload skip()
76
+ # @overload skip(message)
77
+ # @overload skip(message, &block)
78
+ #
79
+ # Marks an example as pending and skips execution when called without a
80
+ # block. When called with a block, skips just that block and does not
81
+ # mark the example as pending. The block form is provided as replacement
82
+ # for RSpec 2's pending-with-block feature, and is not recommended for
83
+ # new code. Use simple conditionals instead.
84
+ #
85
+ # @param [String] message optional message to add to the summary report.
86
+ # @block [Block] block optional block to be skipped
87
+ #
88
+ # @example
89
+ #
90
+ # describe "an example" do
91
+ # # reported as "Pending: no reason given"
92
+ # it "is skipped with no message" do
93
+ # skip
94
+ # end
95
+ #
96
+ # # reported as "Pending: something else getting finished"
97
+ # it "is skipped with a custom message" do
98
+ # skip "something else getting finished"
99
+ # end
100
+ #
101
+ # # Passes
102
+ # it "contains a skipped statement" do
103
+ # skip do
104
+ # fail
105
+ # end
106
+ # end
107
+ # end
108
+ def skip(*args)
109
+ current_example = RSpec.current_example
81
110
 
82
- if options[:unless] || (options.has_key?(:if) && !options[:if])
83
- return block_given? ? yield : nil
111
+ if current_example
112
+ Pending.mark_skipped! current_example, args.first
84
113
  end
85
114
 
86
- current_example.metadata[:pending] = true
87
- current_example.metadata[:execution_result][:pending_message] = message
88
- current_example.execution_result[:pending_fixed] = false
89
- if block_given?
90
- begin
91
- result = begin
92
- yield
93
- current_example.example_group_instance.instance_eval { verify_mocks_for_rspec }
94
- end
95
- current_example.metadata[:pending] = false
96
- rescue Exception => e
97
- current_example.execution_result[:exception] = e
98
- ensure
99
- teardown_mocks_for_rspec
100
- end
101
- if result
102
- current_example.execution_result[:pending_fixed] = true
103
- raise PendingExampleFixedError.new
104
- end
115
+ raise SkipDeclaredInExample.new(args.first)
116
+ end
117
+
118
+ def self.mark_skipped!(example, message_or_bool)
119
+ Pending.mark_pending! example, message_or_bool
120
+ example.metadata[:skip] = true
121
+ end
122
+
123
+ def self.mark_pending!(example, message_or_bool)
124
+ message = if !message_or_bool || !(String === message_or_bool)
125
+ NO_REASON_GIVEN
126
+ else
127
+ message_or_bool
105
128
  end
106
- raise PendingDeclaredInExample.new(message)
129
+
130
+ example.metadata[:pending] = true
131
+ example.metadata[:execution_result][:pending_message] = message
132
+ example.execution_result[:pending_fixed] = false
133
+ end
134
+
135
+ def self.mark_fixed!(example)
136
+ example.metadata[:pending] = false
137
+ example.metadata[:execution_result][:pending_fixed] = true
107
138
  end
108
139
  end
109
140
  end