diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..d62c32c --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,11 @@ +require: rubocop-rspec + +Metrics/LineLength: + Max: 100 + +Style/BlockComments: + Exclude: + - 'spec/spec_helper.rb' + +Layout/EndOfLine: + EnforcedStyle: lf # enforce LF line endings on all platforms diff --git a/Rakefile b/Rakefile index 51c4f2e..34cd9a8 100644 --- a/Rakefile +++ b/Rakefile @@ -6,6 +6,9 @@ Gem::Tasks.new require 'rspec/core/rake_task' RSpec::Core::RakeTask.new +require 'rubocop/rake_task' +RuboCop::RakeTask.new + Rake::ExtensionTask.new 'clocale' do |ext| ext.lib_dir = 'lib/clocale' end @@ -17,4 +20,4 @@ task test: %w[compile] do end task spec: :compile -task default: :spec +task default: %i[spec rubocop] diff --git a/clocale.gemspec b/clocale.gemspec index 852b0a3..2c51581 100644 --- a/clocale.gemspec +++ b/clocale.gemspec @@ -3,19 +3,21 @@ Gem::Specification.new do |spec| spec.version = '0.0.3' spec.authors = ['Claudio Bley'] spec.email = ['claudio.bley@gmail.com'] - spec.summary = "A Ruby gem that wraps C locale functions." + spec.summary = 'A Ruby gem that wraps C locale functions.' spec.homepage = 'https://github.com/avdv/clocale' spec.license = 'MIT' spec.extensions = %w[ext/clocale/extconf.rb] spec.files = `git ls-files -z`.split("\x0").reject do |f| - f.match(%r{^.gitignore}) + f.match(/^.gitignore/) end spec.add_development_dependency 'codecov', '~> 0.1.10' spec.add_development_dependency 'rake', '~> 12.3' spec.add_development_dependency 'rake-compiler', '~> 1.0' spec.add_development_dependency 'rspec', '~> 3.7' + spec.add_development_dependency 'rubocop', '~> 0.58' + spec.add_development_dependency 'rubocop-rspec', '~> 1.27' spec.add_development_dependency 'rubygems-tasks', '~> 0.2' end diff --git a/ext/clocale/extconf.rb b/ext/clocale/extconf.rb index ab859ef..a7faf26 100644 --- a/ext/clocale/extconf.rb +++ b/ext/clocale/extconf.rb @@ -2,7 +2,7 @@ def check_functions %w[setlocale strcoll strxfrm].each do |func| - abort "missing function `#{ func }``" unless have_func func + abort "missing function `#{func}``" unless have_func func end end diff --git a/lib/clocale.rb b/lib/clocale.rb index 91a14a1..46ff4fc 100644 --- a/lib/clocale.rb +++ b/lib/clocale.rb @@ -1,2 +1 @@ - require 'clocale/clocale' diff --git a/spec/c_locale_spec.rb b/spec/c_locale_spec.rb new file mode 100644 index 0000000..6573c66 --- /dev/null +++ b/spec/c_locale_spec.rb @@ -0,0 +1,17 @@ +require 'clocale' + +RSpec.describe CLocale do + %i[LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC LC_TIME].each do |const| + it "has #{const} constant" do + is_expected.to(satisfy { |m| m.const_defined? const }) + end + end + + it 'can call setlocale' do + expect { described_class.setlocale(CLocale::LC_ALL, '') }.not_to raise_error + end + + it 'raises an error with invalid locales' do + expect { described_class.setlocale(CLocale::LC_COLLATE, 'FOOBAR') }.to raise_error(RuntimeError) + end +end diff --git a/spec/clocale_spec.rb b/spec/clocale_spec.rb deleted file mode 100644 index f140efd..0000000 --- a/spec/clocale_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'clocale' - -RSpec.describe CLocale do - context 'module' do - %i(LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC LC_TIME).each do |const| - it "has #{const} constant" do - expect(subject).to be_const_defined const - end - end - - it 'setlocale' do - expect { subject.setlocale(CLocale::LC_ALL, '') }.not_to raise_error - end - end -end