Skip to content

Commit

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

* RuboCop: RequireOrder
  • Loading branch information
jgarber623 authored Dec 12, 2023
1 parent 445984f commit 9a405bf
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 25 deletions.
9 changes: 5 additions & 4 deletions lib/webmention/cli.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

require 'thor'
require 'webmention'
require "thor"
require "webmention"

require_relative 'cli/version'
require_relative 'cli/runner'
require_relative "cli/version"

require_relative "cli/runner"
18 changes: 9 additions & 9 deletions lib/webmention/cli/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ module CLI
class Runner < Thor
include Thor::Actions

package_name 'Webmention'
package_name "Webmention"

map ['-v', '--version'] => :version
map ["-v", "--version"] => :version

# :nocov:
def self.exit_on_failure?
true
end
# :nocov:

desc 'endpoint <target>', 'Discover the Webmention endpoint for <target> URL'
desc "endpoint <target>", "Discover the Webmention endpoint for <target> URL"
def endpoint(target)
url = Webmention::Url.new(target)

Expand All @@ -24,30 +24,30 @@ def endpoint(target)
say url.webmention_endpoint
end

desc 'send <source> <target>', 'Send a webmention from <source> URL to <target> URL'
option :vouch, desc: 'Submit a <vouch> URL'
desc "send <source> <target>", "Send a webmention from <source> URL to <target> URL"
option :vouch, desc: "Submit a <vouch> URL"
def send(source, target)
response = Webmention.send_webmention(source, target, vouch: options[:vouch])

exit 1 unless response.ok?

code = response.code
location = response.headers['Location']
location = response.headers["Location"]

say(code == 201 && location ? location : "#{code} #{response.reason}")

exit 1 unless code.between?(200, 299)
end

desc 'verify <source> <target>', 'Verify that <source> URL links to <target> URL'
option :vouch, desc: 'Verify that <vouch> URL mentions the <source> URL domain'
desc "verify <source> <target>", "Verify that <source> URL links to <target> URL"
option :vouch, desc: "Verify that <vouch> URL mentions the <source> URL domain"
def verify(source, target)
verification = Webmention.verify_webmention(source, target, vouch: options[:vouch])

exit 1 unless verification.verified?
end

desc 'version', 'Print version information'
desc "version", "Print version information"
def version
say "webmention-cli version #{Webmention::CLI::VERSION}"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/webmention/cli/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Webmention
module CLI
VERSION = '2.0.0'
VERSION = "2.0.0"
end
end
18 changes: 9 additions & 9 deletions spec/lib/webmention/cli/runner_endpoint_spec.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# frozen_string_literal: true

RSpec.describe Webmention::CLI::Runner, '#endpoint' do
RSpec.describe Webmention::CLI::Runner, "#endpoint" do
subject(:cmd) { described_class.new.endpoint(url) }

let(:url) { 'https://jgarber.example/post/100' }
let(:url) { "https://jgarber.example/post/100" }

context 'when no Webmention endpoint found' do
context "when no Webmention endpoint found" do
before do
stub_request(:get, url).to_return(
body: '<html><body>Hello, world!</body></html>',
body: "<html><body>Hello, world!</body></html>",
headers: {
'Content-Type': 'text/html'
"Content-Type": "text/html"
}
)
end

it 'raises SystemExit' do
it "raises SystemExit" do
expect { cmd }.to raise_error(SystemExit)
end
end

context 'when Webmention endpoint found' do
let(:webmention_endpoint) { 'https://jgarber.example/webmention' }
context "when Webmention endpoint found" do
let(:webmention_endpoint) { "https://jgarber.example/webmention" }

before do
stub_request(:get, url).to_return(
Expand All @@ -31,7 +31,7 @@
)
end

it 'prints the Webmention endpoint' do
it "prints the Webmention endpoint" do
expect { cmd }.to output("#{webmention_endpoint}\n").to_stdout
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/webmention/cli/runner_version_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

RSpec.describe Webmention::CLI::Runner, '#version' do
RSpec.describe Webmention::CLI::Runner, "#version" do
subject(:cmd) { described_class.new.version }

it 'prints version information' do
it "prints version information" do
expect { cmd }.to output("webmention-cli version #{Webmention::CLI::VERSION}\n").to_stdout
end
end

0 comments on commit 9a405bf

Please sign in to comment.