Skip to content

Commit

Permalink
[core] Merge pull request rspec/rspec-core#2736 from marcandre/be_tru…
Browse files Browse the repository at this point in the history
…e_to_yourself

Avoid be_falsey and be_truthy 

---
This commit was imported from rspec/rspec-core@97a6f23.
  • Loading branch information
JonRowe committed Jun 18, 2020
1 parent 74543eb commit 84d4f25
Show file tree
Hide file tree
Showing 17 changed files with 118 additions and 117 deletions.
22 changes: 9 additions & 13 deletions rspec-core/features/configuration/custom_settings.feature
Expand Up @@ -14,18 +14,14 @@ Feature: custom settings
expect(RSpec.configuration.custom_setting).to be_nil
end
it "acts false by default" do
expect(RSpec.configuration.custom_setting).to be_falsey
end
it "is exposed as a predicate" do
expect(RSpec.configuration.custom_setting?).to be_falsey
expect(RSpec.configuration.custom_setting?).to be(false)
end
it "can be overridden" do
RSpec.configuration.custom_setting = true
expect(RSpec.configuration.custom_setting).to be_truthy
expect(RSpec.configuration.custom_setting?).to be_truthy
expect(RSpec.configuration.custom_setting).to be(true)
expect(RSpec.configuration.custom_setting?).to be(true)
end
end
"""
Expand All @@ -41,17 +37,17 @@ Feature: custom settings
RSpec.describe "custom setting" do
it "is true by default" do
expect(RSpec.configuration.custom_setting).to be_truthy
expect(RSpec.configuration.custom_setting).to be(true)
end
it "is exposed as a predicate" do
expect(RSpec.configuration.custom_setting?).to be_truthy
expect(RSpec.configuration.custom_setting?).to be(true)
end
it "can be overridden" do
RSpec.configuration.custom_setting = false
expect(RSpec.configuration.custom_setting).to be_falsey
expect(RSpec.configuration.custom_setting?).to be_falsey
expect(RSpec.configuration.custom_setting).to be(false)
expect(RSpec.configuration.custom_setting?).to be(false)
end
end
"""
Expand All @@ -71,11 +67,11 @@ Feature: custom settings
RSpec.describe "custom setting" do
it "returns the value set in the last cofigure block to get eval'd" do
expect(RSpec.configuration.custom_setting).to be_truthy
expect(RSpec.configuration.custom_setting).to be(true)
end
it "is exposed as a predicate" do
expect(RSpec.configuration.custom_setting?).to be_truthy
expect(RSpec.configuration.custom_setting?).to be(true)
end
end
"""
Expand Down
4 changes: 2 additions & 2 deletions rspec-core/features/example_groups/shared_examples.feature
Expand Up @@ -106,13 +106,13 @@ Feature: shared examples
describe "#include?" do
context "with an item that is in the collection" do
it "returns true" do
expect(collection.include?(7)).to be_truthy
expect(collection.include?(7)).to be(true)
end
end
context "with an item that is not in the collection" do
it "returns false" do
expect(collection.include?(9)).to be_falsey
expect(collection.include?(9)).to be(false)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion rspec-core/features/hooks/around_hooks.feature
Expand Up @@ -219,7 +219,7 @@ Feature: `around` hooks
end
it "runs the example in the correct context" do
expect(included_in_configure_block).to be_truthy
expect(included_in_configure_block).to be(true)
end
end
"""
Expand Down
17 changes: 10 additions & 7 deletions rspec-core/lib/rspec/core/configuration.rb
Expand Up @@ -67,15 +67,17 @@ def self.define_reader(name)
end

# @private
def self.define_aliases(name, alias_name)
def self.define_alias(name, alias_name)
alias_method alias_name, name
alias_method "#{alias_name}=", "#{name}="
define_predicate_for alias_name
define_predicate alias_name
end

# @private
def self.define_predicate_for(*names)
names.each { |name| alias_method "#{name}?", name }
def self.define_predicate(name)
define_method "#{name}?" do
!!send(name)
end
end

# @private
Expand All @@ -88,7 +90,7 @@ def self.add_setting(name, opts={})
add_read_only_setting name

Array(opts[:alias_with]).each do |alias_name|
define_aliases(name, alias_name)
define_alias(name, alias_name)
end
end

Expand All @@ -98,7 +100,7 @@ def self.add_setting(name, opts={})
def self.add_read_only_setting(name, opts={})
raise "Use the instance add_setting method if you want to set a default" if opts.key?(:default)
define_reader name
define_predicate_for name
define_predicate name
end

# @macro [attach] add_setting
Expand Down Expand Up @@ -312,7 +314,8 @@ def exclude_pattern=(value)
# Report the times for the slowest examples (default: `false`).
# Use this to specify the number of examples to include in the profile.
# @return [Boolean]
add_setting :profile_examples
attr_writer :profile_examples
define_predicate :profile_examples

# @macro add_setting
# Run all examples if none match the configured filters
Expand Down
1 change: 1 addition & 0 deletions rspec-core/lib/rspec/core/world.rb
Expand Up @@ -17,6 +17,7 @@ class World
attr_accessor :non_example_failure

def initialize(configuration=RSpec.configuration)
@wants_to_quit = false
@configuration = configuration
configuration.world = self
@example_groups = []
Expand Down
20 changes: 10 additions & 10 deletions rspec-core/spec/rspec/core/configuration_options_spec.rb
Expand Up @@ -296,16 +296,16 @@
end

describe "--fail-fast" do
it "defaults to false" do
expect(parse_options[:fail_fast]).to be_falsey
it "defaults to nil" do
expect(parse_options[:fail_fast]).to be(nil)
end

it "sets fail_fast on config" do
expect(parse_options("--fail-fast")[:fail_fast]).to be_truthy
it "sets fail_fast to 1 on config" do
expect(parse_options("--fail-fast")[:fail_fast]).to be(1)
end

it "sets fail_fast on config" do
expect(parse_options("--no-fail-fast")[:fail_fast]).to be_falsey
it "sets fail_fast to false on config" do
expect(parse_options("--no-fail-fast")[:fail_fast]).to be(false)
end
end

Expand All @@ -322,12 +322,12 @@
end

describe "--dry-run" do
it "defaults to false" do
expect(parse_options[:dry_run]).to be_falsey
it "defaults to nil" do
expect(parse_options[:dry_run]).to be(nil)
end

it "sets dry_run on config" do
expect(parse_options("--dry-run")[:dry_run]).to be_truthy
expect(parse_options("--dry-run")[:dry_run]).to be(true)
end
end

Expand Down Expand Up @@ -464,7 +464,7 @@ def expect_parsing_to_fail_mentioning_source(source, options=[])

expect(options[:requires]).to eq(["some_file"])
expect(options[:full_description]).to eq([/foo\ bar/])
expect(options[:drb]).to be_truthy
expect(options[:drb]).to be(true)
expect(options[:formatters]).to eq([['global']])
end
end
Expand Down
24 changes: 12 additions & 12 deletions rspec-core/spec/rspec/core/configuration_spec.rb
Expand Up @@ -293,7 +293,7 @@ def mod.configuration; @config ||= Struct.new(:custom_setting).new; end
mod_config.custom_setting = true
end

expect(mod.configuration.custom_setting).to be_truthy
expect(mod.configuration.custom_setting).to be(true)
end

it "raises if framework module doesn't support configuration" do
Expand Down Expand Up @@ -1302,12 +1302,12 @@ def metadata_hash(*args)
describe "#run_all_when_everything_filtered?" do

it "defaults to false" do
expect(config.run_all_when_everything_filtered?).to be_falsey
expect(config.run_all_when_everything_filtered?).to be(false)
end

it "can be queried with question method" do
config.run_all_when_everything_filtered = true
expect(config.run_all_when_everything_filtered?).to be_truthy
expect(config.run_all_when_everything_filtered?).to be(true)
end
end

Expand Down Expand Up @@ -1779,14 +1779,14 @@ def metadata_hash(*args)
config_2 = Configuration.new

config_1.full_backtrace = true
expect(config_2.full_backtrace?).to be_falsey
expect(config_2.full_backtrace?).to be(false)
end
end

describe "#backtrace_exclusion_patterns=" do
it "actually receives the new filter values" do
config.backtrace_exclusion_patterns = [/.*/]
expect(config.backtrace_formatter.exclude? "this").to be_truthy
expect(config.backtrace_formatter.exclude? "this").to be(true)
end
end

Expand All @@ -1805,7 +1805,7 @@ def metadata_hash(*args)
describe "#backtrace_exclusion_patterns" do
it "can be appended to" do
config.backtrace_exclusion_patterns << /.*/
expect(config.backtrace_formatter.exclude? "this").to be_truthy
expect(config.backtrace_formatter.exclude? "this").to be(true)
end
end

Expand Down Expand Up @@ -2213,7 +2213,7 @@ def exclude?(line)
end

it "adds a predicate" do
expect(config.custom_option?).to be_falsey
expect(config.custom_option?).to be(false)
end

it "can be overridden" do
Expand All @@ -2232,7 +2232,7 @@ def exclude?(line)
end

it "returns true for the predicate" do
expect(config.custom_option?).to be_truthy
expect(config.custom_option?).to be(true)
end

it "can be overridden with a truthy value" do
Expand Down Expand Up @@ -2269,7 +2269,7 @@ def exclude?(line)

it "delegates the predicate to the other option" do
config.custom_option = true
expect(config.another_custom_option?).to be_truthy
expect(config.another_custom_option?).to be(true)
end
end
end
Expand Down Expand Up @@ -2526,11 +2526,11 @@ def example_numbered(num)
it "forces 'false' value" do
config.add_setting :custom_option
config.custom_option = true
expect(config.custom_option?).to be_truthy
expect(config.custom_option?).to be(true)
config.force :custom_option => false
expect(config.custom_option?).to be_falsey
expect(config.custom_option?).to be(false)
config.custom_option = true
expect(config.custom_option?).to be_falsey
expect(config.custom_option?).to be(false)
end
end

Expand Down

0 comments on commit 84d4f25

Please sign in to comment.