diff --git a/lib/kangaru/testing/gem.rb b/lib/kangaru/testing/gem.rb deleted file mode 100644 index 78da7da..0000000 --- a/lib/kangaru/testing/gem.rb +++ /dev/null @@ -1,57 +0,0 @@ -module Kangaru - module Testing - class Gem - class GemNotCreatedError < StandardError; end - - DEFAULT_NAME = "some_gem".freeze - VIEWS_DIR = "views".freeze - - attr_reader :dir, :name - - def initialize(dir:, name: DEFAULT_NAME) - @dir = Pathname.new(dir) - @name = name - end - - def path - @path ||= dir.join(name) - end - - def lib_path - @lib_path ||= path.join("lib") - end - - def main_file - @main_file ||= lib_path.join("#{name}.rb") - end - - def gem_file(file) - lib_path.join(name, "#{file}.rb") - end - - def gem_dir(dir) - lib_path.join(name, dir) - end - - def view_path(controller:, action:) - gem_dir(VIEWS_DIR).join(controller, "#{action}.erb") - end - - def created? - @created == true - end - - def create! - `bundle gem #{path}` - - @created = true - end - - def load! - raise GemNotCreatedError, "gem must be created first" unless created? - - require main_file.to_s - end - end - end -end diff --git a/sig/kangaru/testing/gem.rbs b/sig/kangaru/testing/gem.rbs deleted file mode 100644 index 1c32df8..0000000 --- a/sig/kangaru/testing/gem.rbs +++ /dev/null @@ -1,31 +0,0 @@ -module Kangaru - module Testing - class Gem - class GemNotCreatedError < StandardError - end - - DEFAULT_NAME: String - VIEWS_DIR: String - - @created: bool - - attr_reader dir: Pathname - attr_reader name: String - attr_reader path: Pathname - attr_reader lib_path: Pathname - attr_reader main_file: Pathname - - def initialize: (dir: String, ?name: String) -> void - - def gem_file: (String file) -> Pathname - - def gem_dir: (String dir) -> Pathname - - def created?: -> bool - - def create!: -> void - - def load!: -> void - end - end -end diff --git a/spec/kangaru/testing/gem_spec.rb b/spec/kangaru/testing/gem_spec.rb deleted file mode 100644 index 044380d..0000000 --- a/spec/kangaru/testing/gem_spec.rb +++ /dev/null @@ -1,193 +0,0 @@ -RSpec.describe Kangaru::Testing::Gem, :with_temp_dir do - subject(:gem) { described_class.new(**attributes) } - - let(:attributes) { { dir:, name: }.compact } - - let(:name) { "some_gem" } - let(:dir) { temp_dir } - - shared_examples :returns_path do |options| - let(:expected_path) { options[:for] } - - it "returns a Pathname" do - expect(subject).to be_a(Pathname) - end - - it "sets the expected path" do - expect(subject.to_s).to eq(expected_path) - end - end - - describe "#initialize" do - context "when gem name is not specified" do - let(:name) { nil } - - it "sets the directory" do - expect(gem.dir.to_s).to eq(dir) - end - - it "sets the name to the default" do - expect(gem.name).to eq(described_class::DEFAULT_NAME) - end - end - - context "when gem name is specified" do - let(:name) { "some_gem" } - - it "sets the directory" do - expect(gem.dir.to_s).to eq(dir) - end - - it "sets the name to the specified value" do - expect(gem.name).to eq(name) - end - end - end - - describe "#path" do - subject(:path) { gem.path } - - it "returns a Pathname" do - expect(path).to be_a(Pathname) - end - - it "returns the expected path" do - expect(path.to_s).to eq("#{dir}/#{name}") - end - end - - describe "#lib_path" do - subject(:lib_path) { gem.lib_path } - - it "returns a Pathname" do - expect(lib_path).to be_a(Pathname) - end - - it "sets the expected path" do - expect(lib_path.to_s).to eq("#{dir}/#{name}/lib") - end - end - - describe "#main_file" do - subject(:main_file) { gem.main_file } - - it "returns a Pathname" do - expect(main_file).to be_a(Pathname) - end - - it "returns the expected path" do - expect(main_file.to_s).to eq("#{dir}/#{name}/lib/#{name}.rb") - end - end - - describe "#gem_file" do - subject(:gem_file) { gem.gem_file(file) } - - let(:file) { "some_file" } - - it "returns a Pathname" do - expect(gem_file).to be_a(Pathname) - end - - it "returns the expected path" do - expect(gem_file.to_s).to eq("#{dir}/#{name}/lib/#{name}/#{file}.rb") - end - end - - describe "#gem_dir" do - subject(:gem_dir) { gem.gem_dir(dir_arg) } - - let(:dir_arg) { "some_dir" } - - it "returns a Pathname" do - expect(gem_dir).to be_a(Pathname) - end - - it "returns the expected path" do - expect(gem_dir.to_s).to eq("#{dir}/#{name}/lib/#{name}/#{dir_arg}") - end - end - - describe "#view_file", skip: :deprecated do - subject(:view_file) { gem.view_file(controller:, action:) } - - let(:controller) { "default" } - - let(:action) { :do_something } - - include_examples :returns_path, for: - "/foo/bar/double/lib/double/views/default/do_something.erb" - end - - describe "#created?" do - context "when gem has not been created" do - it "returns false" do - expect(gem).not_to be_created - end - end - - context "when gem has been created" do - before { gem.create! } - - it "returns true" do - expect(gem).to be_created - end - end - end - - describe "#create!" do - subject(:create!) { gem.create! } - - let(:gem_path) { File.join(temp_dir, name) } - - let(:lib_dir) { File.join(gem_path, "lib") } - - it "creates the gem in the specified directory" do - expect { create! }.to create_dir(name).in(temp_dir) - end - - it "generates a Gemfile" do - expect { create! }.to create_file("Gemfile").in(gem_path) - end - - it "generates a gemspec" do - expect { create! }.to create_file("#{name}.gemspec").in(gem_path) - end - - it "generates a lib directory" do - expect { create! }.to create_dir("lib").in(gem_path) - end - - it "generates a main file" do - expect { create! }.to create_file("#{name}.rb").in(lib_dir) - end - end - - describe "#load!" do - subject(:load!) { gem.load! } - - after do - Object.send(:remove_const, :SomeGem) if Object.const_defined?(:SomeGem) - end - - context "when gem has not been created" do - it "raises an error" do - expect { load! }.to raise_error( - described_class::GemNotCreatedError, - "gem must be created first" - ) - end - end - - context "when gem has been created" do - before { gem.create! } - - it "loads the gem" do - expect { load! } - .to change { Object.const_defined?(:SomeGem) } - .from(false) - .to(true) - end - end - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 194994d..cfee15b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -18,10 +18,6 @@ def load_support_files! config.order = :random - config.include FileHelper - config.include GemHelper - config.include TempDirHelper - config.after(with_gem: true) do if Kangaru.instance_variable_defined?(:@application) Kangaru.remove_instance_variable(:@application) diff --git a/spec/support/file_helper.rb b/spec/support/file_helper.rb deleted file mode 100644 index 84a70b5..0000000 --- a/spec/support/file_helper.rb +++ /dev/null @@ -1,31 +0,0 @@ -module FileHelper - extend RSpec::Matchers::DSL - - matcher :create_dir do |filename| - supports_block_expectations - - match do |action| - path = File.join(@dir, filename) - - expect(&action).to change { Dir.exist?(path) }.from(false).to(true) - end - - chain :in do |dir| - @dir = dir - end - end - - matcher :create_file do |filename| - supports_block_expectations - - match do |action| - path = File.join(@dir, filename) - - expect(&action).to change { File.exist?(path) }.from(false).to(true) - end - - chain :in do |dir| - @dir = dir - end - end -end diff --git a/spec/support/gem_helper.rb b/spec/support/gem_helper.rb deleted file mode 100644 index 83104a3..0000000 --- a/spec/support/gem_helper.rb +++ /dev/null @@ -1,21 +0,0 @@ -require "tmpdir" - -module GemHelper - RSpec.configure do |config| - config.around(with_gem_deprecated: true) do |spec| - self.class.class_eval { attr_reader :gem } - - Dir.mktmpdir do |dir| - @gem = Kangaru::Testing::Gem.new(dir:).tap(&:create!) - - spec.run - - Object.send(:remove_const, :SomeGem) if Object.const_defined?(:SomeGem) - - if Kangaru.instance_variable_defined?(:@application) - Kangaru.remove_instance_variable(:@application) - end - end - end - end -end diff --git a/spec/support/temp_dir_helper.rb b/spec/support/temp_dir_helper.rb deleted file mode 100644 index 1e45a6b..0000000 --- a/spec/support/temp_dir_helper.rb +++ /dev/null @@ -1,15 +0,0 @@ -module TempDirHelper - RSpec.configure do |config| - config.around(with_temp_dir: true) do |spec| - self.class.class_eval { attr_reader :temp_dir } - - Dir.mktmpdir do |temp_dir| - @temp_dir = temp_dir - - spec.run - - remove_instance_variable(:@temp_dir) - end - end - end -end