Skip to content

Commit

Permalink
Refactor letsencrypt generator spec
Browse files Browse the repository at this point in the history
  • Loading branch information
elct9620 committed Nov 9, 2023
1 parent d06a67b commit 96c6b74
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
require 'generators/lets_encrypt/install_generator'

RSpec.describe LetsEncrypt::Generators::InstallGenerator do
before(:all) do
@dummy_class = Class.new(Rails::Generators::TestCase) do
let(:klass) do
Class.new(Rails::Generators::TestCase) do
tests LetsEncrypt::Generators::InstallGenerator
destination Rails.root.join('tmp')
end
end

let(:generator) { klass.new(:fake_test_case) }

@generator = @dummy_class.new(:fake_test_case)
@generator.send(:prepare_destination)
@generator.run_generator
before do
generator.send(:prepare_destination)
generator.run_generator
end

it do
@generator.assert_migration 'db/migrate/create_letsencrypt_certificates.rb', /def change/
generator.assert_migration 'db/migrate/create_letsencrypt_certificates.rb', /def change/
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,28 @@
require 'generators/lets_encrypt/register_generator'

RSpec.describe LetsEncrypt::Generators::RegisterGenerator do
before(:all) do
@dummy_class = Class.new(Rails::Generators::TestCase) do
let(:klass) do
Class.new(Rails::Generators::TestCase) do
tests LetsEncrypt::Generators::RegisterGenerator
destination Rails.root.join('tmp')
end
@generator = @dummy_class.new(:fake_test_case)
end

it do
let(:generator) { klass.new(:fake_test_case) }

before do
answers = [
'', # In production
'', # File path
'Y', # Overwrite?
'[email protected]' # E-Mail
]
allow(Thor::LineEditor).to receive(:readline) { answers.shift.dup || 'N' }
allow(LetsEncrypt).to receive(:register).and_return(true)

expect(LetsEncrypt).to receive(:register).and_return(true)

@generator.send(:prepare_destination)
@generator.run_generator
generator.send(:prepare_destination)
generator.run_generator
end

it { expect(LetsEncrypt).to have_received(:register).with('[email protected]') }
end

0 comments on commit 96c6b74

Please sign in to comment.