spec/lib/builder/source_spec.rb in vx-builder-0.0.12 vs spec/lib/builder/source_spec.rb in vx-builder-0.0.13

- old
+ new

@@ -1,10 +1,11 @@ require 'spec_helper' describe Vx::Builder::Source do - let(:content) { YAML.load fixture('travis.yml') } - let(:config) { described_class.from_attributes content } + let(:default_content) { YAML.load fixture('travis.yml') } + let(:content) { default_content } + let(:config) { described_class.from_attributes content } subject { config } its(:attributes) { should be } its(:rvm) { should eq %w{ 2.0.0 } } its(:gemfile) { should eq %w{ Gemfile } } @@ -22,17 +23,41 @@ it "should replace attributes" do expect(subject.attributes["rvm"]).to eq %w{ replaced } end end + context "cached_directories" do + subject { config.cached_directories } + context "when cache is false" do + let(:content) { default_content.merge("cache" => false) } + it { should be_false } + end + context "when cache is nil" do + let(:content) { default_content.delete("cache") && default_content } + it { should eq [] } + end + + context "when cache.directories is nil" do + let(:content) { default_content["cache"].delete("directories") && default_content } + it { should eq [] } + end + + context "when exists" do + it { should eq ["~/.cache"] } + end + end + context "(serialization)" do context "build new instance" do let(:expected) { { "rvm" => ["2.0.0"], "gemfile" => ["Gemfile"], "before_script" => ["echo before_script"], + "cache" => { + "directories"=>["~/.cache"] + }, "before_install" => ["echo before_install"], "script" => ["RAILS_ENV=test ls -1 && echo DONE!"], "env" => { "matrix" => [], "global" => [] @@ -53,10 +78,13 @@ let(:attrs) {{ rvm: "2.0.0", gemfile: "Gemfile", before_script: "echo before_script", before_install: "echo before_install", - script: "RAILS_ENV=test ls -1 && echo DONE!" + script: "RAILS_ENV=test ls -1 && echo DONE!", + cache: { + "directories" => ["~/.cache"] + } }} subject { described_class.from_attributes(attrs).attributes } it { should eq expected } end end