-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Kangaru | ||
module Patches | ||
module Inflections | ||
refine String do | ||
def to_class_name | ||
Inflectors::ClassInflector.inflect(self) | ||
end | ||
|
||
def to_constant_name | ||
Inflectors::ConstantInflector.inflect(self) | ||
end | ||
end | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Kangaru | ||
module Patches | ||
module Inflections : String | ||
class ::String | ||
def to_class_name: -> String | ||
|
||
def to_constant_name: -> String | ||
end | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
RSpec.describe Kangaru::Patches::Inflections do | ||
using described_class | ||
|
||
describe String do | ||
subject(:string) { "foo/bar/baz" } | ||
|
||
shared_examples :delegates_to_inflector do |options| | ||
let(:inflector_class) { options[:inflector] } | ||
|
||
let(:inflector) { instance_double(inflector_class, inflect: "output") } | ||
|
||
before do | ||
allow(inflector_class).to receive(:new).and_return(inflector) | ||
end | ||
|
||
it "instantiates a #{options[:inflector]}" do | ||
subject | ||
expect(inflector_class).to have_received(:new).with(string).once | ||
end | ||
|
||
it "inflects and returns the output" do | ||
expect(subject).to eq(inflector.inflect) | ||
end | ||
end | ||
|
||
describe "#to_class_name" do | ||
subject(:class_name) { string.to_class_name } | ||
|
||
include_examples :delegates_to_inflector, | ||
inflector: Kangaru::Inflectors::ClassInflector | ||
end | ||
|
||
describe "#to_constant_name" do | ||
subject(:constant_name) { string.to_constant_name } | ||
|
||
include_examples :delegates_to_inflector, | ||
inflector: Kangaru::Inflectors::ConstantInflector | ||
end | ||
end | ||
end |