Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix predicates to return actual true/false values. #2758

Merged
merged 1 commit into from Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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