-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters