-
Notifications
You must be signed in to change notification settings - Fork 23
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
1 parent
989f1f8
commit 7f46431
Showing
12 changed files
with
188 additions
and
19 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
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
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
# :nocov: | ||
module Ruby | ||
module Enum | ||
## | ||
# Mock I18n module in case the i18n gem is not available. | ||
module I18nMock | ||
def self.load_path | ||
[] | ||
end | ||
|
||
def self.translate(key, _options = {}) | ||
key | ||
end | ||
end | ||
end | ||
end | ||
# :nocov: |
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
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
source 'http://rubygems.org' | ||
|
||
gemspec path: '../' | ||
|
||
# This Gemfile should not include any gem that has i18n as a dependency. | ||
gem 'rake' | ||
gem 'rspec', '~> 3.0' |
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,52 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
test_class = Class.new do | ||
include Ruby::Enum | ||
|
||
define :RED, 'red' | ||
define :GREEN, 'green' | ||
end | ||
|
||
describe Ruby::Enum do | ||
context 'when the i18n gem is not loaded' do | ||
it 'raises UninitializedConstantError on an invalid constant' do | ||
expect do | ||
test_class::ANYTHING | ||
end.to raise_error Ruby::Enum::Errors::UninitializedConstantError, /ruby.enum.errors.messages.uninitialized_constant.summary/ | ||
end | ||
end | ||
|
||
context 'when a duplicate key is used' do | ||
context 'when the i18n gem is not loaded' do | ||
before do | ||
allow(described_class).to receive(:i18n).and_return(Ruby::Enum::I18nMock) | ||
end | ||
|
||
it 'raises DuplicateKeyError' do | ||
expect do | ||
test_class.class_eval do | ||
define :RED, 'some' | ||
end | ||
end.to raise_error Ruby::Enum::Errors::DuplicateKeyError, /ruby.enum.errors.messages.duplicate_key.message/ | ||
end | ||
end | ||
end | ||
|
||
context 'when a duplicate value is used' do | ||
context 'when the i18n gem is not loaded' do | ||
before do | ||
allow(described_class).to receive(:i18n).and_return(Ruby::Enum::I18nMock) | ||
end | ||
|
||
it 'raises a DuplicateValueError' do | ||
expect do | ||
test_class.class_eval do | ||
define :Other, 'red' | ||
end | ||
end.to raise_error Ruby::Enum::Errors::DuplicateValueError, /ruby.enum.errors.messages.duplicate_value.summary/ | ||
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,8 @@ | ||
# frozen_string_literal: true | ||
|
||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib')) | ||
|
||
require 'rubygems' | ||
|
||
require 'rspec' | ||
require 'ruby-enum' |