Skip to content

Commit dd87f33

Browse files
committed
Change the expectation for predicate methods
Predicate methods typically return true or false, this is part of an associated bug-fix in rspec/rspec-core#2736 but as rspec-rails is now a separate entity we must account for this ourselves. Note some predicates are here by default settings and may be able to be tidied up in `rspec-rails` 5.
1 parent 9d6986f commit dd87f33

File tree

2 files changed

+52
-16
lines changed

2 files changed

+52
-16
lines changed

lib/rspec/rails/configuration.rb

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,35 @@ def render_views
105105
end
106106

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

111139
def infer_spec_type_from_file_location!

spec/rspec/rails/configuration_spec.rb

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

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

3341
describe "`##{command_method}`" do
34-
it "changes `#{query_method}` to the provided value" do
42+
it "changes `#{predicate_method}` to the true for a truthy value" do
43+
config.send(command_method, nil)
44+
expect(config.send(predicate_method)).to be false
3545
expect {
3646
config.send(command_method, :a_value)
37-
}.to change { config.send(query_method) }.to(:a_value)
47+
}.to change { config.send(predicate_method) }.to(true)
3848
end
3949

4050
it "sets `#{accessor}` to the provided value" do
@@ -72,8 +82,8 @@
7282

7383
include_examples "adds setting", :rendering_views
7484

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

7989
specify "`#render_views` sets `render_views?` to `true`" do
@@ -83,16 +93,14 @@
8393
end
8494

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

0 commit comments

Comments
 (0)