Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 91f092f

Browse files
committed
Merge pull request #2758 from rspec/strict-predicates
Fix predicates to return actual true/false values.
1 parent efbac94 commit 91f092f

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

lib/rspec/core/example.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,13 @@ def example_group
231231
@example_group_class
232232
end
233233

234-
alias_method :pending?, :pending
235-
alias_method :skipped?, :skip
234+
def pending?
235+
!!pending
236+
end
237+
238+
def skipped?
239+
!!skip
240+
end
236241

237242
# @api private
238243
# instance_execs the block passed to the constructor in the context of
@@ -577,7 +582,9 @@ class ExecutionResult
577582
# this indicates whether or not it now passes.
578583
attr_accessor :pending_fixed
579584

580-
alias pending_fixed? pending_fixed
585+
def pending_fixed?
586+
!!pending_fixed
587+
end
581588

582589
# @return [Boolean] Indicates if the example was completely skipped
583590
# (typically done via `:skip` metadata or the `skip` method). Skipped examples

spec/rspec/core/example_execution_result_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Example
2222

2323
it 'provides a `pending_fixed?` predicate' do
2424
er = ExecutionResult.new
25-
expect { er.pending_fixed = true }.to change(er, :pending_fixed?).to(true)
25+
expect { er.pending_fixed = true }.to change(er, :pending_fixed?).from(false).to(true)
2626
end
2727

2828
describe "backwards compatibility" do

spec/rspec/core/example_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,18 @@ def expect_pending_result(example)
778778
expect_pending_result(group.examples.last)
779779
end
780780
end
781+
end
782+
783+
describe "#pending?" do
784+
it "only returns true / false values" do
785+
group = describe_successfully do
786+
example("", :pending => "a message thats ignored") { fail }
787+
example { }
788+
end
781789

790+
expect(group.examples[0].pending?).to eq true
791+
expect(group.examples[1].pending?).to eq false
792+
end
782793
end
783794

784795
describe "#skip" do
@@ -847,6 +858,18 @@ def expect_pending_result(example)
847858
end
848859
end
849860

861+
describe "#skipped?" do
862+
it "only returns true / false values" do
863+
group = describe_successfully do
864+
example("", :skip => "a message thats ignored") { fail }
865+
example { }
866+
end
867+
868+
expect(group.examples[0].skipped?).to eq true
869+
expect(group.examples[1].skipped?).to eq false
870+
end
871+
end
872+
850873
describe "timing" do
851874
it "uses RSpec::Core::Time as to not be affected by changes to time in examples" do
852875
reporter = double(:reporter).as_null_object

0 commit comments

Comments
 (0)