spec/environment_spec.rb in palimpsest-0.0.1 vs spec/environment_spec.rb in palimpsest-0.1.0
- old
+ new
@@ -1,20 +1,14 @@
require 'spec_helper'
describe Palimpsest::Environment do
- let(:site_1) { double name: 'site_1' }
- let(:site_2) { double name: 'site_2' }
+ let(:site_1) { Palimpsest::Site.new name: 'site_1' }
+ let(:site_2) { Palimpsest::Site.new name: 'site_2' }
subject(:environment) { Palimpsest::Environment.new }
- after :all do
- Dir.glob("#{Palimpsest::Environment.new.options[:tmp_dir]}/#{Palimpsest::Environment.new.options[:dir_prefix]}*").each do |dir|
- FileUtils.remove_entry_secure dir
- end
- end
-
describe ".new" do
it "sets default options" do
expect(environment.options).to eq Palimpsest::Environment::DEFAULT_OPTIONS
end
@@ -61,40 +55,37 @@
end
end
describe "#directory" do
- context "when required values set" do
+ before :each do
+ allow(Palimpsest::Utility).to receive(:make_random_directory).and_return('/tmp/rand_dir')
+ end
- subject(:environment) { Palimpsest::Environment.new site: site_1 }
+ context "when directory is unset" do
- before :each do
- allow(Palimpsest::Utility).to receive(:make_random_directory).and_return('/tmp/rand_dir')
+ it "makes and returns a random directory" do
+ expect(environment.directory).to eq '/tmp/rand_dir'
end
+ end
- context "when directory is unset" do
+ context "when directory is set" do
- it "makes and returns a random directory" do
- expect(environment.directory).to eq '/tmp/rand_dir'
- end
+ it "returns the current directory" do
+ expect(Palimpsest::Utility).to receive(:make_random_directory).once
+ environment.directory
+ expect(environment.directory).to eq '/tmp/rand_dir'
end
-
- context "when directory is set" do
-
- it "returns the current directory" do
- expect(Palimpsest::Utility).to receive(:make_random_directory).once
- environment.directory
- expect(environment.directory).to eq '/tmp/rand_dir'
- end
- end
end
+ end
- context "when required values are not set" do
-
- it "fails if site is not set" do
- expect { environment.directory }.to raise_error RuntimeError
- end
+ describe "#copy" do
+ it "moves the component to the install path" do
+ dir = environment.directory
+ allow(Dir).to receive(:[]).with("#{dir}/*").and_return( %W(#{dir}/path/1 #{dir}/path/2) )
+ expect(FileUtils).to receive(:cp_r).with( %W(#{dir}/path/1 #{dir}/path/2), '/dest/path', preserve: true)
+ environment.copy dest: '/dest/path'
end
end
describe "#cleanup" do
@@ -104,10 +95,14 @@
environment.directory
FileUtils.should_receive(:remove_entry_secure).with(environment.directory)
environment.cleanup
expect(environment.instance_variable_get :@directory).to eq nil
end
+
+ it "returns itself" do
+ expect(environment.cleanup).to be environment
+ end
end
describe "#populate" do
it "fails when missing site" do
@@ -118,44 +113,44 @@
context "populate from repo" do
subject(:environment) { Palimpsest::Environment.new site: site_1, treeish: 'master' }
before :each do
- allow(site_1).to receive(:repo).and_return(double Grit::Repo)
+ site_1.repo = double Grit::Repo
allow(Palimpsest::Utility).to receive :extract_repo
end
it "extracts the repo to the directory and sets populated true" do
expect(Palimpsest::Utility).to receive(:extract_repo).with(site_1.repo, 'master', environment.directory)
- environment.populate
+ environment.populate from: :repo
expect(environment.populated).to eq true
end
it "fails when missing treeish" do
environment.site = site_1
environment.treeish = ''
- expect { environment.populate }.to raise_error RuntimeError, /populate without/
+ expect { environment.populate from: :repo }.to raise_error RuntimeError, /populate without/
end
it "returns itself" do
- expect(environment.populate).to be environment
+ expect(environment.populate from: :repo).to be environment
end
it "will cleanup if populated" do
environment.populate
expect(environment).to receive :cleanup
- environment.populate
+ environment.populate from: :repo
end
end
- context "populate from directory" do
+ context "populate from source" do
- it "copies the source files to the directory" do
+ it "copies the source files to the directory preserving mtime" do
environment.site = site_1
- allow(site_1).to receive(:source).and_return('/path/to/source')
+ site_1.source = '/path/to/source'
allow(Dir).to receive(:[]).with('/path/to/source/*').and_return( %w(dir_1 dir_2) )
- expect(FileUtils).to receive(:cp_r).with( %w(dir_1 dir_2), environment.directory )
+ expect(FileUtils).to receive(:cp_r).with( %w(dir_1 dir_2), environment.directory, preserve: true )
environment.populate from: :source
end
end
end
@@ -187,10 +182,20 @@
describe "methods that modify the working directory" do
let(:config) do
YAML.load <<-EOF
+ :components:
+ :base: _components
+ :paths:
+ - [ my_app/templates, apps/my_app/templates ]
+ - [ my_app/extra, apps/my_app ]
+ :externals:
+ :server: "https://github.com/razor-x"
+ :repos:
+ - [ my_app, apps/my_app, master ]
+ - [ sub_app, apps/my_app/sub_app, my_feature, "https://bitbucket.org/razorx" ]
:assets:
:options:
:output: compiled
:src_pre: "(%"
:sources:
@@ -217,10 +222,89 @@
environment.directory
allow(environment).to receive(:populated).and_return(true)
allow(environment).to receive(:config).and_return(config)
end
+ describe "#components" do
+
+ it "returns an array" do
+ expect(environment.components).to be_a Array
+ end
+
+ it "contains components" do
+ expect(environment.components[0]).to be_a Palimpsest::Component
+ expect(environment.components[1]).to be_a Palimpsest::Component
+ end
+
+ it "sets the components source and install paths" do
+ expect(environment.components[0].source_path).to eq "#{environment.directory}/_components/my_app/templates"
+ expect(environment.components[0].install_path).to eq "#{environment.directory}/apps/my_app/templates"
+ end
+ end
+
+ describe "#install_components" do
+
+ it "installs the components" do
+ expect(environment.components[0]).to receive(:install)
+ expect(environment.components[1]).to receive(:install)
+ environment.install_components
+ end
+
+ it "returns itself" do
+ expect(environment.install_components).to be environment
+ end
+ end
+
+ describe "#externals" do
+
+ it "returns an array" do
+ expect(environment.externals).to be_a Array
+ end
+
+ it "contains externals" do
+ expect(environment.externals[0]).to be_a Palimpsest::External
+ expect(environment.externals[1]).to be_a Palimpsest::External
+ end
+
+ it "sets the externals repo path" do
+ expect(environment.externals[0].repo_path).to eq 'https://github.com/razor-x/my_app'
+ expect(environment.externals[1].repo_path).to eq 'https://bitbucket.org/razorx/sub_app'
+ end
+
+ it "sets the externals branch" do
+ expect(environment.externals[0].branch).to eq 'master'
+ expect(environment.externals[1].branch).to eq 'my_feature'
+ end
+
+ it "sets the install path" do
+ expect(environment.externals[0].install_path).to eq "#{environment.directory}/apps/my_app"
+ expect(environment.externals[1].install_path).to eq "#{environment.directory}/apps/my_app/sub_app"
+ end
+ end
+
+ describe "#install_externals" do
+
+ let(:external_1) { double Palimpsest::External }
+ let(:external_2) { double Palimpsest::External }
+
+ before :each do
+ allow(environment).to receive(:externals).and_return( [ external_1, external_2 ] )
+ allow(external_1).to receive(:install)
+ allow(external_2).to receive(:install)
+ end
+
+ it "installs the externals" do
+ expect(external_1).to receive(:install)
+ expect(external_2).to receive(:install)
+ environment.install_externals
+ end
+
+ it "returns itself" do
+ expect(environment.install_externals).to be environment
+ end
+ end
+
describe "#assets" do
subject(:assets) { environment.assets }
it "returns an array" do
@@ -290,15 +374,15 @@
it "returns itself" do
allow(environment).to receive(:sources_with_assets).and_return([])
expect(environment.compile_assets).to be environment
end
- it "compiles the assets and writes the sources" do
+ it "compiles the assets and writes the sources while preserving mtime" do
allow(environment).to receive(:sources_with_assets).and_return sources
allow(File).to receive(:read).with(sources[0]).and_return('data_1')
allow(File).to receive(:read).with(sources[1]).and_return('data_2')
- expect(Palimpsest::Utility).to receive(:write).with 'data_1', sources[0]
- expect(Palimpsest::Utility).to receive(:write).with 'data_2', sources[1]
+ expect(Palimpsest::Utility).to receive(:write).with 'data_1', sources[0], preserve: true
+ expect(Palimpsest::Utility).to receive(:write).with 'data_2', sources[1], preserve: true
environment.compile_assets
end
end
end
end