Skip to content

Commit 5ea773c

Browse files
authored
Merge pull request rspec#2736 from marcandre/be_true_to_yourself
Avoid be_falsey and be_truthy
2 parents 202c003 + ddc46f6 commit 5ea773c

17 files changed

+118
-117
lines changed

features/configuration/custom_settings.feature

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,14 @@ Feature: custom settings
1414
expect(RSpec.configuration.custom_setting).to be_nil
1515
end
1616
17-
it "acts false by default" do
18-
expect(RSpec.configuration.custom_setting).to be_falsey
19-
end
20-
2117
it "is exposed as a predicate" do
22-
expect(RSpec.configuration.custom_setting?).to be_falsey
18+
expect(RSpec.configuration.custom_setting?).to be(false)
2319
end
2420
2521
it "can be overridden" do
2622
RSpec.configuration.custom_setting = true
27-
expect(RSpec.configuration.custom_setting).to be_truthy
28-
expect(RSpec.configuration.custom_setting?).to be_truthy
23+
expect(RSpec.configuration.custom_setting).to be(true)
24+
expect(RSpec.configuration.custom_setting?).to be(true)
2925
end
3026
end
3127
"""
@@ -41,17 +37,17 @@ Feature: custom settings
4137
4238
RSpec.describe "custom setting" do
4339
it "is true by default" do
44-
expect(RSpec.configuration.custom_setting).to be_truthy
40+
expect(RSpec.configuration.custom_setting).to be(true)
4541
end
4642
4743
it "is exposed as a predicate" do
48-
expect(RSpec.configuration.custom_setting?).to be_truthy
44+
expect(RSpec.configuration.custom_setting?).to be(true)
4945
end
5046
5147
it "can be overridden" do
5248
RSpec.configuration.custom_setting = false
53-
expect(RSpec.configuration.custom_setting).to be_falsey
54-
expect(RSpec.configuration.custom_setting?).to be_falsey
49+
expect(RSpec.configuration.custom_setting).to be(false)
50+
expect(RSpec.configuration.custom_setting?).to be(false)
5551
end
5652
end
5753
"""
@@ -71,11 +67,11 @@ Feature: custom settings
7167
7268
RSpec.describe "custom setting" do
7369
it "returns the value set in the last cofigure block to get eval'd" do
74-
expect(RSpec.configuration.custom_setting).to be_truthy
70+
expect(RSpec.configuration.custom_setting).to be(true)
7571
end
7672
7773
it "is exposed as a predicate" do
78-
expect(RSpec.configuration.custom_setting?).to be_truthy
74+
expect(RSpec.configuration.custom_setting?).to be(true)
7975
end
8076
end
8177
"""

features/example_groups/shared_examples.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ Feature: shared examples
106106
describe "#include?" do
107107
context "with an item that is in the collection" do
108108
it "returns true" do
109-
expect(collection.include?(7)).to be_truthy
109+
expect(collection.include?(7)).to be(true)
110110
end
111111
end
112112
113113
context "with an item that is not in the collection" do
114114
it "returns false" do
115-
expect(collection.include?(9)).to be_falsey
115+
expect(collection.include?(9)).to be(false)
116116
end
117117
end
118118
end

features/hooks/around_hooks.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ Feature: `around` hooks
219219
end
220220
221221
it "runs the example in the correct context" do
222-
expect(included_in_configure_block).to be_truthy
222+
expect(included_in_configure_block).to be(true)
223223
end
224224
end
225225
"""

lib/rspec/core/configuration.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,17 @@ def self.define_reader(name)
6767
end
6868

6969
# @private
70-
def self.define_aliases(name, alias_name)
70+
def self.define_alias(name, alias_name)
7171
alias_method alias_name, name
7272
alias_method "#{alias_name}=", "#{name}="
73-
define_predicate_for alias_name
73+
define_predicate alias_name
7474
end
7575

7676
# @private
77-
def self.define_predicate_for(*names)
78-
names.each { |name| alias_method "#{name}?", name }
77+
def self.define_predicate(name)
78+
define_method "#{name}?" do
79+
!!send(name)
80+
end
7981
end
8082

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

9092
Array(opts[:alias_with]).each do |alias_name|
91-
define_aliases(name, alias_name)
93+
define_alias(name, alias_name)
9294
end
9395
end
9496

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

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

317320
# @macro add_setting
318321
# Run all examples if none match the configured filters

lib/rspec/core/world.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class World
1717
attr_accessor :non_example_failure
1818

1919
def initialize(configuration=RSpec.configuration)
20+
@wants_to_quit = false
2021
@configuration = configuration
2122
configuration.world = self
2223
@example_groups = []

spec/rspec/core/configuration_options_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -296,16 +296,16 @@
296296
end
297297

298298
describe "--fail-fast" do
299-
it "defaults to false" do
300-
expect(parse_options[:fail_fast]).to be_falsey
299+
it "defaults to nil" do
300+
expect(parse_options[:fail_fast]).to be(nil)
301301
end
302302

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

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

@@ -322,12 +322,12 @@
322322
end
323323

324324
describe "--dry-run" do
325-
it "defaults to false" do
326-
expect(parse_options[:dry_run]).to be_falsey
325+
it "defaults to nil" do
326+
expect(parse_options[:dry_run]).to be(nil)
327327
end
328328

329329
it "sets dry_run on config" do
330-
expect(parse_options("--dry-run")[:dry_run]).to be_truthy
330+
expect(parse_options("--dry-run")[:dry_run]).to be(true)
331331
end
332332
end
333333

@@ -464,7 +464,7 @@ def expect_parsing_to_fail_mentioning_source(source, options=[])
464464

465465
expect(options[:requires]).to eq(["some_file"])
466466
expect(options[:full_description]).to eq([/foo\ bar/])
467-
expect(options[:drb]).to be_truthy
467+
expect(options[:drb]).to be(true)
468468
expect(options[:formatters]).to eq([['global']])
469469
end
470470
end

spec/rspec/core/configuration_spec.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def mod.configuration; @config ||= Struct.new(:custom_setting).new; end
293293
mod_config.custom_setting = true
294294
end
295295

296-
expect(mod.configuration.custom_setting).to be_truthy
296+
expect(mod.configuration.custom_setting).to be(true)
297297
end
298298

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

13041304
it "defaults to false" do
1305-
expect(config.run_all_when_everything_filtered?).to be_falsey
1305+
expect(config.run_all_when_everything_filtered?).to be(false)
13061306
end
13071307

13081308
it "can be queried with question method" do
13091309
config.run_all_when_everything_filtered = true
1310-
expect(config.run_all_when_everything_filtered?).to be_truthy
1310+
expect(config.run_all_when_everything_filtered?).to be(true)
13111311
end
13121312
end
13131313

@@ -1779,14 +1779,14 @@ def metadata_hash(*args)
17791779
config_2 = Configuration.new
17801780

17811781
config_1.full_backtrace = true
1782-
expect(config_2.full_backtrace?).to be_falsey
1782+
expect(config_2.full_backtrace?).to be(false)
17831783
end
17841784
end
17851785

17861786
describe "#backtrace_exclusion_patterns=" do
17871787
it "actually receives the new filter values" do
17881788
config.backtrace_exclusion_patterns = [/.*/]
1789-
expect(config.backtrace_formatter.exclude? "this").to be_truthy
1789+
expect(config.backtrace_formatter.exclude? "this").to be(true)
17901790
end
17911791
end
17921792

@@ -1805,7 +1805,7 @@ def metadata_hash(*args)
18051805
describe "#backtrace_exclusion_patterns" do
18061806
it "can be appended to" do
18071807
config.backtrace_exclusion_patterns << /.*/
1808-
expect(config.backtrace_formatter.exclude? "this").to be_truthy
1808+
expect(config.backtrace_formatter.exclude? "this").to be(true)
18091809
end
18101810
end
18111811

@@ -2213,7 +2213,7 @@ def exclude?(line)
22132213
end
22142214

22152215
it "adds a predicate" do
2216-
expect(config.custom_option?).to be_falsey
2216+
expect(config.custom_option?).to be(false)
22172217
end
22182218

22192219
it "can be overridden" do
@@ -2232,7 +2232,7 @@ def exclude?(line)
22322232
end
22332233

22342234
it "returns true for the predicate" do
2235-
expect(config.custom_option?).to be_truthy
2235+
expect(config.custom_option?).to be(true)
22362236
end
22372237

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

22702270
it "delegates the predicate to the other option" do
22712271
config.custom_option = true
2272-
expect(config.another_custom_option?).to be_truthy
2272+
expect(config.another_custom_option?).to be(true)
22732273
end
22742274
end
22752275
end
@@ -2526,11 +2526,11 @@ def example_numbered(num)
25262526
it "forces 'false' value" do
25272527
config.add_setting :custom_option
25282528
config.custom_option = true
2529-
expect(config.custom_option?).to be_truthy
2529+
expect(config.custom_option?).to be(true)
25302530
config.force :custom_option => false
2531-
expect(config.custom_option?).to be_falsey
2531+
expect(config.custom_option?).to be(false)
25322532
config.custom_option = true
2533-
expect(config.custom_option?).to be_falsey
2533+
expect(config.custom_option?).to be(false)
25342534
end
25352535
end
25362536

0 commit comments

Comments
 (0)