Skip to content

Commit

Permalink
Create initialiser integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
apexatoll committed Sep 24, 2023
1 parent 3f6e063 commit 655ded6
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
87 changes: 87 additions & 0 deletions spec/features/initialiser_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
RSpec.describe "Initialising Kangaru in a target gem", :with_gem do
subject(:require_gem) { gem.load! }

before do
gem.gem_file("foobar").write(<<~RUBY)
module SomeGem
class Foobar
end
end
RUBY
end

context "when the target gem does not extend the initialiser" do
before do
gem.main_file.write(<<~RUBY)
require "kangaru"
module SomeGem
end
RUBY
end

it "loads the gem module" do
expect { require_gem }
.to change { Object.const_defined?(:SomeGem) }
.from(false)
.to(true)
end

it "does not autoload gem files" do
expect { require_gem }
.not_to change { Object.const_defined?("SomeGem::Foobar") }
.from(false)
end

it "does not set the Kangaru application reference" do
expect { require_gem }.not_to change { Kangaru.application }.from(nil)
end
end

context "when the target gem extends the initialiser" do
before do
gem.main_file.write(<<~RUBY)
require "kangaru"
module SomeGem
extend Kangaru::Initialiser
end
RUBY
end

it "loads the gem module" do
expect { require_gem }
.to change { Object.const_defined?("SomeGem") }
.from(false)
.to(true)
end

it "autoloads gem files" do
expect { require_gem }
.to change { Object.const_defined?("SomeGem::Foobar") }
.from(false)
.to(true)
end

it "sets the Kangaru application reference" do
expect { require_gem }
.to change { Kangaru.application }
.from(nil)
.to(a_kind_of(Kangaru::Application))
end

describe "application reference" do
subject(:application) { Kangaru.application }

before { require_gem }

it "sets the application root dir to the gem lib path" do
expect(application.root_dir).to eq(gem.lib_path)
end

it "sets the application root file to the main gem file" do
expect(application.root_file).to eq(gem.main_file)
end
end
end
end
4 changes: 4 additions & 0 deletions spec/kangaru/testing/gem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
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(
Expand Down

0 comments on commit 655ded6

Please sign in to comment.