Skip to content

Commit

Permalink
Merge de3e3b1 into 59523d0
Browse files Browse the repository at this point in the history
  • Loading branch information
ochaochaocha3 committed Jul 25, 2019
2 parents 59523d0 + de3e3b1 commit fae9fc1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 27 deletions.
6 changes: 2 additions & 4 deletions lib/rgrb/plugin/random_generator/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ def list
end.keys.sort
end

private

# 表から値を取得して返す
# @param [String] table_name 表名
# @param [Boolean] root 最初に参照する表の場合 true にする
Expand Down Expand Up @@ -162,7 +160,7 @@ def load_data(glob_pattern)
end

# 表が存在することを確かめる
# @return [String] table_name 表名
# @param [String] table_name 表名
# @return [true] 表が存在する場合
# @raise [TableNotFound] 表が存在しない場合
def check_existence_of(table_name)
Expand All @@ -172,7 +170,7 @@ def check_existence_of(table_name)
end

# 表が公開されていることを確かめる
# @return [String] table_name 表名
# @param [String] table_name 表名
# @return [true] 表が公開されている場合
# @raise [PrivateTable] 表が公開されていない場合
def check_permission_of(table_name)
Expand Down
40 changes: 20 additions & 20 deletions spec/rgrb/plugin/random_generator/generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
require 'rgrb/plugin/random_generator/generator'

describe RGRB::Plugin::RandomGenerator::Generator do
let(:generator) do
obj = described_class.new
obj.send(:load_data, "#{__dir__}/data/*.yaml")
obj.send(:logger=, Lumberjack::Logger.new($stdout, progname: self.class.to_s))
let(:generator) {
g = described_class.new
g.logger = Lumberjack::Logger.new($stdout, progname: self.class.to_s)
g.load_data("#{__dir__}/data/*.yaml")

obj
end
g
}

describe '#desc' do
context 'hiragana' do
Expand All @@ -33,14 +33,14 @@
end
end

describe '#japanese_date (private)' do
describe '#japanese_date' do
context '2014-12-31' do
subject { generator.send(:japanese_date, Date.new(2014, 12, 31)) }
subject { generator.japanese_date(Date.new(2014, 12, 31)) }
it { should eq('2014年12月31日') }
end

context '2015-04-01' do
subject { generator.send(:japanese_date, Date.new(2015, 4, 1)) }
subject { generator.japanese_date(Date.new(2015, 4, 1)) }
it { should eq('2015年4月1日') }
end
end
Expand All @@ -64,9 +64,9 @@
end
end

describe '#get_value_from (private)' do
describe '#get_value_from' do
shared_examples 'one line' do
subject { generator.send(:get_value_from, table) }
subject { generator.get_value_from(table) }
it { should eq(expected_text) }
end

Expand All @@ -93,14 +93,14 @@

context '存在しない表の名前が指定された場合' do
it 'TableNotFound エラーが発生する' do
expect { generator.send(:get_value_from, 'none') }.
expect { generator.get_value_from('none') }.
to raise_error(RGRB::Plugin::RandomGenerator::TableNotFound)
end
end

context '最初に非公開の表から引こうとした場合' do
it 'PrivateTable エラーが発生する' do
expect { generator.send(:get_value_from, 'HA06pretty', true) }.
expect { generator.get_value_from('HA06pretty', true) }.
to raise_error(RGRB::Plugin::RandomGenerator::PrivateTable)
end
end
Expand All @@ -109,31 +109,31 @@
it '100 回取り出したとき、値がすべて同じではない' do
table = 'hiraganarand'
results = Array.new(100) do
generator.send(:get_value_from, table)
generator.get_value_from(table)
end

expect(results.uniq.length).to be > 1
end
end
end

describe '#replace_var_with_value (private)' do
describe '#replace_var_with_value' do
shared_examples 'correctly replaced' do |root_table, result|
it %Q("#{result}" に置換される) do
data = generator.
instance_variable_get(:@table)[root_table].
instance_variable_get(:@values)
from = data.first
expect(generator.send(:replace_var_with_value, from, root_table)).
expect(generator.replace_var_with_value(from, root_table)).
to eq(result)
end
end

shared_examples 'raise error' do |root_table, error_class|
error_class_name = error_class.name.split('::').last
it "#{error_class_name} エラーが発生する" do
from = generator.send(:get_value_from, root_table)
expect { generator.send(:replace_var_with_value, from, root_table) }.
from = generator.get_value_from(root_table)
expect { generator.replace_var_with_value(from, root_table) }.
to raise_error(error_class)
end
end
Expand All @@ -153,9 +153,9 @@
context 'hiraganarand2' do
it '100 回取り出したとき、値がすべて同じではない' do
table = 'hiraganarand2'
from = generator.send(:get_value_from, table)
from = generator.get_value_from(table)
results = Array.new(100) do
generator.send(:replace_var_with_value, from, table)
generator.replace_var_with_value(from, table)
end

expect(results.uniq.length).to be > 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
}

let(:mail_generator) {
obj = described_class.new
obj.send(:logger=, Lumberjack::Logger.new($stdout, progname: self.class.to_s))
g = described_class.new
g.logger = Lumberjack::Logger.new($stdout, progname: self.class.to_s)

obj
g
}

describe '#initialize' do
Expand Down

0 comments on commit fae9fc1

Please sign in to comment.