Skip to content

Commit

Permalink
[core] Merge pull request rspec/rspec-core#1473 from rspec/issue-1472
Browse files Browse the repository at this point in the history
skip fixes for 2.99

---
This commit was imported from rspec/rspec-core@cb5ea78.
  • Loading branch information
xaviershay committed Apr 6, 2014
2 parents d4c822e + 235a4b3 commit 9f32572
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
3 changes: 3 additions & 0 deletions rspec-core/Changelog.md
Expand Up @@ -5,6 +5,8 @@ Enhancements:

* Add `--deprecation-out` CLI option which directs deprecation warnings
to the named file. (Myron Marston)
* Backport support for `skip` in metadata to skip execution of an example.
(Xavier Shay, #1472)

Deprecations:

Expand Down Expand Up @@ -60,6 +62,7 @@ Bug Fixes:

* Issue a warning when you set `config.deprecation_stream` too late for
it to take effect because the reporter has already been setup. (Myron Marston)
* `skip` with a block should not execute the block. (Xavier Shay, #1472)

### 2.99.0.beta2 / 2014-02-17
[full changelog](http://github.com/rspec/rspec-core/compare/v2.99.0.beta1...v2.99.0.beta2)
Expand Down
2 changes: 2 additions & 0 deletions rspec-core/lib/rspec/core/example_group.rb
Expand Up @@ -92,6 +92,8 @@ def self.#{name}(desc=nil, *args, &block)
end
options = build_metadata_hash_from(args)
options.update(:pending => RSpec::Core::Pending::NOT_YET_IMPLEMENTED) unless block
# Backport from RSpec 3 to assist with upgrading
options.update(:pending => options[:skip]) if options[:skip]
options.update(#{extra_options.inspect})
examples << RSpec::Core::Example.new(self, desc, options, block)
examples.last
Expand Down
6 changes: 5 additions & 1 deletion rspec-core/lib/rspec/core/pending.rb
Expand Up @@ -137,7 +137,11 @@ def pending_no_warning(*args)
end

# Backport from RSpec 3 to aid in upgrading.
alias_method :skip, :pending_no_warning
#
# Not using alias method because we explictly want to discard any block.
def skip(*args)
pending_no_warning(*args)
end

def self.const_missing(name)
return super unless name == :PendingDeclaredInExample
Expand Down
26 changes: 22 additions & 4 deletions rspec-core/spec/rspec/core/example_group_spec.rb
Expand Up @@ -752,19 +752,37 @@ def define_and_run_group(define_outer_example = false)
end
end

context 'skip in metadata' do
let(:group) { ExampleGroup.describe do
it 'is skipped', :skip => 'skip this' do
end
end
}

before { group.run }

it 'generates a pending example' do
expect(group.examples.first).to be_pending
end

it 'sets the pending message' do
expect(group.examples.first.metadata[:execution_result][:pending_message]).to eq('skip this')
end
end

%w[pending skip].each do |method_name|
describe ".#{method_name}" do
let(:group) { ExampleGroup.describe.tap {|x|
x.send(method_name, "is pending") { }
}}

before { group.run }

it "generates a pending example" do
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
Expand All @@ -776,13 +794,13 @@ def define_and_run_group(define_outer_example = false)
x.send(method_name, "is pending") { }
}}

before { group.run }

it "generates a pending example" do
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("Temporarily disabled with #{method_name}")
end
end
Expand Down
14 changes: 14 additions & 0 deletions rspec-core/spec/rspec/core/pending_example_spec.rb
Expand Up @@ -117,6 +117,20 @@
end
end

context "skip with a block" do
it "does not execute the block" do
called = false
group = RSpec::Core::ExampleGroup.describe('group') do
it "does something" do
skip { called = true }
end
end
example = group.examples.first
example.run(group.new, double.as_null_object)
expect(called).to eq(false)
end
end

context "with a block" do
def run_example(*pending_args, &block)
group = RSpec::Core::ExampleGroup.describe('group') do
Expand Down

0 comments on commit 9f32572

Please sign in to comment.