-
-
Notifications
You must be signed in to change notification settings - Fork 752
Provide upgrade warning for pending behaviour change. #1268
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,22 @@ def description | |
| def self.define_example_method(name, extra_options={}) | ||
| module_eval(<<-END_RUBY, __FILE__, __LINE__) | ||
| def #{name}(desc=nil, *args, &block) | ||
| if #{name.inspect} == :pending | ||
| RSpec.warn_deprecation(<<-EOS.gsub(/^\s+\|/, '')) | ||
| |The semantics of `RSpec::Core::ExampleGroup#pending` are changing in RSpec 3. | ||
| |In RSpec 2.x, it caused the example to be skipped. In RSpec 3, the example will | ||
| |still be run but is expected to fail, and will be marked as a failure (rather | ||
| |than as pending) if the example passes, just like how `pending` with a block | ||
| |from within an example already works. | ||
| | | ||
| |To keep the same skip semantics, change `pending` to `skip`. Otherwise, if you | ||
| |want the new RSpec 3 behavior, you can safely ignore this warning and continue | ||
| |to upgrade to RSpec 3 without addressing it. | ||
| | | ||
| |Called from \#{CallerFilter.first_non_rspec_line}. | ||
| | | ||
| EOS | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW, I've become a fan of this technique for doc strings: RSpec.warn_deprecation(<<-EOS.gsub(/^\s+\|/, ''))
|Some text
|Some more text
|blah blah
EOSI like how it keeps the indentation flow rather than forcing the string to be fully left-aligned. Not worth holding up this PR for, though; more something to think about in the future. (Or not, if you don't prefer it...I hold this preference quite loosely). |
||
| end | ||
| options = build_metadata_hash_from(args) | ||
| options.update(:pending => RSpec::Core::Pending::NOT_YET_IMPLEMENTED) unless block | ||
| options.update(#{extra_options.inspect}) | ||
|
|
@@ -108,6 +124,10 @@ def #{name}(desc=nil, *args, &block) | |
| # Shortcut to define an example with :pending => true | ||
| # @see example | ||
| define_example_method :pending, :pending => true | ||
| # Shortcut to define an example with :pending => true | ||
| # Backported from RSpec 3 to aid migration. | ||
| # @see example | ||
| define_example_method :skip, :pending => true | ||
| # Shortcut to define an example with :pending => 'Temporarily disabled with xexample' | ||
| # @see example | ||
| define_example_method :xexample, :pending => 'Temporarily disabled with xexample' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,7 +71,32 @@ class PendingExampleFixedError < StandardError; end | |
| # it "does something", :pending => "something else getting finished" do | ||
| # # ... | ||
| # end | ||
| def pending(*args) | ||
| def pending(*args, &block) | ||
| RSpec.warn_deprecation(<<-EOS.gsub(/^\s+\|/, '')) | ||
| |The semantics of `RSpec::Core::Pending#pending` are changing in | ||
| |RSpec 3. In RSpec 2.x, it caused the example to be skipped. In | ||
| |RSpec 3, the rest of the example will still be run but is expected | ||
| |to fail, and will be marked as a failure (rather than as pending) | ||
| |if the example passes. | ||
| | | ||
| |Any passed block will no longer be executed. This feature is being | ||
| |removed since it was semantically inconsistent, and the behaviour it | ||
| |offered is being made available with the other ways of marking an | ||
| |example pending. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 This wording is very clear and well done. Nice work! |
||
| | | ||
| |To keep the same skip semantics, change `pending` to `skip`. | ||
| |Otherwise, if you want the new RSpec 3 behavior, you can safely | ||
| |ignore this warning and continue to upgrade to RSpec 3 without | ||
| |addressing it. | ||
| | | ||
| |Called from #{CallerFilter.first_non_rspec_line}. | ||
| | | ||
| EOS | ||
|
|
||
| pending_no_warning(*args, &block) | ||
| end | ||
|
|
||
| def pending_no_warning(*args) | ||
| return self.class.before(:each) { pending(*args) } unless RSpec.current_example | ||
|
|
||
| options = args.last.is_a?(Hash) ? args.pop : {} | ||
|
|
@@ -103,6 +128,9 @@ def pending(*args) | |
| end | ||
| raise PendingDeclaredInExample.new(message) | ||
| end | ||
|
|
||
| # Backport from RSpec 3 to aid in upgrading. | ||
| alias_method :skip, :pending_no_warning | ||
| end | ||
|
|
||
| # Alias the error for compatibility with extension gems (e.g. formatters) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -693,30 +693,52 @@ def define_and_run_group(define_outer_example = false) | |
| end | ||
| end | ||
|
|
||
| %w[pending xit xspecify xexample].each do |method_name| | ||
| describe "::#{method_name}" do | ||
| before do | ||
| @group = ExampleGroup.describe | ||
| @group.send(method_name, "is pending") { } | ||
| end | ||
| %w[pending skip].each do |method_name| | ||
| describe ".#{method_name}" do | ||
| let(:group) { ExampleGroup.describe.tap {|x| | ||
| x.send(method_name, "is pending") { } | ||
| }} | ||
|
|
||
| it "generates a pending example" do | ||
| @group.run | ||
| expect(@group.examples.first).to be_pending | ||
| group.run | ||
| expect(group.examples.first).to be_pending | ||
| end | ||
|
|
||
| it "sets the pending message" do | ||
| group.run | ||
| expect(group.examples.first.metadata[:execution_result][:pending_message]).to eq(RSpec::Core::Pending::NO_REASON_GIVEN) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| it "sets the pending message", :if => method_name == 'pending' do | ||
| @group.run | ||
| expect(@group.examples.first.metadata[:execution_result][:pending_message]).to eq(RSpec::Core::Pending::NO_REASON_GIVEN) | ||
| %w[xit xspecify xexample].each do |method_name| | ||
| describe ".#{method_name}" do | ||
| let(:group) { ExampleGroup.describe.tap {|x| | ||
| x.send(method_name, "is pending") { } | ||
| }} | ||
|
|
||
| it "generates a pending example" do | ||
| group.run | ||
| expect(group.examples.first).to be_pending | ||
| end | ||
|
|
||
| it "sets the pending message", :unless => method_name == 'pending' do | ||
| @group.run | ||
| expect(@group.examples.first.metadata[:execution_result][:pending_message]).to eq("Temporarily disabled with #{method_name}") | ||
| it "sets the pending message" do | ||
| group.run | ||
| expect(group.examples.first.metadata[:execution_result][:pending_message]).to eq("Temporarily disabled with #{method_name}") | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe '::pending' do | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've never really liked using Are there situations where you prefer it? (Don't bother changing it in this PR -- since it's in 2.99 and not master it's not sticking around and I don't really care. I'm just bringing this up because I'm curious how others on the team feel about it).
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer |
||
| it 'shows upgrade warning' do | ||
| expect_warn_deprecation_with_call_site( | ||
| "example_group_spec.rb", __LINE__ + 3 | ||
| ) | ||
| group = ExampleGroup.describe | ||
| group.send(:pending, "is pending") { } | ||
| end | ||
| end | ||
|
|
||
| describe "adding examples" do | ||
|
|
||
| it "allows adding an example using 'it'" do | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also the predicate form
show_failures_in_pending_blocks?to deprecate.Also, "with no replacement" isn't entirely true -- the replacement is to use a custom formatter that prints the failure details from pending examples. Not sure if that's worth mentioning, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, one slight complication with
show_failures_in_pending_blocks?is that it's the method called from base text formatter but we don't want it issuing a deprecation. You could probably change it to useRSpec.configuration.instance_variable_get(:@show_failures_in_pending_blocks)which is a hack but bypasses the deprecation warning and I'm OK with since it's a temporary thing just in 2.99.