Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
2 changed files
with
52 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,18 +23,28 @@ | |
opts ||= {} | ||
default_value = opts[:default] | ||
alias_setting = opts[:alias_with] | ||
query_method = "#{accessor}?".to_sym | ||
predicate_method = "#{accessor}?".to_sym | ||
command_method = "#{accessor}=".to_sym | ||
|
||
specify "`##{query_method}` is `#{default_value.inspect}` by default" do | ||
expect(config.send(query_method)).to be(default_value) | ||
specify "`##{accessor}` is `#{default_value.inspect}` by default" do | ||
expect(config.send(accessor)).to eq default_value | ||
end | ||
|
||
specify "`##{predicate_method}` is `#{!!default_value}` by default" do | ||
expect(config.send(predicate_method)).to be !!default_value | ||
end | ||
|
||
specify "`##{predicate_method}` is `#{!!default_value}` by default" do | ||
expect(config.send(predicate_method)).to be !!default_value | ||
end | ||
|
||
describe "`##{command_method}`" do | ||
it "changes `#{query_method}` to the provided value" do | ||
it "changes `#{predicate_method}` to the true for a truthy value" do | ||
config.send(command_method, nil) | ||
expect(config.send(predicate_method)).to be false | ||
This comment has been minimized.
Sorry, something went wrong.
pirj
Author
Member
|
||
expect { | ||
config.send(command_method, :a_value) | ||
}.to change { config.send(query_method) }.to(:a_value) | ||
}.to change { config.send(predicate_method) }.to(true) | ||
end | ||
|
||
it "sets `#{accessor}` to the provided value" do | ||
|
@@ -72,8 +82,8 @@ | |
|
||
include_examples "adds setting", :rendering_views | ||
|
||
specify "`#render_views?` is falsey by default" do | ||
expect(config.render_views?).to be_falsey | ||
specify "`#render_views?` is false by default" do | ||
expect(config.render_views?).to be false | ||
end | ||
|
||
specify "`#render_views` sets `render_views?` to `true`" do | ||
|
@@ -83,16 +93,14 @@ | |
end | ||
|
||
describe "`#render_views=`" do | ||
it "sets `render_views?` to the provided value" do | ||
expect { | ||
config.render_views = false | ||
}.to change { config.render_views? }.from(nil).to(false) | ||
end | ||
|
||
it "sets `render_views` to the provided value" do | ||
it "sets `render_views?` to the truthyness of the provided value" do | ||
expect { | ||
config.render_views = :a_value | ||
}.to change { config.render_views? }.to(:a_value) | ||
}.to change { config.render_views? }.from(false).to(true) | ||
# this is repeated to put the value back to false | ||
expect { | ||
config.render_views = false | ||
}.to change { config.render_views? }.from(true).to(false) | ||
end | ||
end | ||
end | ||
|
👍