Skip to content

Commit

Permalink
Merge pull request rspec#2758 from rspec/strict-predicates
Browse files Browse the repository at this point in the history
Fix predicates to return actual true/false values.
  • Loading branch information
JonRowe committed Sep 3, 2020
2 parents 5a80658 + b2c950c commit e304ccb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
13 changes: 10 additions & 3 deletions lib/rspec/core/example.rb
Expand Up @@ -231,8 +231,13 @@ def example_group
@example_group_class
end

alias_method :pending?, :pending
alias_method :skipped?, :skip
def pending?
!!pending
end

def skipped?
!!skip
end

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

alias pending_fixed? pending_fixed
def pending_fixed?
!!pending_fixed
end

# @return [Boolean] Indicates if the example was completely skipped
# (typically done via `:skip` metadata or the `skip` method). Skipped examples
Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/core/example_execution_result_spec.rb
Expand Up @@ -22,7 +22,7 @@ class Example

it 'provides a `pending_fixed?` predicate' do
er = ExecutionResult.new
expect { er.pending_fixed = true }.to change(er, :pending_fixed?).to(true)
expect { er.pending_fixed = true }.to change(er, :pending_fixed?).from(false).to(true)
end

describe "backwards compatibility" do
Expand Down
23 changes: 23 additions & 0 deletions spec/rspec/core/example_spec.rb
Expand Up @@ -778,7 +778,18 @@ def expect_pending_result(example)
expect_pending_result(group.examples.last)
end
end
end

describe "#pending?" do
it "only returns true / false values" do
group = describe_successfully do
example("", :pending => "a message thats ignored") { fail }
example { }
end

expect(group.examples[0].pending?).to eq true
expect(group.examples[1].pending?).to eq false
end
end

describe "#skip" do
Expand Down Expand Up @@ -847,6 +858,18 @@ def expect_pending_result(example)
end
end

describe "#skipped?" do
it "only returns true / false values" do
group = describe_successfully do
example("", :skip => "a message thats ignored") { fail }
example { }
end

expect(group.examples[0].skipped?).to eq true
expect(group.examples[1].skipped?).to eq false
end
end

describe "timing" do
it "uses RSpec::Core::Time as to not be affected by changes to time in examples" do
reporter = double(:reporter).as_null_object
Expand Down

0 comments on commit e304ccb

Please sign in to comment.