require 'spec_helper' require 'vx/common/spawn' require 'fileutils' describe Vx::Router::ScriptBuilder::WebdavCache do let(:path) { '/tmp/.test' } let(:app) { ->(_) { _ } } let(:build) { create :build, branch: "feature" } let(:config) { create :configuration } let(:env) { OpenStruct.new( build: build, init: [], configuration: config, after_script: [], cache_key: ['rvm-1.9.3'] )} let(:mid) { described_class.new app } subject { mid.call env } before do FileUtils.rm_rf path FileUtils.mkdir_p path Vx::Router.configure do |c| c.webdav_cache_url = 'http://localhost:8080' end end after { FileUtils.rm_rf path } it { should eq env } its(:init) { should_not be_empty } its(:after_script) { should_not be_empty } its(:webdav_push_url) { should eq "http://localhost:8080/evrone/test-repo/feature/rvm-1.9.3.tgz" } its(:webdav_fetch_url) { should eq( ["http://localhost:8080/evrone/test-repo/feature/rvm-1.9.3.tgz", "http://localhost:8080/evrone/test-repo/master/rvm-1.9.3.tgz"] ) } context "execute command" do include Vx::Common::Spawn let(:init_script) { env.init.join("\n") } let(:after_script) { env.after_script.join("\n") } before do mid.call env init_script.gsub!("$HOME/cached", path) after_script.gsub!("$HOME/cached", path) end it "should be success" do out = "" code = spawn(init_script, chdir: path) do |o| out << o puts " ===> #{o}" end expect(code).to eq 0 code = spawn(after_script, chdir: path) do |o| out << o puts " ===> #{o}" end expect(code).to eq 0 #twice code = spawn(after_script, chdir: path) do |o| out << o puts " ===> #{o}" end expect(code).to eq 0 #expect(out).to match("adding /tmp/.test to cache") #expect(out).to match("casher successfuly downloaded") end end end