diff --git a/.rubocop.yml b/.rubocop.yml index ba5bb34..4c5ed9b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -24,6 +24,9 @@ Metrics/MethodLength: Style/Documentation: Enabled: false +Style/HashSyntax: + EnforcedShorthandSyntax: never + RSpec/ContextWording: Enabled: false RSpec/ExampleLength: diff --git a/spec/helpers/definition_helper.rb b/spec/helpers/definition_helper.rb index 138514e..2a83b3c 100644 --- a/spec/helpers/definition_helper.rb +++ b/spec/helpers/definition_helper.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true module DefinitionHelper + # rubocop:disable Metrics/AbcSize def simple_definition Slither.define :simple, by_bytes: false do |d| # This is a template section that can be reused in other sections @@ -18,7 +19,7 @@ def simple_definition end d.body do |body| - body.trap { |line| line[0, 4] =~ /[^(HEAD|FOOT)]/ } + body.trap { |line| line[0, 4] =~ /[^(HEAD|FOT)]/ } body.column :id, 10, type: :integer body.column :name, 10, align: :left body.spacer 3 @@ -32,9 +33,10 @@ def simple_definition end end end + # rubocop:enable Metrics/AbcSize def simple_definition_test_data - { + { header: [ { record_type: "HEAD", company_id: "ABC" } ], diff --git a/spec/slither/column_spec.rb b/spec/slither/column_spec.rb index 8e63ed5..8f7092e 100644 --- a/spec/slither/column_spec.rb +++ b/spec/slither/column_spec.rb @@ -192,7 +192,7 @@ let(:options) { { padding: :space } } it "respect the format" do - expect(subject.format(25)).to eq(' 25') + expect(subject.format(25)).to eq(" 25") end end @@ -280,13 +280,13 @@ end context "with format" do - let(:options) { { type: :float, format: "%.3f"} } + let(:options) { { type: :float, format: "%.3f" } } let(:length) { 10 } it "support the type with its format" do expect(subject.format(234.45)).to eq(" 234.450") - expect(subject.format('234.4500')).to eq(" 234.450") - expect(subject.format('3')).to eq(" 3.000") + expect(subject.format("234.4500")).to eq(" 234.450") + expect(subject.format("3")).to eq(" 3.000") end context "alignment and padding" do diff --git a/spec/slither/definition_spec.rb b/spec/slither/definition_spec.rb index f2cfbd6..5cd8602 100644 --- a/spec/slither/definition_spec.rb +++ b/spec/slither/definition_spec.rb @@ -20,7 +20,9 @@ subject { described_class.new } it "defaults to :right if is not specified" do - subject.section("name") {} + subject.section("name") do + # Empty block + end section = subject.sections.first @@ -28,7 +30,9 @@ end it "override default if :align is passed to the section" do - subject.section("name", align: :left) {} + subject.section("name", align: :left) do + # Empty block + end section = subject.sections.first @@ -63,10 +67,14 @@ end it "does not create duplicate section names" do - subject.section(:header) {} + subject.section(:header) do + # Empty block + end expect do - subject.section(:header) {} + subject.section(:header) do + # Empty block + end end.to raise_error(ArgumentError) end @@ -85,12 +93,16 @@ it "create a new section" do expect(Slither::Section).to receive(:new) - subject.template(:row) {} + subject.template(:row) do + # Empty block + end end it "add a section to the templates collection" do expect do - subject.template(:row) {} + subject.template(:row) do + # Empty block + end end.to change { subject.templates.count }.by(1) end diff --git a/spec/slither/generator_spec.rb b/spec/slither/generator_spec.rb index 46bb72c..0491076 100644 --- a/spec/slither/generator_spec.rb +++ b/spec/slither/generator_spec.rb @@ -6,19 +6,19 @@ let(:definition) do Slither.define :test do |d| d.header do |h| - h.trap { |line| line[0,4] == 'HEAD' } + h.trap { |line| line[0, 4] == "HEAD" } h.column :type, 4 h.column :file_id, 10 end d.body do |b| - b.trap { |line| line[0,4] =~ /[^(HEAD|FOOT)]/ } + b.trap { |line| line[0, 4] =~ /[^(HEAD|FOOT)]/ } # rubocop:disable Lint/DuplicateRegexpCharacterClassElement b.column :first, 10 b.column :last, 10 end d.footer do |f| - f.trap { |line| line[0,4] == 'FOOT' } + f.trap { |line| line[0, 4] == "FOOT" } f.column :type, 4 f.column :file_id, 10 end @@ -28,12 +28,12 @@ describe ".generate" do let(:data) do { - :header => [ {:type => "HEAD", :file_id => "1" }], - :body => [ - {:first => "Paul", :last => "Hewson" }, - {:first => "Dave", :last => "Evans" } + header: [{ type: "HEAD", file_id: "1" }], + body: [ + { first: "Paul", last: "Hewson" }, + { first: "Dave", last: "Evans" } ], - :footer => [ {:type => "FOOT", :file_id => "1" }] + footer: [{ type: "FOOT", file_id: "1" }] } end diff --git a/spec/slither/parser_spec.rb b/spec/slither/parser_spec.rb index b8eaa2c..c4d7230 100644 --- a/spec/slither/parser_spec.rb +++ b/spec/slither/parser_spec.rb @@ -192,40 +192,40 @@ describe "private methods" do describe "#remove_new_lines!" do it "returns true for file starting in newlines or EOF" do - expect(subject.send(:remove_newlines!)).to eq(true) + expect(subject.send(:remove_newlines!)).to be(true) io.string = "\nXYZ" - expect(subject.send(:remove_newlines!)).to eq(true) + expect(subject.send(:remove_newlines!)).to be(true) io.string = "\r\n" - expect(subject.send(:remove_newlines!)).to eq(true) + expect(subject.send(:remove_newlines!)).to be(true) io.string = "\n\n\n\nXYZ\n" - expect(subject.send(:remove_newlines!)).to eq(true) + expect(subject.send(:remove_newlines!)).to be(true) io.string = "" - expect(subject.send(:remove_newlines!)).to eq(true) + expect(subject.send(:remove_newlines!)).to be(true) end it "return false for any other first characters" do io.string = "XYZ\nxyz" - expect(subject.send(:remove_newlines!)).to eq(false) + expect(subject.send(:remove_newlines!)).to be(false) io.string = " \nxyz" - expect(subject.send(:remove_newlines!)).to eq(false) + expect(subject.send(:remove_newlines!)).to be(false) io.string = "!YZxyz\n" - expect(subject.send(:remove_newlines!)).to eq(false) + expect(subject.send(:remove_newlines!)).to be(false) end it "leaves first non-newline char in place" do io.string = "\nXYZ" - expect(subject.send(:remove_newlines!)).to eq(true) + expect(subject.send(:remove_newlines!)).to be(true) first_character = io.getc expect(first_character).to eq("X") - expect(subject.send(:remove_newlines!)).to eq(false) + expect(subject.send(:remove_newlines!)).to be(false) end end @@ -233,11 +233,11 @@ it "is true for \n or \r and false otherwise" do ["\n", "\r"].each do |e| # ord = https://apidock.com/rails/String/ord - expect(subject.send(:newline?, e.ord)).to eq(true) + expect(subject.send(:newline?, e.ord)).to be(true) end ["", nil, "meep"].each do |e| - expect(subject.send(:newline?, e)).to eq(false) + expect(subject.send(:newline?, e)).to be(false) end end end diff --git a/spec/slither/section_spec.rb b/spec/slither/section_spec.rb index 312be81..b288505 100644 --- a/spec/slither/section_spec.rb +++ b/spec/slither/section_spec.rb @@ -36,7 +36,7 @@ end.to raise_error(Slither::DuplicateColumnNameError) end - it "should allow duplicate column names that are reserved (i.e. spacer)" do + it "allow duplicate column names that are reserved (i.e. spacer)" do subject.spacer(10) expect do @@ -82,15 +82,15 @@ trap = subject.instance_variable_get(:@trap) expect(trap).to be_a(Proc) - expect(trap.call(4)).to eq(true) + expect(trap.call(4)).to be(true) end end - it "should try to match a line using the trap" do + it "try to match a line using the trap" do subject.trap { |line| line == "hello" } - expect(subject.match("hello")).to eq(true) - expect(subject.match("goodbye")).to eq(false) + expect(subject.match("hello")).to be(true) + expect(subject.match("goodbye")).to be(false) end end @@ -102,8 +102,8 @@ context "when template does not exist" do it "raise an error if the template is not found on the definition" do expect do - subject.template(:none).to raise_error(ArgumentError) - end + subject.template(:none).to + end.to raise_error(ArgumentError) end end @@ -136,7 +136,7 @@ end describe "#format" do - let(:data) { { id: 3, name: "Ryan"} } + let(:data) { { id: 3, name: "Ryan" } } it "transform the 'data' hash to the expected format based on the columns width" do subject.column(:id, 5) @@ -198,6 +198,4 @@ end end end - - end