Skip to content

Commit e5ba05e

Browse files
authored
Merge pull request #2358 from rspec/fix-3-9-maintenance
Backport config changes from 4-0-maintenance
2 parents 39d5343 + b3b1c12 commit e5ba05e

File tree

3 files changed

+69
-18
lines changed

3 files changed

+69
-18
lines changed

Changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
### Development
2+
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v3.9.1...3-9-maintenance)
3+
4+
Bug Fixes:
5+
6+
* Return `true`/`false` from predicate methods in config rather than raw values.
7+
(Phil Pirozhkov, Jon Rowe, #2353, #2354)
8+
19
### 3.9.1 / 2020-03-10
210
[Full Changelog](http://github.com/rspec/rspec-rails/compare/v3.9.0...v3.9.1)
311

lib/rspec/rails/configuration.rb

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# rubocop: disable Metrics/ModuleLength
12
module RSpec
23
module Rails
34
# Fake class to document RSpec Rails configuration options. In practice,
@@ -53,8 +54,7 @@ def self.add_test_type_configurations(config)
5354
end
5455

5556
# @private
56-
# rubocop:disable Style/MethodLength
57-
def self.initialize_configuration(config)
57+
def self.initialize_configuration(config) # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity
5858
config.backtrace_exclusion_patterns << /vendor\//
5959
config.backtrace_exclusion_patterns << %r{lib/rspec/rails}
6060

@@ -103,7 +103,41 @@ def render_views
103103
end
104104

105105
def render_views?
106-
rendering_views
106+
rendering_views?
107+
end
108+
109+
undef :rendering_views? if respond_to?(:rendering_views?)
110+
def rendering_views?
111+
!!rendering_views
112+
end
113+
114+
# Define boolean predicates rather than relying on rspec-core due
115+
# to the bug fix in rspec/rspec-core#2736, note some of these
116+
# predicates are a bit nonsensical, but they exist for backwards
117+
# compatibility, we can tidy these up in `rspec-rails` 5.
118+
undef :fixture_path? if respond_to?(:fixture_path?)
119+
def fixture_path?
120+
!!fixture_path
121+
end
122+
123+
undef :global_fixtures? if respond_to?(:global_fixtures?)
124+
def global_fixtures?
125+
!!global_fixtures
126+
end
127+
128+
undef :infer_base_class_for_anonymous_controllers? if respond_to?(:infer_base_class_for_anonymous_controllers?)
129+
def infer_base_class_for_anonymous_controllers?
130+
!!infer_base_class_for_anonymous_controllers
131+
end
132+
133+
undef :use_instantiated_fixtures? if respond_to?(:use_instantiated_fixtures?)
134+
def use_instantiated_fixtures?
135+
!!use_instantiated_fixtures
136+
end
137+
138+
undef :use_transactional_fixtures? if respond_to?(:use_transactional_fixtures?)
139+
def use_transactional_fixtures?
140+
!!use_transactional_fixtures
107141
end
108142

109143
def infer_spec_type_from_file_location!
@@ -146,3 +180,4 @@ def filter_rails_from_backtrace!
146180
initialize_configuration RSpec.configuration
147181
end
148182
end
183+
# rubocop: enable Metrics/ModuleLength

spec/rspec/rails/configuration_spec.rb

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,28 @@
2424
opts ||= {}
2525
default_value = opts[:default]
2626
alias_setting = opts[:alias_with]
27-
query_method = "#{accessor}?".to_sym
27+
predicate_method = "#{accessor}?".to_sym
2828
command_method = "#{accessor}=".to_sym
2929

30-
specify "`##{query_method}` is `#{default_value.inspect}` by default" do
31-
expect(config.send(query_method)).to be(default_value)
30+
specify "`##{accessor}` is `#{default_value.inspect}` by default" do
31+
expect(config.send(accessor)).to eq default_value
32+
end
33+
34+
specify "`##{predicate_method}` is `#{!!default_value}` by default" do
35+
expect(config.send(predicate_method)).to be !!default_value
36+
end
37+
38+
specify "`##{predicate_method}` is `#{!!default_value}` by default" do
39+
expect(config.send(predicate_method)).to be !!default_value
3240
end
3341

3442
describe "`##{command_method}`" do
35-
it "changes `#{query_method}` to the provided value" do
43+
it "changes `#{predicate_method}` to the true for a truthy value" do
44+
config.send(command_method, nil)
45+
expect(config.send(predicate_method)).to be false
3646
expect {
3747
config.send(command_method, :a_value)
38-
}.to change { config.send(query_method) }.to(:a_value)
48+
}.to change { config.send(predicate_method) }.to(true)
3949
end
4050

4151
it "sets `#{accessor}` to the provided value" do
@@ -73,8 +83,8 @@
7383

7484
include_examples "adds setting", :rendering_views
7585

76-
specify "`#render_views?` is falsey by default" do
77-
expect(config.render_views?).to be_falsey
86+
specify "`#render_views?` is false by default" do
87+
expect(config.render_views?).to be false
7888
end
7989

8090
specify "`#render_views` sets `render_views?` to `true`" do
@@ -84,16 +94,14 @@
8494
end
8595

8696
describe "`#render_views=`" do
87-
it "sets `render_views?` to the provided value" do
88-
expect {
89-
config.render_views = false
90-
}.to change { config.render_views? }.from(nil).to(false)
91-
end
92-
93-
it "sets `render_views` to the provided value" do
97+
it "sets `render_views?` to the truthyness of the provided value" do
9498
expect {
9599
config.render_views = :a_value
96-
}.to change { config.render_views? }.to(:a_value)
100+
}.to change { config.render_views? }.from(false).to(true)
101+
# this is repeated to put the value back to false
102+
expect {
103+
config.render_views = false
104+
}.to change { config.render_views? }.from(true).to(false)
97105
end
98106
end
99107
end

0 commit comments

Comments
 (0)