spec/environment_spec.rb in palimpsest-0.1.1 vs spec/environment_spec.rb in palimpsest-0.2.0

- old
+ new

@@ -5,10 +5,14 @@ let(:site_1) { Palimpsest::Site.new name: 'site_1' } let(:site_2) { Palimpsest::Site.new name: 'site_2' } subject(:environment) { Palimpsest::Environment.new } + before :each do + allow(Kernel).to receive(:system) + end + describe ".new" do it "sets default options" do expect(environment.options).to eq Palimpsest::Environment::DEFAULT_OPTIONS end @@ -147,23 +151,22 @@ context "populate from source" do it "copies the source files to the directory preserving mtime" do environment.site = site_1 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, preserve: true ) + expect(Kernel).to receive(:system).with('rsync', '-rt', %q{--exclude='.git/'}, '/path/to/source/', environment.directory) environment.populate from: :source end end end - describe "config" do + describe "#config" do subject(:environment) { Palimpsest::Environment.new site: site_1, treeish: 'master' } before :each do - allow(YAML).to receive(:load_file) + allow(YAML).to receive(:load_file).and_return({}) end it "populate if not populated" do expect(environment).to receive :populate environment.config @@ -178,10 +181,36 @@ it "loads the config if populated" do allow(environment).to receive(:populated).and_return(true) expect(YAML).to receive(:load_file).with("#{environment.directory}/palimpsest_config.yml") environment.config end + + context "settings given" do + + before :each do + allow(YAML).to receive(:load_file).with("#{environment.directory}/palimpsest_config.yml") + .and_return( { conf_1: :val_1, conf_2: :val_2 } ) + end + + it "merges new settings on first call" do + expect( environment.config({ conf_3: :val_3 }) ).to eq({ conf_1: :val_1, conf_2: :val_2, conf_3: :val_3 }) + end + + it "merges new settings on subsequent call" do + environment.config + expect( environment.config({ conf_3: :val_3 }) ).to eq({ conf_1: :val_1, conf_2: :val_2, conf_3: :val_3 }) + end + + it "remembers new settings" do + environment.config({ conf_3: :val_3 }) + expect(environment.config).to eq({ conf_1: :val_1, conf_2: :val_2, conf_3: :val_3 }) + end + + it "overwrites current settings" do + expect( environment.config({ conf_2: :new_val_2 }) ).to eq({ conf_1: :val_1, conf_2: :new_val_2 }) + end + end end describe "methods that modify the working directory" do let(:config) do @@ -194,10 +223,13 @@ :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" ] + :excludes: + - .gitignore + - apps/*/assets :assets: :options: :output: compiled :src_pre: "(%" :sources: @@ -298,9 +330,25 @@ expect(external_1).to receive(:install).and_return(external_1) expect(external_1).to receive(:cleanup) expect(external_2).to receive(:install).and_return(external_2) expect(external_2).to receive(:cleanup) expect(environment.install_externals).to be environment + end + end + + describe "#remove_excludes" do + + it "removes excluded files" do + allow(Dir).to receive(:[]).with("#{environment.directory}/.gitignore") + .and_return(["#{environment.directory}/.gitignore"]) + + allow(Dir).to receive(:[]).with("#{environment.directory}/apps/*/assets") + .and_return( %W(#{environment.directory}/apps/app_1/assets #{environment.directory}/apps/app_2/assets) ) + + expect(FileUtils).to receive(:remove_entry_secure).with("#{environment.directory}/.gitignore") + expect(FileUtils).to receive(:remove_entry_secure).with("#{environment.directory}/apps/app_1/assets") + expect(FileUtils).to receive(:remove_entry_secure).with("#{environment.directory}/apps/app_2/assets") + expect(environment.remove_excludes).to be environment end end describe "#assets" do