Skip to content

Commit

Permalink
Address RuboCop Style/StringLiterals warnings' (#73)
Browse files Browse the repository at this point in the history
* RuboCop: Style/StringLiterals

* RuboCop: Style/StringLiterals
  • Loading branch information
jgarber623 authored Dec 9, 2023
1 parent 1ce9fab commit 3fb3cf4
Show file tree
Hide file tree
Showing 17 changed files with 211 additions and 117 deletions.
2 changes: 1 addition & 1 deletion .simplecov
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
formatters = SimpleCov::Formatter.from_env(ENV)

if RSpec.configuration.files_to_run.length > 1
require 'simplecov-console'
require "simplecov-console"

formatters << SimpleCov::Formatter::Console
end
Expand Down
24 changes: 12 additions & 12 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# frozen_string_literal: true

source 'https://rubygems.org'
source "https://rubygems.org"

# Specify your gem's dependencies in micromicro.gemspec
gemspec

gem 'debug'
gem 'rake'
gem 'rspec'
gem 'rspec-its'
gem 'rubocop'
gem 'rubocop-packaging'
gem 'rubocop-performance'
gem 'rubocop-rake'
gem 'rubocop-rspec'
gem 'simplecov'
gem 'simplecov-console'
gem "debug"
gem "rake"
gem "rspec"
gem "rspec-its"
gem "rubocop"
gem "rubocop-packaging"
gem "rubocop-performance"
gem "rubocop-rake"
gem "rubocop-rspec"
gem "simplecov"
gem "simplecov-console"
5 changes: 2 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'

require 'rspec/core/rake_task'
require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new

Expand Down
34 changes: 17 additions & 17 deletions micromicro.gemspec
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
# frozen_string_literal: true

require_relative 'lib/micro_micro/version'
require_relative "lib/micro_micro/version"

Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 3.0', '< 4'
spec.required_ruby_version = ">= 3.0", "< 4"

spec.name = 'micromicro'
spec.name = "micromicro"
spec.version = MicroMicro::VERSION
spec.authors = ['Jason Garber']
spec.email = ['jason@sixtwothree.org']
spec.authors = ["Jason Garber"]
spec.email = ["jason@sixtwothree.org"]

spec.summary = 'Extract microformats2-encoded data from HTML documents.'
spec.summary = "Extract microformats2-encoded data from HTML documents."
spec.description = spec.summary
spec.homepage = 'https://github.com/jgarber623/micromicro'
spec.license = 'MIT'
spec.homepage = "https://github.com/jgarber623/micromicro"
spec.license = "MIT"

spec.files = Dir['lib/**/*'].reject { |f| File.directory?(f) }
spec.files += %w[LICENSE CHANGELOG.md CONTRIBUTING.md README.md]
spec.files = Dir["lib/**/*"].reject { |f| File.directory?(f) }
spec.files += %w[LICENSE CHANGELOG.md README.md]
spec.files += %w[micromicro.gemspec]

spec.require_paths = ['lib']
spec.require_paths = ["lib"]

spec.metadata = {
'bug_tracker_uri' => "#{spec.homepage}/issues",
'changelog_uri' => "#{spec.homepage}/blob/v#{spec.version}/CHANGELOG.md",
'rubygems_mfa_required' => 'true'
"bug_tracker_uri" => "#{spec.homepage}/issues",
"changelog_uri" => "#{spec.homepage}/blob/v#{spec.version}/CHANGELOG.md",
"rubygems_mfa_required" => "true"
}

spec.add_runtime_dependency 'activesupport', '~> 7.0'
spec.add_runtime_dependency 'nokogiri', '>= 1.14'
spec.add_runtime_dependency 'nokogiri-html-ext', '~> 0.4.0'
spec.add_runtime_dependency "activesupport", "~> 7.0"
spec.add_runtime_dependency "nokogiri", ">= 1.14"
spec.add_runtime_dependency "nokogiri-html-ext", "~> 0.4.0"
end
28 changes: 14 additions & 14 deletions spec/lib/micro_micro/collections/items_collection_find_by_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

RSpec.describe MicroMicro::Collections::ItemsCollection, '#find_by' do
let(:base_url) { 'https://jgarber.example' }
RSpec.describe MicroMicro::Collections::ItemsCollection, "#find_by" do
let(:base_url) { "https://jgarber.example" }

let(:document) { MicroMicro.parse(markup, base_url) }

Expand All @@ -23,35 +23,35 @@
HTML
end

context 'when given neither params nor a block' do
context "when given neither params nor a block" do
subject(:item) { items.find_by }

it { is_expected.to eq(item) }
end

context 'when no match' do
subject(:item) { items.find_by(types: ['h-event']) }
context "when no match" do
subject(:item) { items.find_by(types: ["h-event"]) }

it { is_expected.to be_nil }
end

context 'when given Hash params' do
context 'when value is a String' do
subject(:item) { items.find_by(types: 'h-card') }
context "when given Hash params" do
context "when value is a String" do
subject(:item) { items.find_by(types: "h-card") }

its(:id) { is_expected.to eq('card-1') }
its(:id) { is_expected.to eq("card-1") }
end

context 'when value is an Array' do
context "when value is an Array" do
subject(:item) { items.find_by(types: %w[h-entry h-card]) }

its(:id) { is_expected.to eq('post-1') }
its(:id) { is_expected.to eq("post-1") }
end
end

context 'when given a block' do
subject(:item) { items.find_by { |item| item.id == 'post-2' } }
context "when given a block" do
subject(:item) { items.find_by { |item| item.id == "post-2" } }

its(:id) { is_expected.to eq('post-2') }
its(:id) { is_expected.to eq("post-2") }
end
end
4 changes: 2 additions & 2 deletions spec/lib/micro_micro/collections/items_collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RSpec.describe MicroMicro::Collections::ItemsCollection do
subject(:items_collection) { MicroMicro.parse(markup, base_url).items }

let(:base_url) { 'http://example.com' }
let(:base_url) { "http://example.com" }

let(:markup) do
<<~HTML.chomp
Expand All @@ -13,5 +13,5 @@
HTML
end

its(:types) { is_expected.to eq(['h-entry']) }
its(:types) { is_expected.to eq(["h-entry"]) }
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

RSpec.describe MicroMicro::Collections::PropertiesCollection, '#find_by' do
let(:base_url) { 'https://jgarber.example' }
RSpec.describe MicroMicro::Collections::PropertiesCollection, "#find_by" do
let(:base_url) { "https://jgarber.example" }

let(:document) { MicroMicro.parse(markup, base_url) }

Expand All @@ -18,43 +18,43 @@
HTML
end

context 'when given neither params nor a block' do
context "when given neither params nor a block" do
subject(:property) { properties.find_by }

it { is_expected.to eq(property) }
end

context 'when no match' do
subject(:property) { properties.find_by(name: ['foo']) }
context "when no match" do
subject(:property) { properties.find_by(name: ["foo"]) }

it { is_expected.to be_nil }
end

context 'when given Hash params' do
context 'when value is a String' do
subject(:property) { properties.find_by(name: 'url') }
context "when given Hash params" do
context "when value is a String" do
subject(:property) { properties.find_by(name: "url") }

its(:value) { is_expected.to eq('https://jgarber.example/posts/hello-world') }
its(:value) { is_expected.to eq("https://jgarber.example/posts/hello-world") }
end

context 'when value is an Array' do
context "when value is an Array" do
subject(:property) { properties.find_by(name: %w[author name]) }

its(:value) { is_expected.to eq('Hello, world!') }
its(:value) { is_expected.to eq("Hello, world!") }
end
end

context 'when given a block' do
context "when given a block" do
subject(:property) { properties.find_by { |property| property.value.is_a?(Hash) } }

let(:matched_value) do
{
properties: {
name: ['Jason Garber'],
url: ['https://jgarber.example/']
name: ["Jason Garber"],
url: ["https://jgarber.example/"]
},
type: ['h-card'],
value: 'Jason Garber'
type: ["h-card"],
value: "Jason Garber"
}
end

Expand Down
12 changes: 6 additions & 6 deletions spec/lib/micro_micro/collections/properties_collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RSpec.describe MicroMicro::Collections::PropertiesCollection do
subject(:collection) { MicroMicro.parse(markup, base_url).items.first.properties }

let(:base_url) { 'http://example.com' }
let(:base_url) { "http://example.com" }

let(:markup) do
<<~HTML.chomp
Expand All @@ -21,20 +21,20 @@
its(:values) do
is_expected.to eq(
[
'Hello, world!',
'https://jgarber.example/posts/hello-world',
{ properties: { name: ['Jason Garber'], url: ['https://jgarber.example/'] }, type: ['h-card'], value: 'Jason Garber' }
"Hello, world!",
"https://jgarber.example/posts/hello-world",
{ properties: { name: ["Jason Garber"], url: ["https://jgarber.example/"] }, type: ["h-card"], value: "Jason Garber" }
]
)
end

its(:plain_text_properties) { is_expected.to be_a(described_class) }
its('plain_text_properties.first.name') { is_expected.to eq('name') }
its("plain_text_properties.first.name") { is_expected.to eq("name") }

its(:plain_text_properties?) { is_expected.to be(true) }

its(:url_properties) { is_expected.to be_a(described_class) }
its('url_properties.first.name') { is_expected.to eq('url') }
its("url_properties.first.name") { is_expected.to eq("url") }

its(:url_properties?) { is_expected.to be(true) }
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

RSpec.describe MicroMicro::Collections::RelationshipsCollection, '#find_by' do
let(:base_url) { 'https://jgarber.example' }
RSpec.describe MicroMicro::Collections::RelationshipsCollection, "#find_by" do
let(:base_url) { "https://jgarber.example" }

let(:document) { MicroMicro.parse(markup, base_url) }

Expand All @@ -15,35 +15,35 @@
HTML
end

context 'when given neither params nor a block' do
context "when given neither params nor a block" do
subject(:relationship) { relationships.find_by }

it { is_expected.to eq(relationship) }
end

context 'when no match' do
subject(:relationship) { relationships.find_by(rels: ['foo']) }
context "when no match" do
subject(:relationship) { relationships.find_by(rels: ["foo"]) }

it { is_expected.to be_nil }
end

context 'when given Hash params' do
context 'when value is a String' do
subject(:relationship) { relationships.find_by(rels: 'home') }
context "when given Hash params" do
context "when value is a String" do
subject(:relationship) { relationships.find_by(rels: "home") }

its(:rels) { is_expected.to eq(['home']) }
its(:rels) { is_expected.to eq(["home"]) }
end

context 'when value is an Array' do
context "when value is an Array" do
subject(:relationship) { relationships.find_by(rels: %w[me webmention]) }

its(:rels) { is_expected.to eq(['webmention']) }
its(:rels) { is_expected.to eq(["webmention"]) }
end
end

context 'when given a block' do
context "when given a block" do
subject(:relationship) { relationships.find_by { |rel| rel.text.match?(/\sGarber\Z/) } }

its(:rels) { is_expected.to eq(['me']) }
its(:rels) { is_expected.to eq(["me"]) }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
RSpec.describe MicroMicro::Collections::RelationshipsCollection do
subject(:collection) { MicroMicro.parse(markup, base_url).relationships }

let(:base_url) { 'http://example.com' }
let(:base_url) { "http://example.com" }

let(:markup) { '<a href="http://example.com/home" rel="home">Back home</a>' }
let(:markup) { %(<a href="http://example.com/home" rel="home">Back home</a>) }

its(:rels) { is_expected.to eq(['home']) }
its(:rels) { is_expected.to eq(["home"]) }

its(:urls) { is_expected.to eq(['http://example.com/home']) }
its(:urls) { is_expected.to eq(["http://example.com/home"]) }
end
4 changes: 2 additions & 2 deletions spec/lib/micro_micro/document_to_h_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

RSpec.describe MicroMicro::Document, '#to_h' do
let(:base_url) { 'http://example.com' }
RSpec.describe MicroMicro::Document, "#to_h" do
let(:base_url) { "http://example.com" }

FixturesHelpers::MicroformatsTestSuite.test_case_file_paths.each do |test_case_file_path|
context "when parsing #{test_case_file_path.match(%r{((?:[^/]+/){2}[^/]+)\.json$})[1]}.html" do
Expand Down
10 changes: 5 additions & 5 deletions spec/lib/micro_micro/parsers/date_time_parser_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# frozen_string_literal: true

RSpec.describe MicroMicro::Parsers::DateTimeParser do
describe '#normalized_ordinal_date' do
subject(:parser) { described_class.new('2022-174') }
describe "#normalized_ordinal_date" do
subject(:parser) { described_class.new("2022-174") }

its(:normalized_ordinal_date) { is_expected.to eq('2022-174') }
its(:normalized_ordinal_date) { is_expected.to eq("2022-174") }
end

describe '#values' do
subject(:parser) { described_class.new('') }
describe "#values" do
subject(:parser) { described_class.new("") }

its(:values) { is_expected.to eq({}) }
end
Expand Down
Loading

0 comments on commit 3fb3cf4

Please sign in to comment.