From d40b8699048cd35a1823eeb41243a34c1233f8a2 Mon Sep 17 00:00:00 2001 From: Luca Guidi Date: Sun, 18 Oct 2020 08:40:12 +0200 Subject: [PATCH] Rubocop Hanami dry-rb rules (1.3) (#86) --- .drone.yml | 177 ------------------ Gemfile | 16 +- README.md | 3 +- bin/console | 7 +- hanami-mailer.gemspec | 41 ++-- lib/hanami-mailer.rb | 4 +- lib/hanami/mailer.rb | 35 ++-- lib/hanami/mailer/configuration.rb | 16 +- lib/hanami/mailer/dsl.rb | 6 +- lib/hanami/mailer/rendering/template_name.rb | 8 +- .../mailer/rendering/templates_finder.rb | 12 +- lib/hanami/mailer/template.rb | 4 +- lib/hanami/mailer/version.rb | 4 +- script/ci | 10 +- spec/spec_helper.rb | 2 + spec/support/fixtures.rb | 58 +++--- spec/unit/hanami/mailer/configuration_spec.rb | 108 +++++------ spec/unit/hanami/mailer/delivery_spec.rb | 62 +++--- spec/unit/hanami/mailer/dsl_spec.rb | 34 ++-- spec/unit/hanami/mailer/rendering_spec.rb | 28 +-- spec/unit/hanami/mailer/version_spec.rb | 2 + 21 files changed, 249 insertions(+), 388 deletions(-) delete mode 100644 .drone.yml diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index 7fba5fb..0000000 --- a/.drone.yml +++ /dev/null @@ -1,177 +0,0 @@ -kind: pipeline -name: ruby-2-7 -group: build - -steps: -- name: install - image: ruby:2.7 - volumes: - - name: bundle - path: /usr/local/bundle - commands: - - ruby -v - - gem install bundler - - bundle install --jobs=3 --retry=3 - -- name: unit - image: ruby:2.7 - volumes: - - name: bundle - path: /usr/local/bundle - commands: - - COVERAGE=true bundle exec rake spec:unit - -- name: quality - image: ruby:2.7 - environment: - CODECOV_TOKEN: - from_secret: codecov - volumes: - - name: bundle - path: /usr/local/bundle - commands: - - CI=true bundle exec rake codecov:upload - -volumes: -- name: bundle - temp: {} - ---- -kind: pipeline -name: ruby-2-6 -group: build - -steps: -- name: install - image: ruby:2.6 - volumes: - - name: bundle - path: /usr/local/bundle - commands: - - ruby -v - - gem install bundler - - bundle install --jobs=3 --retry=3 - -- name: unit - image: ruby:2.6 - volumes: - - name: bundle - path: /usr/local/bundle - commands: - - COVERAGE=true bundle exec rake spec:unit - -- name: quality - image: ruby:2.6 - environment: - CODECOV_TOKEN: - from_secret: codecov - volumes: - - name: bundle - path: /usr/local/bundle - commands: - - CI=true bundle exec rake codecov:upload - -volumes: -- name: bundle - temp: {} - ---- -kind: pipeline -name: ruby-2-5 -group: build - -steps: -- name: install - image: ruby:2.5 - volumes: - - name: bundle - path: /usr/local/bundle - commands: - - ruby -v - - gem install bundler - - bundle install --jobs=3 --retry=3 - -- name: unit - image: ruby:2.5 - volumes: - - name: bundle - path: /usr/local/bundle - commands: - - COVERAGE=true bundle exec rake spec:unit - -- name: quality - image: ruby:2.5 - environment: - CODECOV_TOKEN: - from_secret: codecov - volumes: - - name: bundle - path: /usr/local/bundle - commands: - - CI=true bundle exec rake codecov:upload - -volumes: -- name: bundle - temp: {} - ---- -kind: pipeline -name: jruby-9-2 -group: build - -steps: -- name: install - image: hanami/jruby-9.2 - volumes: - - name: bundle - path: /usr/local/bundle - commands: - - ruby -v - - gem install bundler - - bundle install --jobs=3 --retry=3 - -- name: unit - image: hanami/jruby-9.2 - volumes: - - name: bundle - path: /usr/local/bundle - commands: - - COVERAGE=true bundle exec rake spec:unit - -- name: quality - image: hanami/jruby-9.2 - environment: - CODECOV_TOKEN: - from_secret: codecov - volumes: - - name: bundle - path: /usr/local/bundle - commands: - - CI=true bundle exec rake codecov:upload - -volumes: -- name: bundle - temp: {} - ---- -kind: pipeline -name: slack -group: build - -clone: - disable: true - -depends_on: - - jruby-9-2 - -steps: -- name: slack - image: plugins/slack - settings: - link_names: true - webhook: - from_secret: slack - channel: dev - when: - event: - - push diff --git a/Gemfile b/Gemfile index 6d33344..7728090 100644 --- a/Gemfile +++ b/Gemfile @@ -1,12 +1,14 @@ -source 'https://rubygems.org' +# frozen_string_literal: true + +source "https://rubygems.org" gemspec -unless ENV['CI'] - gem 'byebug', require: false, platforms: :mri - gem 'yard', require: false +unless ENV["CI"] + gem "byebug", require: false, platforms: :mri + gem "yard", require: false end -gem 'hanami-utils', '~> 1.3', require: false, git: 'https://github.com/hanami/utils.git', branch: 'master' -gem 'haml' +gem "hanami-utils", "~> 1.3", require: false, git: "https://github.com/hanami/utils.git", branch: "master" +gem "haml" -gem 'hanami-devtools', require: false, git: 'https://github.com/hanami/devtools.git' +gem "hanami-devtools", require: false, git: "https://github.com/hanami/devtools.git" diff --git a/README.md b/README.md index f972ea3..faa85fd 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,6 @@ Mail for Ruby applications. ## Status [![Gem Version](https://badge.fury.io/rb/hanami-mailer.svg)](https://badge.fury.io/rb/hanami-mailer) -[![Build Status](https://ci.hanamirb.org/api/badges/hanami/mailer/status.svg)](https://ci.hanamirb.org/hanami/mailer) [![CircleCI](https://circleci.com/gh/hanami/mailer/tree/master.svg?style=svg)](https://circleci.com/gh/hanami/mailer/tree/master) [![Test Coverage](https://codecov.io/gh/hanami/mailer/branch/master/graph/badge.svg)](https://codecov.io/gh/hanami/mailer) [![Depfu](https://badges.depfu.com/badges/739c6e10eaf20d3ba4240d00828284db/overview.svg)](https://depfu.com/github/hanami/mailer?project=Bundler) @@ -416,6 +415,6 @@ __Hanami::Mailer__ uses [Semantic Versioning 2.0.0](http://semver.org) ## Copyright -Copyright © 2015-2017 Luca Guidi – Released under MIT License +Copyright © 2015-2020 Luca Guidi – Released under MIT License This project was formerly known as Lotus (`lotus-mailer`). diff --git a/bin/console b/bin/console index b802273..7bd9fee 100755 --- a/bin/console +++ b/bin/console @@ -1,7 +1,8 @@ #!/usr/bin/env ruby +# frozen_string_literal: true -require 'bundler/setup' -require 'hanami/mailer' +require "bundler/setup" +require "hanami/mailer" # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. @@ -10,5 +11,5 @@ require 'hanami/mailer' # require "pry" # Pry.start -require 'irb' +require "irb" IRB.start diff --git a/hanami-mailer.gemspec b/hanami-mailer.gemspec index 4a87bb8..88c618f 100644 --- a/hanami-mailer.gemspec +++ b/hanami-mailer.gemspec @@ -1,29 +1,32 @@ -lib = File.expand_path('../lib', __FILE__) +# frozen_string_literal: true + +lib = File.expand_path("../lib", __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'hanami/mailer/version' +require "hanami/mailer/version" Gem::Specification.new do |spec| - spec.name = 'hanami-mailer' + spec.name = "hanami-mailer" spec.version = Hanami::Mailer::VERSION - spec.authors = ['Luca Guidi'] - spec.email = ['me@lucaguidi.com'] + spec.authors = ["Luca Guidi"] + spec.email = ["me@lucaguidi.com"] - spec.summary = 'Mail for Ruby applications.' - spec.description = 'Mail for Ruby applications and Hanami mailers' - spec.homepage = 'http://hanamirb.org' - spec.license = 'MIT' + spec.summary = "Mail for Ruby applications." + spec.description = "Mail for Ruby applications and Hanami mailers" + spec.homepage = "http://hanamirb.org" + spec.license = "MIT" - spec.files = `git ls-files -- lib/* CHANGELOG.md LICENSE.md README.md hanami-mailer.gemspec`.split($/) # rubocop:disable Style/SpecialGlobalVars - spec.bindir = 'exe' + spec.files = `git ls-files -- lib/* CHANGELOG.md LICENSE.md README.md hanami-mailer.gemspec`.split($/) + spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } - spec.require_paths = ['lib'] - spec.required_ruby_version = '>= 2.3.0' + spec.require_paths = ["lib"] + spec.required_ruby_version = ">= 2.3.0" - spec.add_dependency 'hanami-utils', '~> 1.3' - spec.add_dependency 'tilt', '~> 2.0', '>= 2.0.1' - spec.add_dependency 'mail', '~> 2.6' + spec.add_dependency "hanami-utils", "~> 1.3" + spec.add_dependency "tilt", "~> 2.0", ">= 2.0.1" + spec.add_dependency "mail", "~> 2.6" - spec.add_development_dependency 'bundler', '>= 1.6', '< 3' - spec.add_development_dependency 'rake', '~> 13' - spec.add_development_dependency 'rspec', '~> 3.7' + spec.add_development_dependency "bundler", ">= 1.6", "< 3" + spec.add_development_dependency "rake", "~> 13" + spec.add_development_dependency "rspec", "~> 3.7" + spec.add_development_dependency "rubocop", "0.81" # rubocop 0.81+ removed support for Ruby 2.3 end diff --git a/lib/hanami-mailer.rb b/lib/hanami-mailer.rb index 087fa1b..5231779 100644 --- a/lib/hanami-mailer.rb +++ b/lib/hanami-mailer.rb @@ -1 +1,3 @@ -require 'hanami/mailer' +# frozen_string_literal: true + +require "hanami/mailer" diff --git a/lib/hanami/mailer.rb b/lib/hanami/mailer.rb index abf9b1e..0518f91 100644 --- a/lib/hanami/mailer.rb +++ b/lib/hanami/mailer.rb @@ -1,8 +1,10 @@ -require 'hanami/utils/class_attribute' -require 'hanami/mailer/version' -require 'hanami/mailer/configuration' -require 'hanami/mailer/dsl' -require 'mail' +# frozen_string_literal: true + +require "hanami/utils/class_attribute" +require "hanami/mailer/version" +require "hanami/mailer/configuration" +require "hanami/mailer/dsl" +require "mail" # Hanami # @@ -34,8 +36,8 @@ module Hanami # @since 0.1.0 # @api private CONTENT_TYPES = { - html: 'text/html', - txt: 'text/plain' + html: "text/html", + txt: "text/plain" }.freeze include Utils::ClassAttribute @@ -181,10 +183,17 @@ module Hanami # invoice = Invoice.new # user = User.new(name: 'L', email: 'user@example.com') # - # Billing::Invoice.deliver(invoice: invoice, user: user) # Deliver both text, HTML parts and the attachment - # Billing::Invoice.deliver(invoice: invoice, user: user, format: :txt) # Deliver only the text part and the attachment - # Billing::Invoice.deliver(invoice: invoice, user: user, format: :html) # Deliver only the text part and the attachment - # Billing::Invoice.deliver(invoice: invoice, user: user, charset: 'iso-8859') # Deliver both the parts with "iso-8859" + # # Deliver both text, HTML parts and the attachment + # Billing::Invoice.deliver(invoice: invoice, user: user) + # + # # Deliver only the text part and the attachment + # Billing::Invoice.deliver(invoice: invoice, user: user, format: :txt) + # + # # Deliver only the text part and the attachment + # Billing::Invoice.deliver(invoice: invoice, user: user, format: :html) + # + # # Deliver both the parts with "iso-8859" + # Billing::Invoice.deliver(invoice: invoice, user: user, charset: "iso-8859") def deliver(locals = {}) new(locals).deliver end @@ -280,8 +289,6 @@ module Hanami private - # rubocop:disable Metrics/MethodLength - # rubocop:disable Metrics/AbcSize def build Mail.new.tap do |m| m.return_path = __dsl(:return_path) @@ -299,8 +306,6 @@ module Hanami m.delivery_method(*Hanami::Mailer.configuration.delivery_method) end end - # rubocop:enable Metrics/MethodLength - # rubocop:enable Metrics/AbcSize # @api private # @since 0.1.0 diff --git a/lib/hanami/mailer/configuration.rb b/lib/hanami/mailer/configuration.rb index 890eb75..8cd9e25 100644 --- a/lib/hanami/mailer/configuration.rb +++ b/lib/hanami/mailer/configuration.rb @@ -1,5 +1,7 @@ -require 'set' -require 'hanami/utils/kernel' +# frozen_string_literal: true + +require "set" +require "hanami/utils/kernel" module Hanami module Mailer @@ -11,7 +13,7 @@ module Hanami # # @since 0.1.0 # @api private - DEFAULT_ROOT = '.'.freeze + DEFAULT_ROOT = "." # Default delivery method # @@ -23,7 +25,7 @@ module Hanami # # @since 0.1.0 # @api private - DEFAULT_CHARSET = 'UTF-8'.freeze + DEFAULT_CHARSET = "UTF-8" # @since 0.1.0 # @api private @@ -144,10 +146,10 @@ module Hanami # # @see Hanami::Mailer.configure def prepare(&blk) - if block_given? # rubocop:disable Style/GuardClause + if block_given? @modules.push(blk) else - raise ArgumentError.new('Please provide a block') + raise ArgumentError.new("Please provide a block") end end @@ -191,7 +193,7 @@ module Hanami @modules = [] end - alias unload! reset! + alias_method :unload!, :reset! # Copy the configuration for the given mailer # diff --git a/lib/hanami/mailer/dsl.rb b/lib/hanami/mailer/dsl.rb index bd06b64..e008a3e 100644 --- a/lib/hanami/mailer/dsl.rb +++ b/lib/hanami/mailer/dsl.rb @@ -1,5 +1,7 @@ -require 'hanami/mailer/rendering/template_name' -require 'hanami/mailer/rendering/templates_finder' +# frozen_string_literal: true + +require "hanami/mailer/rendering/template_name" +require "hanami/mailer/rendering/templates_finder" module Hanami module Mailer diff --git a/lib/hanami/mailer/rendering/template_name.rb b/lib/hanami/mailer/rendering/template_name.rb index ba35970..8665c17 100644 --- a/lib/hanami/mailer/rendering/template_name.rb +++ b/lib/hanami/mailer/rendering/template_name.rb @@ -1,4 +1,6 @@ -require 'hanami/utils/string' +# frozen_string_literal: true + +require "hanami/utils/string" module Hanami module Mailer @@ -10,7 +12,7 @@ module Hanami class TemplateName # @since 0.1.0 # @api private - NAMESPACE_SEPARATOR = '::'.freeze + NAMESPACE_SEPARATOR = "::" # @since 0.1.0 # @api private @@ -45,7 +47,7 @@ module Hanami # @since 0.1.0 # @api private def replace!(token) - @name = @name.gsub(/\A#{token}#{NAMESPACE_SEPARATOR}/, '') + @name = @name.gsub(/\A#{token}#{NAMESPACE_SEPARATOR}/, "") end end end diff --git a/lib/hanami/mailer/rendering/templates_finder.rb b/lib/hanami/mailer/rendering/templates_finder.rb index ef0ebcc..d6e2dc6 100644 --- a/lib/hanami/mailer/rendering/templates_finder.rb +++ b/lib/hanami/mailer/rendering/templates_finder.rb @@ -1,4 +1,6 @@ -require 'hanami/mailer/template' +# frozen_string_literal: true + +require "hanami/mailer/template" module Hanami module Mailer @@ -14,19 +16,19 @@ module Hanami # # @api private # @since 0.1.0 - FORMAT = '*'.freeze + FORMAT = "*" # Default template engines # # @api private # @since 0.1.0 - ENGINES = '*'.freeze + ENGINES = "*" # Recursive pattern # # @api private # @since 0.1.0 - RECURSIVE = '**'.freeze + RECURSIVE = "**" # Initialize a finder # @@ -72,7 +74,7 @@ module Hanami templates = Hash[] _find.map do |template| name = File.basename(template) - format = (name.split('.')[-2]).to_sym + format = (name.split(".")[-2]).to_sym templates[format] = Mailer::Template.new(template) end templates diff --git a/lib/hanami/mailer/template.rb b/lib/hanami/mailer/template.rb index 56b601a..fecb3f1 100644 --- a/lib/hanami/mailer/template.rb +++ b/lib/hanami/mailer/template.rb @@ -1,4 +1,6 @@ -require 'tilt' +# frozen_string_literal: true + +require "tilt" module Hanami module Mailer diff --git a/lib/hanami/mailer/version.rb b/lib/hanami/mailer/version.rb index 74ef4bc..e751b31 100644 --- a/lib/hanami/mailer/version.rb +++ b/lib/hanami/mailer/version.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + module Hanami module Mailer # @since 0.1.0 - VERSION = '1.3.2'.freeze + VERSION = "1.3.2" end end diff --git a/script/ci b/script/ci index c3946ce..70f1c53 100755 --- a/script/ci +++ b/script/ci @@ -26,11 +26,11 @@ upload_code_coverage() { } main() { - prepare_build && - print_ruby_version && - run_code_quality_checks && - run_unit_tests && - upload_code_coverage + prepare_build + print_ruby_version + run_code_quality_checks + run_unit_tests + upload_code_coverage } main diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0c87833..f656911 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $LOAD_PATH.unshift "lib" require "hanami/utils" require "hanami/devtools/unit" diff --git a/spec/support/fixtures.rb b/spec/support/fixtures.rb index d570813..251af8e 100644 --- a/spec/support/fixtures.rb +++ b/spec/support/fixtures.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + class InvoiceMailer include Hanami::Mailer - template 'invoice' + template "invoice" end class RenderMailer @@ -14,43 +16,43 @@ end class CharsetMailer include Hanami::Mailer - from 'noreply@example.com' - to 'user@example.com' - subject 'こんにちは' + from "noreply@example.com" + to "user@example.com" + subject "こんにちは" end class MissingFromMailer include Hanami::Mailer - template 'missing' + template "missing" - to 'recipient@example.com' - subject 'Hello' + to "recipient@example.com" + subject "Hello" end class MissingToMailer include Hanami::Mailer - template 'missing' + template "missing" - from 'sender@example.com' - subject 'Hello' + from "sender@example.com" + subject "Hello" end class CcOnlyMailer include Hanami::Mailer - template 'missing' + template "missing" - cc 'recipient@example.com' - from 'sender@example.com' - subject 'Hello' + cc "recipient@example.com" + from "sender@example.com" + subject "Hello" end class BccOnlyMailer include Hanami::Mailer - template 'missing' + template "missing" - bcc 'recipient@example.com' - from 'sender@example.com' - subject 'Hello' + bcc "recipient@example.com" + from "sender@example.com" + subject "Hello" end User = Struct.new(:name, :email) @@ -84,21 +86,21 @@ end class WelcomeMailer include Hanami::Mailer - return_path 'bounce@sender.com' - from 'noreply@sender.com' - to ['noreply@recipient.com', 'owner@recipient.com'] - cc 'cc@recipient.com' - bcc 'bcc@recipient.com' - reply_to 'reply_to@recipient.com' + return_path "bounce@sender.com" + from "noreply@sender.com" + to ["noreply@recipient.com", "owner@recipient.com"] + cc "cc@recipient.com" + bcc "bcc@recipient.com" + reply_to "reply_to@recipient.com" - subject 'Welcome' + subject "Welcome" def greeting - 'Ahoy' + "Ahoy" end def prepare - mail.attachments['invoice.pdf'] = '/path/to/invoice.pdf' + mail.attachments["invoice.pdf"] = "/path/to/invoice.pdf" end end @@ -120,6 +122,6 @@ end module DefaultSubject def self.included(mailer) - mailer.subject 'default subject' + mailer.subject "default subject" end end diff --git a/spec/unit/hanami/mailer/configuration_spec.rb b/spec/unit/hanami/mailer/configuration_spec.rb index 50e3f4f..db78f39 100644 --- a/spec/unit/hanami/mailer/configuration_spec.rb +++ b/spec/unit/hanami/mailer/configuration_spec.rb @@ -1,25 +1,27 @@ +# frozen_string_literal: true + RSpec.describe Hanami::Mailer::Configuration do before do @configuration = Hanami::Mailer::Configuration.new end - describe '#root' do - describe 'when a value is given' do - describe 'and it is a string' do - it 'sets it as a Pathname' do - @configuration.root 'spec' - expect(@configuration.root).to eq(Pathname.new('spec').realpath) + describe "#root" do + describe "when a value is given" do + describe "and it is a string" do + it "sets it as a Pathname" do + @configuration.root "spec" + expect(@configuration.root).to eq(Pathname.new("spec").realpath) end end - describe 'and it is a pathname' do - it 'sets it' do - @configuration.root Pathname.new('spec') - expect(@configuration.root).to eq(Pathname.new('spec').realpath) + describe "and it is a pathname" do + it "sets it" do + @configuration.root Pathname.new("spec") + expect(@configuration.root).to eq(Pathname.new("spec").realpath) end end - describe 'and it implements #to_pathname' do + describe "and it implements #to_pathname" do before do RootPath = Struct.new(:path) do def to_pathname @@ -32,39 +34,39 @@ RSpec.describe Hanami::Mailer::Configuration do Object.send(:remove_const, :RootPath) end - it 'sets the converted value' do - @configuration.root RootPath.new('spec') - expect(@configuration.root).to eq(Pathname.new('spec').realpath) + it "sets the converted value" do + @configuration.root RootPath.new("spec") + expect(@configuration.root).to eq(Pathname.new("spec").realpath) end end - describe 'and it is an unexisting path' do - it 'raises an error' do + describe "and it is an unexisting path" do + it "raises an error" do expect do - @configuration.root '/path/to/unknown' + @configuration.root "/path/to/unknown" end.to raise_error(Errno::ENOENT) end end end - describe 'when a value is not given' do - it 'defaults to the current path' do - expect(@configuration.root).to eq(Pathname.new('.').realpath) + describe "when a value is not given" do + it "defaults to the current path" do + expect(@configuration.root).to eq(Pathname.new(".").realpath) end end end - describe '#mailers' do - it 'defaults to an empty set' do + describe "#mailers" do + it "defaults to an empty set" do expect(@configuration.mailers).to be_empty end - it 'allows to add mailers' do + it "allows to add mailers" do @configuration.add_mailer(InvoiceMailer) expect(@configuration.mailers).to include(InvoiceMailer) end - it 'eliminates duplications' do + it "eliminates duplications" do @configuration.add_mailer(RenderMailer) @configuration.add_mailer(RenderMailer) @@ -72,11 +74,11 @@ RSpec.describe Hanami::Mailer::Configuration do end end - describe '#prepare' do + describe "#prepare" do before do module FooRendering def render - 'foo' + "foo" end end @@ -89,8 +91,8 @@ RSpec.describe Hanami::Mailer::Configuration do Object.__send__(:remove_const, :PrepareMailer) end - it 'raises error in case of missing block' do - expect { @configuration.prepare }.to raise_error(ArgumentError, 'Please provide a block') + it "raises error in case of missing block" do + expect { @configuration.prepare }.to raise_error(ArgumentError, "Please provide a block") end end @@ -118,75 +120,75 @@ RSpec.describe Hanami::Mailer::Configuration do # end - describe '#load!' do + describe "#load!" do before do - @configuration.root 'spec' + @configuration.root "spec" @configuration.load! end - it 'loads root' do - root = Pathname.new('spec').realpath + it "loads root" do + root = Pathname.new("spec").realpath expect(@configuration.root).to eq(root) end end - describe '#delivery_method' do - describe 'when not previously set' do + describe "#delivery_method" do + describe "when not previously set" do before do @configuration.reset! end - it 'defaults to SMTP' do + it "defaults to SMTP" do expect(@configuration.delivery_method).to eq([:smtp, {}]) end end - describe 'set with a symbol' do + describe "set with a symbol" do before do - @configuration.delivery_method :exim, location: '/path/to/exim' + @configuration.delivery_method :exim, location: "/path/to/exim" end - it 'saves the delivery method in the configuration' do - expect(@configuration.delivery_method).to eq([:exim, { location: '/path/to/exim' }]) + it "saves the delivery method in the configuration" do + expect(@configuration.delivery_method).to eq([:exim, {location: "/path/to/exim"}]) end end - describe 'set with a class' do + describe "set with a class" do before do @configuration.delivery_method MandrillDeliveryMethod, - username: 'mandrill-username', password: 'mandrill-api-key' + username: "mandrill-username", password: "mandrill-api-key" end - it 'saves the delivery method in the configuration' do - expect(@configuration.delivery_method).to eq([MandrillDeliveryMethod, username: 'mandrill-username', password: 'mandrill-api-key']) + it "saves the delivery method in the configuration" do + expect(@configuration.delivery_method).to eq([MandrillDeliveryMethod, username: "mandrill-username", password: "mandrill-api-key"]) end end end - describe '#default_charset' do - describe 'when not previously set' do + describe "#default_charset" do + describe "when not previously set" do before do @configuration.reset! end - it 'defaults to UTF-8' do - expect(@configuration.default_charset).to eq('UTF-8') + it "defaults to UTF-8" do + expect(@configuration.default_charset).to eq("UTF-8") end end - describe 'when set' do + describe "when set" do before do - @configuration.default_charset 'iso-8859-1' + @configuration.default_charset "iso-8859-1" end - it 'saves the delivery method in the configuration' do - expect(@configuration.default_charset).to eq('iso-8859-1') + it "saves the delivery method in the configuration" do + expect(@configuration.default_charset).to eq("iso-8859-1") end end end - describe '#prepare' do - it 'injects code in each mailer' + describe "#prepare" do + it "injects code in each mailer" # it 'injects code in each mailer' do # InvoiceMailer.subject.must_equal 'default subject' # end diff --git a/spec/unit/hanami/mailer/delivery_spec.rb b/spec/unit/hanami/mailer/delivery_spec.rb index 3733204..fc7486b 100644 --- a/spec/unit/hanami/mailer/delivery_spec.rb +++ b/spec/unit/hanami/mailer/delivery_spec.rb @@ -1,11 +1,13 @@ +# frozen_string_literal: true + RSpec.describe Hanami::Mailer do - describe '.deliver' do + describe ".deliver" do before do Hanami::Mailer.deliveries.clear end - it 'can deliver with specified charset' do - CharsetMailer.deliver(charset: charset = 'iso-2022-jp') + it "can deliver with specified charset" do + CharsetMailer.deliver(charset: charset = "iso-2022-jp") mail = Hanami::Mailer.deliveries.first expect(mail.charset).to eq(charset) @@ -40,7 +42,7 @@ RSpec.describe Hanami::Mailer do expect { mailer.deliver }.to raise_error(ArgumentError, "ouch") end - describe 'test delivery with hardcoded values' do + describe "test delivery with hardcoded values" do before do WelcomeMailer.deliver @mail = Hanami::Mailer.deliveries.first @@ -50,27 +52,27 @@ RSpec.describe Hanami::Mailer do Hanami::Mailer.deliveries.clear end - it 'delivers the mail' do + it "delivers the mail" do expect(Hanami::Mailer.deliveries.length).to eq(1) end - it 'sends the correct information' do - expect(@mail.return_path).to eq('bounce@sender.com') - expect(@mail.from).to eq(['noreply@sender.com']) - expect(@mail.to).to eq(['noreply@recipient.com', 'owner@recipient.com']) - expect(@mail.cc).to eq(['cc@recipient.com']) - expect(@mail.bcc).to eq(['bcc@recipient.com']) - expect(@mail.reply_to).to eq(['reply_to@recipient.com']) - expect(@mail.subject).to eq('Welcome') + it "sends the correct information" do + expect(@mail.return_path).to eq("bounce@sender.com") + expect(@mail.from).to eq(["noreply@sender.com"]) + expect(@mail.to).to eq(["noreply@recipient.com", "owner@recipient.com"]) + expect(@mail.cc).to eq(["cc@recipient.com"]) + expect(@mail.bcc).to eq(["bcc@recipient.com"]) + expect(@mail.reply_to).to eq(["reply_to@recipient.com"]) + expect(@mail.subject).to eq("Welcome") end - it 'has the correct templates' do + it "has the correct templates" do expect(@mail.html_part.to_s).to include(%(template)) expect(@mail.text_part.to_s).to include(%(template)) end - it 'interprets the prepare statement' do - attachment = @mail.attachments['invoice.pdf'] + it "interprets the prepare statement" do + attachment = @mail.attachments["invoice.pdf"] expect(attachment).to be_kind_of(Mail::Part) @@ -78,16 +80,16 @@ RSpec.describe Hanami::Mailer do expect(attachment).to_not be_inline expect(attachment).to_not be_multipart - expect(attachment.filename).to eq('invoice.pdf') + expect(attachment.filename).to eq("invoice.pdf") - expect(attachment.content_type).to match('application/pdf') - expect(attachment.content_type).to match('filename=invoice.pdf') + expect(attachment.content_type).to match("application/pdf") + expect(attachment.content_type).to match("filename=invoice.pdf") end end - describe 'test delivery with methods' do + describe "test delivery with methods" do before do - @user = User.new('Name', 'student@deigirls.com') + @user = User.new("Name", "student@deigirls.com") MethodMailer.deliver(user: @user) @mail = Hanami::Mailer.deliveries.first @@ -97,23 +99,23 @@ RSpec.describe Hanami::Mailer do Hanami::Mailer.deliveries.clear end - it 'delivers the mail' do + it "delivers the mail" do expect(Hanami::Mailer.deliveries.length).to eq(1) end - it 'sends the correct information' do + it "sends the correct information" do expect(@mail.from).to eq(["hello-#{@user.name.downcase}@example.com"]) expect(@mail.to).to eq([@user.email]) expect(@mail.subject).to eq("Hello, #{@user.name}") end end - describe 'multipart' do + describe "multipart" do after do Hanami::Mailer.deliveries.clear end - it 'delivers all the parts by default' do + it "delivers all the parts by default" do WelcomeMailer.deliver mail = Hanami::Mailer.deliveries.first @@ -123,7 +125,7 @@ RSpec.describe Hanami::Mailer do expect(body).to include(%(This is a txt template)) end - it 'can deliver only the text part' do + it "can deliver only the text part" do WelcomeMailer.deliver(format: :txt) mail = Hanami::Mailer.deliveries.first @@ -133,7 +135,7 @@ RSpec.describe Hanami::Mailer do expect(body).to include(%(This is a txt template)) end - it 'can deliver only the html part' do + it "can deliver only the html part" do WelcomeMailer.deliver(format: :html) mail = Hanami::Mailer.deliveries.first @@ -144,9 +146,9 @@ RSpec.describe Hanami::Mailer do end end - describe 'custom delivery' do + describe "custom delivery" do before do - @options = options = { deliveries: [] } + @options = options = {deliveries: []} # Hanami::Mailer.reset! # Hanami::Mailer.configure do @@ -158,7 +160,7 @@ RSpec.describe Hanami::Mailer do @mail = options.fetch(:deliveries).first end - it 'delivers the mail' + it "delivers the mail" # it 'delivers the mail' do # @options.fetch(:deliveries).length.must_equal 1 # end diff --git a/spec/unit/hanami/mailer/dsl_spec.rb b/spec/unit/hanami/mailer/dsl_spec.rb index f5e2415..557680c 100644 --- a/spec/unit/hanami/mailer/dsl_spec.rb +++ b/spec/unit/hanami/mailer/dsl_spec.rb @@ -1,43 +1,45 @@ +# frozen_string_literal: true + RSpec.describe Hanami::Mailer do - describe '.template' do - describe 'when no value is set' do - it 'returns the convention name' do - expect(RenderMailer.template).to eq('render_mailer') + describe ".template" do + describe "when no value is set" do + it "returns the convention name" do + expect(RenderMailer.template).to eq("render_mailer") end - it 'returns correct namespaced value' do - expect(Users::Welcome.template).to eq('users/welcome') + it "returns correct namespaced value" do + expect(Users::Welcome.template).to eq("users/welcome") end end - describe 'when a value is set' do - it 'returns that name' do - expect(InvoiceMailer.template).to eq('invoice') + describe "when a value is set" do + it "returns that name" do + expect(InvoiceMailer.template).to eq("invoice") end end end - describe '.templates' do - describe 'when no value is set' do - it 'returns a set of templates' do + describe ".templates" do + describe "when no value is set" do + it "returns a set of templates" do template_formats = LazyMailer.templates.keys expect(template_formats).to match_array(%i[html txt]) end - it 'returns only the template for the given format' do + it "returns only the template for the given format" do template = LazyMailer.templates(:txt) expect(template).to be_kind_of(Hanami::Mailer::Template) expect(template.file).to match(%r{spec/support/fixtures/templates/lazy_mailer.txt.erb\z}) end end - describe 'when a value is set' do - it 'returns a set of templates' do + describe "when a value is set" do + it "returns a set of templates" do template_formats = InvoiceMailer.templates.keys expect(template_formats).to eq([:html]) end - it 'returns only the template for the given format' do + it "returns only the template for the given format" do template = InvoiceMailer.templates(:html) expect(template).to be_kind_of(Hanami::Mailer::Template) expect(template.file).to match(%r{spec/support/fixtures/templates/invoice.html.erb\z}) diff --git a/spec/unit/hanami/mailer/rendering_spec.rb b/spec/unit/hanami/mailer/rendering_spec.rb index 6fd3811..7cc81b2 100644 --- a/spec/unit/hanami/mailer/rendering_spec.rb +++ b/spec/unit/hanami/mailer/rendering_spec.rb @@ -1,42 +1,44 @@ +# frozen_string_literal: true + RSpec.describe Hanami::Mailer do - describe '#render' do - describe 'when template is explicitly declared' do + describe "#render" do + describe "when template is explicitly declared" do let(:mailer) { InvoiceMailer.new } - it 'renders the given template' do + it "renders the given template" do expect(mailer.render(:html)).to include(%(

Invoice template

)) end end - describe 'when template is implicitly declared' do + describe "when template is implicitly declared" do let(:mailer) { LazyMailer.new } - it 'looks for template with same name with inflected classname and render it' do + it "looks for template with same name with inflected classname and render it" do expect(mailer.render(:html)).to include(%(Hello World)) expect(mailer.render(:txt)).to include(%(This is a txt template)) end end - describe 'when mailer defines context' do + describe "when mailer defines context" do let(:mailer) { WelcomeMailer.new } - it 'renders template with defined context' do + it "renders template with defined context" do expect(mailer.render(:txt)).to include(%(Ahoy)) end end - describe 'when locals are parsed in' do - let(:mailer) { RenderMailer.new(user: User.new('Luca')) } + describe "when locals are parsed in" do + let(:mailer) { RenderMailer.new(user: User.new("Luca")) } - it 'renders template with parsed locals' do + it "renders template with parsed locals" do expect(mailer.render(:html)).to include(%(Luca)) end end - describe 'with HAML template engine' do - let(:mailer) { TemplateEngineMailer.new(user: User.new('Luca')) } + describe "with HAML template engine" do + let(:mailer) { TemplateEngineMailer.new(user: User.new("Luca")) } - it 'renders template with parsed locals' do + it "renders template with parsed locals" do expect(mailer.render(:html)).to include(%(

\nLuca\n

\n)) end end diff --git a/spec/unit/hanami/mailer/version_spec.rb b/spec/unit/hanami/mailer/version_spec.rb index 80881ca..de2cd67 100644 --- a/spec/unit/hanami/mailer/version_spec.rb +++ b/spec/unit/hanami/mailer/version_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe "Hanami::Mailer::VERSION" do it "returns current version" do expect(Hanami::Mailer::VERSION).to eq("1.3.2")