Skip to content

Commit

Permalink
[expectations] Merge pull request rspec/rspec-expectations#1193 from …
Browse files Browse the repository at this point in the history
…reshleman/re-expected-hash

Improve Hash formatting in `EnglishPhrasing.list`

---
This commit was imported from rspec/rspec-expectations@08d44a3.
  • Loading branch information
JonRowe committed Jun 14, 2020
1 parent f894da1 commit c7a309f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rspec-expectations/lib/rspec/matchers/english_phrasing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def self.split_words(sym)
# list([]) #=> ""
#
def self.list(obj)
return " #{RSpec::Support::ObjectFormatter.format(obj)}" if !obj || Struct === obj
return " #{RSpec::Support::ObjectFormatter.format(obj)}" if !obj || Struct === obj || Hash === obj
items = Array(obj).map { |w| RSpec::Support::ObjectFormatter.format(w) }
case items.length
when 0
Expand Down
11 changes: 10 additions & 1 deletion rspec-expectations/spec/rspec/matchers/english_phrasing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ module Matchers
end
end

context "given an Enumerable" do
context "given a Hash" do
it "returns value from inspect, and a leading space" do
banana = { :flavor => 'Banana' }
expect(
described_class.list(banana)
).to eq(" #{banana.inspect}")
end
end

context "given an Enumerable other than a Hash" do
before do
allow(RSpec::Support::ObjectFormatter).to(
receive(:format).and_return("Banana")
Expand Down

0 comments on commit c7a309f

Please sign in to comment.