Fix coding standards (module nesting) in specs
This commit is contained in:
parent
115561ee88
commit
48a9da9365
@ -1,15 +1,17 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Producer::Core
|
||||
describe Actions::Echo do
|
||||
let(:env) { Env.new(output: StringIO.new) }
|
||||
let(:text) { 'hello' }
|
||||
subject(:echo) { Actions::Echo.new(env, text) }
|
||||
module Actions
|
||||
describe Echo do
|
||||
let(:env) { Env.new(output: StringIO.new) }
|
||||
let(:text) { 'hello' }
|
||||
subject(:echo) { Echo.new(env, text) }
|
||||
|
||||
describe '#apply' do
|
||||
it 'writes the given string to env output with a record separator' do
|
||||
echo.apply
|
||||
expect(env.output.string).to eq "hello\n"
|
||||
describe '#apply' do
|
||||
it 'writes the given string to env output with a record separator' do
|
||||
echo.apply
|
||||
expect(env.output.string).to eq "hello\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,28 +1,30 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Producer::Core
|
||||
describe Actions::FileWriter do
|
||||
let(:env) { Env.new }
|
||||
let(:path) { 'some_path' }
|
||||
let(:content) { 'some_content' }
|
||||
subject(:writer) { Actions::FileWriter.new(env, path, content) }
|
||||
module Actions
|
||||
describe FileWriter do
|
||||
let(:env) { Env.new }
|
||||
let(:path) { 'some_path' }
|
||||
let(:content) { 'some_content' }
|
||||
subject(:writer) { FileWriter.new(env, path, content) }
|
||||
|
||||
describe '#apply' do
|
||||
it 'writes content to file on remote filesystem' do
|
||||
expect(writer.fs).to receive(:file_write).with(path, content)
|
||||
writer.apply
|
||||
describe '#apply' do
|
||||
it 'writes content to file on remote filesystem' do
|
||||
expect(writer.fs).to receive(:file_write).with(path, content)
|
||||
writer.apply
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#path' do
|
||||
it 'returns the path' do
|
||||
expect(writer.path).to eq path
|
||||
describe '#path' do
|
||||
it 'returns the path' do
|
||||
expect(writer.path).to eq path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#content' do
|
||||
it 'returns the content' do
|
||||
expect(writer.content).to eq content
|
||||
describe '#content' do
|
||||
it 'returns the content' do
|
||||
expect(writer.content).to eq content
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,21 +1,23 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Producer::Core
|
||||
describe Actions::Mkdir do
|
||||
let(:env) { Env.new }
|
||||
let(:path) { 'some_path' }
|
||||
subject(:mkdir) { Actions::Mkdir.new(env, path) }
|
||||
module Actions
|
||||
describe Mkdir do
|
||||
let(:env) { Env.new }
|
||||
let(:path) { 'some_path' }
|
||||
subject(:mkdir) { Mkdir.new(env, path) }
|
||||
|
||||
describe '#apply' do
|
||||
it 'creates directory on remote filesystem' do
|
||||
expect(mkdir.fs).to receive(:mkdir).with(path)
|
||||
mkdir.apply
|
||||
describe '#apply' do
|
||||
it 'creates directory on remote filesystem' do
|
||||
expect(mkdir.fs).to receive(:mkdir).with(path)
|
||||
mkdir.apply
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#path' do
|
||||
it 'returns the path' do
|
||||
expect(mkdir.path).to eq path
|
||||
describe '#path' do
|
||||
it 'returns the path' do
|
||||
expect(mkdir.path).to eq path
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,22 +1,24 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Producer::Core
|
||||
describe Actions::ShellCommand do
|
||||
let(:env) { Env.new(output: StringIO.new) }
|
||||
let(:command_args) { 'hello from remote host' }
|
||||
let(:command) { "echo #{command_args}" }
|
||||
subject(:sh) { Actions::ShellCommand.new(env, command) }
|
||||
module Actions
|
||||
describe ShellCommand do
|
||||
let(:env) { Env.new(output: StringIO.new) }
|
||||
let(:command_args) { 'hello from remote host' }
|
||||
let(:command) { "echo #{command_args}" }
|
||||
subject(:sh) { ShellCommand.new(env, command) }
|
||||
|
||||
describe '#apply' do
|
||||
it 'executes the remote command' do
|
||||
expect(sh.remote).to receive(:execute).with(command)
|
||||
sh.apply
|
||||
end
|
||||
describe '#apply' do
|
||||
it 'executes the remote command' do
|
||||
expect(sh.remote).to receive(:execute).with(command)
|
||||
sh.apply
|
||||
end
|
||||
|
||||
it 'writes the returned output with a record separator' do
|
||||
allow(sh.remote).to receive(:execute) { command_args }
|
||||
sh.apply
|
||||
expect(sh.output.string).to eq "#{command_args}\n"
|
||||
it 'writes the returned output with a record separator' do
|
||||
allow(sh.remote).to receive(:execute) { command_args }
|
||||
sh.apply
|
||||
expect(sh.output.string).to eq "#{command_args}\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,76 +1,78 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Producer::Core
|
||||
describe Condition::DSL do
|
||||
let(:block) { proc { :some_condition_code } }
|
||||
let(:env) { double 'env' }
|
||||
subject(:dsl) { Condition::DSL.new(env, &block) }
|
||||
class Condition
|
||||
describe DSL do
|
||||
let(:block) { proc { :some_condition_code } }
|
||||
let(:env) { double 'env' }
|
||||
subject(:dsl) { DSL.new(env, &block) }
|
||||
|
||||
%w[file_contains has_dir has_env has_file].each do |test|
|
||||
it "has `#{test}' test defined" do
|
||||
expect(dsl).to respond_to test.to_sym
|
||||
end
|
||||
end
|
||||
|
||||
describe '.define_test' do
|
||||
let(:some_test_class) { Test }
|
||||
|
||||
before { Condition::DSL.define_test(:some_test, some_test_class) }
|
||||
|
||||
it 'defines a new test keyword' do
|
||||
expect(dsl).to respond_to :some_test
|
||||
end
|
||||
|
||||
it 'defines the negated test' do
|
||||
expect(dsl).to respond_to :no_some_test
|
||||
end
|
||||
|
||||
context 'when a test keyword is called' do
|
||||
it 'registers the test' do
|
||||
expect { dsl.some_test }.to change { dsl.tests.count }.by 1
|
||||
end
|
||||
|
||||
it 'registers the test with current env' do
|
||||
dsl.some_test
|
||||
expect(dsl.tests.first.env).to be env
|
||||
end
|
||||
|
||||
it 'registers the test with given arguments' do
|
||||
dsl.some_test :some, :args
|
||||
expect(dsl.tests.first.arguments).to eq [:some, :args]
|
||||
%w[file_contains has_dir has_env has_file].each do |test|
|
||||
it "has `#{test}' test defined" do
|
||||
expect(dsl).to respond_to test.to_sym
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a negated test keyword is called' do
|
||||
it 'registers a negated test' do
|
||||
dsl.no_some_test
|
||||
expect(dsl.tests.first).to be_negated
|
||||
describe '.define_test' do
|
||||
let(:some_test_class) { Test }
|
||||
|
||||
before { described_class.define_test(:some_test, some_test_class) }
|
||||
|
||||
it 'defines a new test keyword' do
|
||||
expect(dsl).to respond_to :some_test
|
||||
end
|
||||
|
||||
it 'defines the negated test' do
|
||||
expect(dsl).to respond_to :no_some_test
|
||||
end
|
||||
|
||||
context 'when a test keyword is called' do
|
||||
it 'registers the test' do
|
||||
expect { dsl.some_test }.to change { dsl.tests.count }.by 1
|
||||
end
|
||||
|
||||
it 'registers the test with current env' do
|
||||
dsl.some_test
|
||||
expect(dsl.tests.first.env).to be env
|
||||
end
|
||||
|
||||
it 'registers the test with given arguments' do
|
||||
dsl.some_test :some, :args
|
||||
expect(dsl.tests.first.arguments).to eq [:some, :args]
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a negated test keyword is called' do
|
||||
it 'registers a negated test' do
|
||||
dsl.no_some_test
|
||||
expect(dsl.tests.first).to be_negated
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#initialize' do
|
||||
it 'assigns the env' do
|
||||
expect(dsl.env).to be env
|
||||
describe '#initialize' do
|
||||
it 'assigns the env' do
|
||||
expect(dsl.env).to be env
|
||||
end
|
||||
|
||||
it 'assigns the code' do
|
||||
expect(dsl.block).to be block
|
||||
end
|
||||
|
||||
it 'assigns no test' do
|
||||
expect(dsl.tests).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
it 'assigns the code' do
|
||||
expect(dsl.block).to be block
|
||||
end
|
||||
describe '#evaluate' do
|
||||
it 'evaluates its code' do
|
||||
dsl = described_class.new(env) { throw :condition_code }
|
||||
expect { dsl.evaluate }.to throw_symbol :condition_code
|
||||
end
|
||||
|
||||
it 'assigns no test' do
|
||||
expect(dsl.tests).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
describe '#evaluate' do
|
||||
it 'evaluates its code' do
|
||||
dsl = described_class.new(env) { throw :condition_code }
|
||||
expect { dsl.evaluate }.to throw_symbol :condition_code
|
||||
end
|
||||
|
||||
it 'returns the value returned by the assigned block' do
|
||||
expect(dsl.evaluate).to eq block.call
|
||||
it 'returns the value returned by the assigned block' do
|
||||
expect(dsl.evaluate).to eq block.call
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,117 +1,119 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Producer::Core
|
||||
describe Recipe::DSL do
|
||||
include FixturesHelpers
|
||||
class Recipe
|
||||
describe DSL do
|
||||
include FixturesHelpers
|
||||
|
||||
let(:code) { proc { :some_recipe_code } }
|
||||
let(:env) { Env.new }
|
||||
subject(:dsl) { Recipe::DSL.new(env, &code) }
|
||||
let(:code) { proc { :some_recipe_code } }
|
||||
let(:env) { Env.new }
|
||||
subject(:dsl) { DSL.new(env, &code) }
|
||||
|
||||
describe '#initialize' do
|
||||
it 'assigns the given env' do
|
||||
expect(dsl.env).to be env
|
||||
end
|
||||
describe '#initialize' do
|
||||
it 'assigns the given env' do
|
||||
expect(dsl.env).to be env
|
||||
end
|
||||
|
||||
it 'assigns no task' do
|
||||
expect(dsl.tasks).to be_empty
|
||||
end
|
||||
it 'assigns no task' do
|
||||
expect(dsl.tasks).to be_empty
|
||||
end
|
||||
|
||||
context 'when a string of code is given as argument' do
|
||||
let(:code) { 'some_code' }
|
||||
subject(:dsl) { described_class.new(env, code) }
|
||||
context 'when a string of code is given as argument' do
|
||||
let(:code) { 'some_code' }
|
||||
subject(:dsl) { described_class.new(env, code) }
|
||||
|
||||
it 'assigns the string of code' do
|
||||
expect(dsl.code).to eq code
|
||||
it 'assigns the string of code' do
|
||||
expect(dsl.code).to eq code
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a code block is given as argument' do
|
||||
it 'assigns the code block' do
|
||||
expect(dsl.block).to be code
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a code block is given as argument' do
|
||||
it 'assigns the code block' do
|
||||
expect(dsl.block).to be code
|
||||
end
|
||||
end
|
||||
end
|
||||
describe '#tasks' do
|
||||
let(:code) { proc { task(:some_task) {} } }
|
||||
|
||||
describe '#tasks' do
|
||||
let(:code) { proc { task(:some_task) {} } }
|
||||
|
||||
it 'returns registered tasks' do
|
||||
dsl.evaluate
|
||||
expect(dsl.tasks[0].name).to eq :some_task
|
||||
end
|
||||
end
|
||||
|
||||
describe '#evaluate' do
|
||||
it 'evaluates its code' do
|
||||
dsl = described_class.new(env) { throw :recipe_code }
|
||||
expect { dsl.evaluate }.to throw_symbol :recipe_code
|
||||
end
|
||||
|
||||
it 'returns itself' do
|
||||
expect(dsl.evaluate).to eq dsl
|
||||
end
|
||||
end
|
||||
|
||||
describe '#source' do
|
||||
let(:filepath) { fixture_path_for 'recipes/throw' }
|
||||
|
||||
it 'sources the recipe given as argument' do
|
||||
expect { dsl.source filepath }.to throw_symbol :recipe_code
|
||||
end
|
||||
end
|
||||
|
||||
describe '#target' do
|
||||
let(:host) { 'some_host.example' }
|
||||
|
||||
it 'registers the target host in the env' do
|
||||
dsl.target host
|
||||
expect(env.target).to eq host
|
||||
end
|
||||
end
|
||||
|
||||
describe '#task' do
|
||||
it 'registers a new evaluated task' do
|
||||
expect { dsl.task(:some_task) { :some_task_code } }
|
||||
.to change { dsl.tasks.count }.by 1
|
||||
end
|
||||
end
|
||||
|
||||
describe '#macro' do
|
||||
it 'defines the new recipe keyword' do
|
||||
dsl.macro :hello
|
||||
expect(dsl).to respond_to(:hello)
|
||||
end
|
||||
|
||||
context 'when a defined macro is called' do
|
||||
before { dsl.macro(:hello) { :some_macro_code } }
|
||||
|
||||
it 'registers the new task' do
|
||||
expect { dsl.hello }.to change { dsl.tasks.count }.by 1
|
||||
it 'returns registered tasks' do
|
||||
dsl.evaluate
|
||||
expect(dsl.tasks[0].name).to eq :some_task
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a defined macro is called with arguments' do
|
||||
before { dsl.macro(:hello) { |a, b| echo a, b } }
|
||||
describe '#evaluate' do
|
||||
it 'evaluates its code' do
|
||||
dsl = described_class.new(env) { throw :recipe_code }
|
||||
expect { dsl.evaluate }.to throw_symbol :recipe_code
|
||||
end
|
||||
|
||||
it 'evaluates task code with arguments' do
|
||||
dsl.hello :some, :args
|
||||
expect(dsl.tasks.first.actions.first.arguments).to eq [:some, :args]
|
||||
it 'returns itself' do
|
||||
expect(dsl.evaluate).to eq dsl
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#set' do
|
||||
it 'registers a key/value pair in env registry' do
|
||||
dsl.set :some_key, :some_value
|
||||
expect(env[:some_key]).to eq :some_value
|
||||
describe '#source' do
|
||||
let(:filepath) { fixture_path_for 'recipes/throw' }
|
||||
|
||||
it 'sources the recipe given as argument' do
|
||||
expect { dsl.source filepath }.to throw_symbol :recipe_code
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#get' do
|
||||
it 'fetches a value from the registry at given index' do
|
||||
dsl.set :some_key, :some_value
|
||||
expect(dsl.get :some_key).to eq :some_value
|
||||
describe '#target' do
|
||||
let(:host) { 'some_host.example' }
|
||||
|
||||
it 'registers the target host in the env' do
|
||||
dsl.target host
|
||||
expect(env.target).to eq host
|
||||
end
|
||||
end
|
||||
|
||||
describe '#task' do
|
||||
it 'registers a new evaluated task' do
|
||||
expect { dsl.task(:some_task) { :some_task_code } }
|
||||
.to change { dsl.tasks.count }.by 1
|
||||
end
|
||||
end
|
||||
|
||||
describe '#macro' do
|
||||
it 'defines the new recipe keyword' do
|
||||
dsl.macro :hello
|
||||
expect(dsl).to respond_to(:hello)
|
||||
end
|
||||
|
||||
context 'when a defined macro is called' do
|
||||
before { dsl.macro(:hello) { :some_macro_code } }
|
||||
|
||||
it 'registers the new task' do
|
||||
expect { dsl.hello }.to change { dsl.tasks.count }.by 1
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a defined macro is called with arguments' do
|
||||
before { dsl.macro(:hello) { |a, b| echo a, b } }
|
||||
|
||||
it 'evaluates task code with arguments' do
|
||||
dsl.hello :some, :args
|
||||
expect(dsl.tasks.first.actions.first.arguments).to eq [:some, :args]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#set' do
|
||||
it 'registers a key/value pair in env registry' do
|
||||
dsl.set :some_key, :some_value
|
||||
expect(env[:some_key]).to eq :some_value
|
||||
end
|
||||
end
|
||||
|
||||
describe '#get' do
|
||||
it 'fetches a value from the registry at given index' do
|
||||
dsl.set :some_key, :some_value
|
||||
expect(dsl.get :some_key).to eq :some_value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,48 +1,50 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Producer::Core
|
||||
describe Remote::Environment do
|
||||
let(:variables) { { 'FOO' => 'bar', 'BAZ' => 'qux' } }
|
||||
let(:string) { "FOO=bar\nBAZ=qux" }
|
||||
let(:argument) { variables }
|
||||
subject(:environment) { Remote::Environment.new(argument) }
|
||||
class Remote
|
||||
describe Environment do
|
||||
let(:variables) { { 'FOO' => 'bar', 'BAZ' => 'qux' } }
|
||||
let(:string) { "FOO=bar\nBAZ=qux" }
|
||||
let(:argument) { variables }
|
||||
subject(:environment) { Environment.new(argument) }
|
||||
|
||||
describe '.string_to_hash' do
|
||||
it 'converts key=value pairs separated by new lines to a hash' do
|
||||
expect(described_class.string_to_hash(string)).to eq variables
|
||||
end
|
||||
end
|
||||
|
||||
describe '.new_from_string' do
|
||||
it 'returns a new instance with converted keys and values' do
|
||||
environment = described_class.new_from_string string
|
||||
expect(environment.variables).to eq variables
|
||||
end
|
||||
end
|
||||
|
||||
describe '#initialize' do
|
||||
it 'assigns the key/value pairs' do
|
||||
expect(environment.variables).to eq variables
|
||||
end
|
||||
end
|
||||
|
||||
describe '#key?' do
|
||||
context 'when key is defined' do
|
||||
it 'returns true' do
|
||||
expect(environment.key? 'FOO').to be true
|
||||
describe '.string_to_hash' do
|
||||
it 'converts key=value pairs separated by new lines to a hash' do
|
||||
expect(described_class.string_to_hash(string)).to eq variables
|
||||
end
|
||||
end
|
||||
|
||||
context 'when key is not defined' do
|
||||
it 'returns false' do
|
||||
expect(environment.key? 'INEXISTENT_KEY').to be false
|
||||
describe '.new_from_string' do
|
||||
it 'returns a new instance with converted keys and values' do
|
||||
environment = described_class.new_from_string string
|
||||
expect(environment.variables).to eq variables
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#[]' do
|
||||
it 'returns the value indexed by given key' do
|
||||
expect(environment['FOO']).to eq 'bar'
|
||||
describe '#initialize' do
|
||||
it 'assigns the key/value pairs' do
|
||||
expect(environment.variables).to eq variables
|
||||
end
|
||||
end
|
||||
|
||||
describe '#key?' do
|
||||
context 'when key is defined' do
|
||||
it 'returns true' do
|
||||
expect(environment.key? 'FOO').to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when key is not defined' do
|
||||
it 'returns false' do
|
||||
expect(environment.key? 'INEXISTENT_KEY').to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#[]' do
|
||||
it 'returns the value indexed by given key' do
|
||||
expect(environment['FOO']).to eq 'bar'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,97 +1,111 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Producer::Core
|
||||
describe Remote::FS do
|
||||
let(:remote) { Remote.new('some_host.example') }
|
||||
subject(:fs) { Remote::FS.new(remote) }
|
||||
class Remote
|
||||
describe FS do
|
||||
let(:remote) { Remote.new('some_host.example') }
|
||||
subject(:fs) { FS.new(remote) }
|
||||
|
||||
describe '#new' do
|
||||
it 'assigns the remote given as argument' do
|
||||
expect(fs.remote).to be remote
|
||||
end
|
||||
end
|
||||
|
||||
describe '#sftp', :ssh do
|
||||
before { sftp_story }
|
||||
|
||||
it 'builds a new SFTP session' do
|
||||
expect(remote.session.sftp).to receive :connect
|
||||
fs.sftp
|
||||
end
|
||||
|
||||
it 'returns the new SFTP session' do
|
||||
session = double 'session'
|
||||
allow(remote.session.sftp).to receive(:connect) { session }
|
||||
expect(fs.sftp).to be session
|
||||
end
|
||||
|
||||
it 'memoizes the FS' do
|
||||
allow(remote.session.sftp).to receive(:connect) { Object.new }
|
||||
expect(fs.sftp).to be fs.sftp
|
||||
end
|
||||
end
|
||||
|
||||
describe '#dir?' do
|
||||
let(:sftp) { double('sftp').as_null_object }
|
||||
let(:path) { 'some_directory_path' }
|
||||
let(:stat) { double 'stat' }
|
||||
|
||||
before do
|
||||
allow(fs).to receive(:sftp) { sftp }
|
||||
allow(sftp).to receive(:stat!).with(path) { stat }
|
||||
end
|
||||
|
||||
context 'when path given as argument is a directory' do
|
||||
before { allow(stat).to receive(:directory?) { true } }
|
||||
|
||||
it 'returns true' do
|
||||
expect(fs.dir? path).to be true
|
||||
describe '#new' do
|
||||
it 'assigns the remote given as argument' do
|
||||
expect(fs.remote).to be remote
|
||||
end
|
||||
end
|
||||
|
||||
context 'when path given as argument is not a directory' do
|
||||
before { allow(stat).to receive(:directory?) { false } }
|
||||
describe '#sftp', :ssh do
|
||||
before { sftp_story }
|
||||
|
||||
it 'returns false' do
|
||||
expect(fs.dir? path).to be false
|
||||
it 'builds a new SFTP session' do
|
||||
expect(remote.session.sftp).to receive :connect
|
||||
fs.sftp
|
||||
end
|
||||
|
||||
it 'returns the new SFTP session' do
|
||||
session = double 'session'
|
||||
allow(remote.session.sftp).to receive(:connect) { session }
|
||||
expect(fs.sftp).to be session
|
||||
end
|
||||
|
||||
it 'memoizes the FS' do
|
||||
allow(remote.session.sftp).to receive(:connect) { Object.new }
|
||||
expect(fs.sftp).to be fs.sftp
|
||||
end
|
||||
end
|
||||
|
||||
context 'when querying the path raises a Net::SFTP::StatusException' do
|
||||
describe '#dir?' do
|
||||
let(:sftp) { double('sftp').as_null_object }
|
||||
let(:path) { 'some_directory_path' }
|
||||
let(:stat) { double 'stat' }
|
||||
|
||||
before do
|
||||
response = double 'response', code: '42', message: 'some message'
|
||||
ex = Net::SFTP::StatusException.new(response)
|
||||
allow(sftp).to receive(:stat!).with(path).and_raise(ex)
|
||||
allow(fs).to receive(:sftp) { sftp }
|
||||
allow(sftp).to receive(:stat!).with(path) { stat }
|
||||
end
|
||||
|
||||
it 'returns false' do
|
||||
expect(fs.dir? path).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# FIXME: We rely a lot on mocking net-sftp heavily, while we already use a
|
||||
# part of net-ssh story helpers, which are more close to integration tests.
|
||||
describe '#file?', :ssh do
|
||||
let(:file_path) { 'some_file_path' }
|
||||
let(:stat) { double 'stat' }
|
||||
|
||||
before do
|
||||
sftp_story
|
||||
allow(fs.sftp).to receive(:stat!) { stat }
|
||||
end
|
||||
|
||||
context 'when path given as argument exists' do
|
||||
context 'when path is a file' do
|
||||
before { allow(stat).to receive(:file?) { true } }
|
||||
context 'when path given as argument is a directory' do
|
||||
before { allow(stat).to receive(:directory?) { true } }
|
||||
|
||||
it 'returns true' do
|
||||
expect(fs.file? file_path).to be true
|
||||
expect(fs.dir? path).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when path is not a file' do
|
||||
before { allow(stat).to receive(:file?) { false } }
|
||||
context 'when path given as argument is not a directory' do
|
||||
before { allow(stat).to receive(:directory?) { false } }
|
||||
|
||||
it 'returns false' do
|
||||
expect(fs.dir? path).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'when querying the path raises a Net::SFTP::StatusException' do
|
||||
before do
|
||||
response = double 'response', code: '42', message: 'some message'
|
||||
ex = Net::SFTP::StatusException.new(response)
|
||||
allow(sftp).to receive(:stat!).with(path).and_raise(ex)
|
||||
end
|
||||
|
||||
it 'returns false' do
|
||||
expect(fs.dir? path).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# FIXME: We rely a lot on mocking net-sftp heavily, while we already use a
|
||||
# part of net-ssh story helpers, which are more close to integration tests.
|
||||
describe '#file?', :ssh do
|
||||
let(:file_path) { 'some_file_path' }
|
||||
let(:stat) { double 'stat' }
|
||||
|
||||
before do
|
||||
sftp_story
|
||||
allow(fs.sftp).to receive(:stat!) { stat }
|
||||
end
|
||||
|
||||
context 'when path given as argument exists' do
|
||||
context 'when path is a file' do
|
||||
before { allow(stat).to receive(:file?) { true } }
|
||||
|
||||
it 'returns true' do
|
||||
expect(fs.file? file_path).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when path is not a file' do
|
||||
before { allow(stat).to receive(:file?) { false } }
|
||||
|
||||
it 'returns false' do
|
||||
expect(fs.file? file_path).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when querying the path raises a Net::SFTP::StatusException' do
|
||||
before do
|
||||
response = double 'response', code: '42', message: 'some message'
|
||||
ex = Net::SFTP::StatusException.new(response)
|
||||
allow(stat).to receive(:file?).and_raise(ex)
|
||||
end
|
||||
|
||||
it 'returns false' do
|
||||
expect(fs.file? file_path).to be false
|
||||
@ -99,84 +113,72 @@ module Producer::Core
|
||||
end
|
||||
end
|
||||
|
||||
context 'when querying the path raises a Net::SFTP::StatusException' do
|
||||
describe '#mkdir' do
|
||||
let(:sftp) { double 'sftp' }
|
||||
let(:path) { 'some_directory_path' }
|
||||
|
||||
before { allow(fs).to receive(:sftp) { sftp } }
|
||||
|
||||
it 'creates the directory' do
|
||||
expect(sftp).to receive(:mkdir!).with(path)
|
||||
fs.mkdir path
|
||||
end
|
||||
end
|
||||
|
||||
describe '#file_read' do
|
||||
let(:sftp) { double 'sftp' }
|
||||
let(:file) { double 'file' }
|
||||
let(:f) { double 'f' }
|
||||
let(:path) { 'some_file_path' }
|
||||
let(:content) { 'some_content' }
|
||||
|
||||
before do
|
||||
response = double 'response', code: '42', message: 'some message'
|
||||
ex = Net::SFTP::StatusException.new(response)
|
||||
allow(stat).to receive(:file?).and_raise(ex)
|
||||
allow(fs).to receive(:sftp) { sftp }
|
||||
allow(sftp).to receive(:file) { file }
|
||||
allow(file).to receive(:open).and_yield(f)
|
||||
allow(f).to receive(:read) { content }
|
||||
end
|
||||
|
||||
it 'returns false' do
|
||||
expect(fs.file? file_path).to be false
|
||||
it 'returns the file content' do
|
||||
expect(fs.file_read(path)).to eq content
|
||||
end
|
||||
|
||||
context 'when opening the file raises a Net::SFTP::StatusException' do
|
||||
before do
|
||||
response = double 'response', code: '42', message: 'some message'
|
||||
ex = Net::SFTP::StatusException.new(response)
|
||||
allow(file).to receive(:open).and_raise(ex)
|
||||
end
|
||||
|
||||
it 'returns nil' do
|
||||
expect(fs.file_read(path)).to be nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#mkdir' do
|
||||
let(:sftp) { double 'sftp' }
|
||||
let(:path) { 'some_directory_path' }
|
||||
describe '#file_write' do
|
||||
let(:sftp) { double 'sftp' }
|
||||
let(:file) { double 'file' }
|
||||
let(:path) { 'some_file_path' }
|
||||
let(:content) { 'some_content' }
|
||||
|
||||
before { allow(fs).to receive(:sftp) { sftp } }
|
||||
|
||||
it 'creates the directory' do
|
||||
expect(sftp).to receive(:mkdir!).with(path)
|
||||
fs.mkdir path
|
||||
end
|
||||
end
|
||||
|
||||
describe '#file_read' do
|
||||
let(:sftp) { double 'sftp' }
|
||||
let(:file) { double 'file' }
|
||||
let(:f) { double 'f' }
|
||||
let(:path) { 'some_file_path' }
|
||||
let(:content) { 'some_content' }
|
||||
|
||||
before do
|
||||
allow(fs).to receive(:sftp) { sftp }
|
||||
allow(sftp).to receive(:file) { file }
|
||||
allow(file).to receive(:open).and_yield(f)
|
||||
allow(f).to receive(:read) { content }
|
||||
end
|
||||
|
||||
it 'returns the file content' do
|
||||
expect(fs.file_read(path)).to eq content
|
||||
end
|
||||
|
||||
context 'when opening the file raises a Net::SFTP::StatusException' do
|
||||
before do
|
||||
response = double 'response', code: '42', message: 'some message'
|
||||
ex = Net::SFTP::StatusException.new(response)
|
||||
allow(file).to receive(:open).and_raise(ex)
|
||||
allow(fs).to receive(:sftp) { sftp }
|
||||
allow(sftp).to receive(:file) { file }
|
||||
end
|
||||
|
||||
it 'returns nil' do
|
||||
expect(fs.file_read(path)).to be nil
|
||||
it 'opens the file' do
|
||||
expect(file).to receive(:open).with(path, 'w')
|
||||
fs.file_write path, content
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#file_write' do
|
||||
let(:sftp) { double 'sftp' }
|
||||
let(:file) { double 'file' }
|
||||
let(:path) { 'some_file_path' }
|
||||
let(:content) { 'some_content' }
|
||||
|
||||
before do
|
||||
allow(fs).to receive(:sftp) { sftp }
|
||||
allow(sftp).to receive(:file) { file }
|
||||
end
|
||||
|
||||
it 'opens the file' do
|
||||
expect(file).to receive(:open).with(path, 'w')
|
||||
fs.file_write path, content
|
||||
end
|
||||
|
||||
it 'writes the content' do
|
||||
expect(file).to receive(:open).with(any_args) do |&b|
|
||||
expect(file).to receive(:write).with(content)
|
||||
b.call file
|
||||
it 'writes the content' do
|
||||
expect(file).to receive(:open).with(any_args) do |&b|
|
||||
expect(file).to receive(:write).with(content)
|
||||
b.call file
|
||||
end
|
||||
fs.file_write path, content
|
||||
end
|
||||
fs.file_write path, content
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,113 +1,115 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Producer::Core
|
||||
describe Task::DSL do
|
||||
let(:block) { proc {} }
|
||||
let(:env) { Env.new }
|
||||
subject(:dsl) { Task::DSL.new(env, &block) }
|
||||
class Task
|
||||
describe DSL do
|
||||
let(:block) { proc {} }
|
||||
let(:env) { Env.new }
|
||||
subject(:dsl) { DSL.new(env, &block) }
|
||||
|
||||
%w[echo sh mkdir file_write].each do |action|
|
||||
it "has `#{action}' action defined" do
|
||||
expect(dsl).to respond_to action.to_sym
|
||||
end
|
||||
end
|
||||
|
||||
describe '.define_action' do
|
||||
let(:some_action_class) { Class.new(Action) }
|
||||
|
||||
before { described_class.define_action(:some_action, some_action_class) }
|
||||
|
||||
it 'defines a new action keyword' do
|
||||
expect(dsl).to respond_to :some_action
|
||||
end
|
||||
|
||||
context 'when an action keyword is called' do
|
||||
it 'registers the action' do
|
||||
expect { dsl.some_action }.to change { dsl.actions.count }.by 1
|
||||
end
|
||||
|
||||
it 'registers the action with current env' do
|
||||
dsl.some_action
|
||||
expect(dsl.actions.first.env).to be env
|
||||
end
|
||||
|
||||
it 'registers the action with given arguments' do
|
||||
dsl.some_action :some, :args
|
||||
expect(dsl.actions.first.arguments).to eq [:some, :args]
|
||||
%w[echo sh mkdir file_write].each do |action|
|
||||
it "has `#{action}' action defined" do
|
||||
expect(dsl).to respond_to action.to_sym
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#initialize' do
|
||||
it 'assigns the given env' do
|
||||
expect(dsl.env).to be env
|
||||
end
|
||||
describe '.define_action' do
|
||||
let(:some_action_class) { Class.new(Action) }
|
||||
|
||||
it 'assigns the given block' do
|
||||
expect(dsl.block).to be block
|
||||
end
|
||||
before { described_class.define_action(:some_action, some_action_class) }
|
||||
|
||||
it 'assigns no action' do
|
||||
expect(dsl.actions).to be_empty
|
||||
end
|
||||
it 'defines a new action keyword' do
|
||||
expect(dsl).to respond_to :some_action
|
||||
end
|
||||
|
||||
it 'assigns true as the condition' do
|
||||
expect(dsl.condition).to be true
|
||||
end
|
||||
end
|
||||
context 'when an action keyword is called' do
|
||||
it 'registers the action' do
|
||||
expect { dsl.some_action }.to change { dsl.actions.count }.by 1
|
||||
end
|
||||
|
||||
describe '#evaluate' do
|
||||
let(:block) { proc { throw :task_code } }
|
||||
it 'registers the action with current env' do
|
||||
dsl.some_action
|
||||
expect(dsl.actions.first.env).to be env
|
||||
end
|
||||
|
||||
it 'evaluates its code' do
|
||||
expect { dsl.evaluate }
|
||||
.to throw_symbol :task_code
|
||||
end
|
||||
|
||||
context 'when arguments are given' do
|
||||
let(:block) { proc { |e| throw e } }
|
||||
|
||||
it 'passes arguments as block parameters' do
|
||||
expect { dsl.evaluate :some_argument }
|
||||
.to throw_symbol :some_argument
|
||||
it 'registers the action with given arguments' do
|
||||
dsl.some_action :some, :args
|
||||
expect(dsl.actions.first.arguments).to eq [:some, :args]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#condition' do
|
||||
context 'when a block is given' do
|
||||
it 'assigns a new evaluated condition' do
|
||||
dsl.condition { :some_return_value }
|
||||
expect(dsl.condition.return_value).to eq :some_return_value
|
||||
describe '#initialize' do
|
||||
it 'assigns the given env' do
|
||||
expect(dsl.env).to be env
|
||||
end
|
||||
|
||||
it 'assigns the given block' do
|
||||
expect(dsl.block).to be block
|
||||
end
|
||||
|
||||
it 'assigns no action' do
|
||||
expect(dsl.actions).to be_empty
|
||||
end
|
||||
|
||||
it 'assigns true as the condition' do
|
||||
expect(dsl.condition).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#ask' do
|
||||
let(:question) { 'Which letter?' }
|
||||
let(:choices) { [[:a, ?A], [:b, ?B]] }
|
||||
let(:prompter_class) { double('prompter class').as_null_object }
|
||||
subject(:ask) { dsl.ask question, choices,
|
||||
prompter: prompter_class }
|
||||
describe '#evaluate' do
|
||||
let(:block) { proc { throw :task_code } }
|
||||
|
||||
it 'builds a prompter' do
|
||||
expect(prompter_class).to receive(:new).with(env.input, env.output)
|
||||
ask
|
||||
it 'evaluates its code' do
|
||||
expect { dsl.evaluate }
|
||||
.to throw_symbol :task_code
|
||||
end
|
||||
|
||||
context 'when arguments are given' do
|
||||
let(:block) { proc { |e| throw e } }
|
||||
|
||||
it 'passes arguments as block parameters' do
|
||||
expect { dsl.evaluate :some_argument }
|
||||
.to throw_symbol :some_argument
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'prompts and returns the choice' do
|
||||
prompter = double 'prompter'
|
||||
allow(prompter_class).to receive(:new) { prompter }
|
||||
allow(prompter).to receive(:prompt) { :choice }
|
||||
expect(ask).to eq :choice
|
||||
describe '#condition' do
|
||||
context 'when a block is given' do
|
||||
it 'assigns a new evaluated condition' do
|
||||
dsl.condition { :some_return_value }
|
||||
expect(dsl.condition.return_value).to eq :some_return_value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#get' do
|
||||
let(:env) { Env.new(registry: { some_key: :some_value }) }
|
||||
describe '#ask' do
|
||||
let(:question) { 'Which letter?' }
|
||||
let(:choices) { [[:a, ?A], [:b, ?B]] }
|
||||
let(:prompter_class) { double('prompter class').as_null_object }
|
||||
subject(:ask) { dsl.ask question, choices,
|
||||
prompter: prompter_class }
|
||||
|
||||
it 'fetches a value from the registry at given index' do
|
||||
expect(dsl.get :some_key).to eq :some_value
|
||||
it 'builds a prompter' do
|
||||
expect(prompter_class).to receive(:new).with(env.input, env.output)
|
||||
ask
|
||||
end
|
||||
|
||||
it 'prompts and returns the choice' do
|
||||
prompter = double 'prompter'
|
||||
allow(prompter_class).to receive(:new) { prompter }
|
||||
allow(prompter).to receive(:prompt) { :choice }
|
||||
expect(ask).to eq :choice
|
||||
end
|
||||
end
|
||||
|
||||
describe '#get' do
|
||||
let(:env) { Env.new(registry: { some_key: :some_value }) }
|
||||
|
||||
it 'fetches a value from the registry at given index' do
|
||||
expect(dsl.get :some_key).to eq :some_value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -49,7 +49,7 @@ module Producer::Core
|
||||
end
|
||||
|
||||
context 'when only the name is given as argument' do
|
||||
subject(:task) { Task.new(name) }
|
||||
subject(:task) { described_class.new(name) }
|
||||
|
||||
it 'assigns no action' do
|
||||
expect(task.actions).to be_empty
|
||||
|
@ -1,42 +1,49 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Producer::Core
|
||||
describe Tests::FileContains do
|
||||
let(:env) { Env.new }
|
||||
let(:filepath) { 'some_file' }
|
||||
let(:content) { 'some_content' }
|
||||
subject(:test) { Tests::FileContains.new(env, filepath, content) }
|
||||
module Tests
|
||||
describe FileContains do
|
||||
let(:env) { Env.new }
|
||||
let(:filepath) { 'some_file' }
|
||||
let(:content) { 'some_content' }
|
||||
subject(:test) { FileContains.new(env, filepath, content) }
|
||||
|
||||
it 'is a kind of test' do
|
||||
expect(test).to be_a Test
|
||||
end
|
||||
|
||||
describe '#verify' do
|
||||
let(:fs) { double 'fs' }
|
||||
|
||||
before { allow(test).to receive(:fs) { fs } }
|
||||
|
||||
context 'when file contains the content' do
|
||||
before { allow(fs).to receive(:file_read).with(filepath) { "foo#{content}bar" } }
|
||||
|
||||
it 'returns true' do
|
||||
expect(test.verify).to be true
|
||||
end
|
||||
it 'is a kind of test' do
|
||||
expect(test).to be_a Test
|
||||
end
|
||||
|
||||
context 'when file does not contain the content' do
|
||||
before { allow(fs).to receive(:file_read).with(filepath) { 'foo bar' } }
|
||||
describe '#verify' do
|
||||
let(:fs) { double 'fs' }
|
||||
|
||||
it 'returns false' do
|
||||
expect(test.verify).to be false
|
||||
before { allow(test).to receive(:fs) { fs } }
|
||||
|
||||
context 'when file contains the content' do
|
||||
before do
|
||||
allow(fs)
|
||||
.to receive(:file_read).with(filepath) { "foo#{content}bar" }
|
||||
end
|
||||
|
||||
it 'returns true' do
|
||||
expect(test.verify).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when file does not exist' do
|
||||
before { allow(fs).to receive(:file_read).with(filepath) { nil } }
|
||||
context 'when file does not contain the content' do
|
||||
before do
|
||||
allow(fs).to receive(:file_read).with(filepath) { 'foo bar' }
|
||||
end
|
||||
|
||||
it 'returns false' do
|
||||
expect(test.verify).to be false
|
||||
it 'returns false' do
|
||||
expect(test.verify).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'when file does not exist' do
|
||||
before { allow(fs).to receive(:file_read).with(filepath) { nil } }
|
||||
|
||||
it 'returns false' do
|
||||
expect(test.verify).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,27 +1,29 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Producer::Core
|
||||
describe Tests::HasDir do
|
||||
let(:env) { Env.new }
|
||||
let(:path) { 'some_directory' }
|
||||
subject(:has_dir) { Tests::HasDir.new(env, path) }
|
||||
module Tests
|
||||
describe HasDir do
|
||||
let(:env) { Env.new }
|
||||
let(:path) { 'some_directory' }
|
||||
subject(:has_dir) { HasDir.new(env, path) }
|
||||
|
||||
it 'is a kind of test' do
|
||||
expect(has_dir).to be_a Test
|
||||
end
|
||||
|
||||
describe '#verify', :ssh do
|
||||
before { sftp_story }
|
||||
|
||||
it 'delegates the call on remote FS' do
|
||||
expect(env.remote.fs).to receive(:dir?).with(path)
|
||||
has_dir.verify
|
||||
it 'is a kind of test' do
|
||||
expect(has_dir).to be_a Test
|
||||
end
|
||||
|
||||
it 'returns the dir existence' do
|
||||
existence = double 'existence'
|
||||
allow(env.remote.fs).to receive(:dir?) { existence }
|
||||
expect(has_dir.verify).to be existence
|
||||
describe '#verify', :ssh do
|
||||
before { sftp_story }
|
||||
|
||||
it 'delegates the call on remote FS' do
|
||||
expect(env.remote.fs).to receive(:dir?).with(path)
|
||||
has_dir.verify
|
||||
end
|
||||
|
||||
it 'returns the dir existence' do
|
||||
existence = double 'existence'
|
||||
allow(env.remote.fs).to receive(:dir?) { existence }
|
||||
expect(has_dir.verify).to be existence
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,40 +1,42 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Producer::Core
|
||||
describe Tests::HasEnv do
|
||||
let(:env) { Env.new }
|
||||
let(:variable_name) { :some_variable_name }
|
||||
subject(:has_env) { Tests::HasEnv.new(env, variable_name) }
|
||||
module Tests
|
||||
describe HasEnv do
|
||||
let(:env) { Env.new }
|
||||
let(:variable_name) { :some_variable_name }
|
||||
subject(:has_env) { HasEnv.new(env, variable_name) }
|
||||
|
||||
it 'is a kind of test' do
|
||||
expect(has_env).to be_a Test
|
||||
end
|
||||
|
||||
describe '#verify' do
|
||||
let(:environment) { double 'environment' }
|
||||
|
||||
before do
|
||||
allow(env.remote).to receive(:environment) { environment }
|
||||
it 'is a kind of test' do
|
||||
expect(has_env).to be_a Test
|
||||
end
|
||||
|
||||
it 'stringifies the queried variable name' do
|
||||
expect(environment).to receive(:key?).with(kind_of(String))
|
||||
has_env.verify
|
||||
end
|
||||
describe '#verify' do
|
||||
let(:environment) { double 'environment' }
|
||||
|
||||
it 'upcases the queried variable name' do
|
||||
expect(environment).to receive(:key?).with('SOME_VARIABLE_NAME')
|
||||
has_env.verify
|
||||
end
|
||||
before do
|
||||
allow(env.remote).to receive(:environment) { environment }
|
||||
end
|
||||
|
||||
it 'returns true when remote environment var is defined' do
|
||||
allow(environment).to receive(:key?) { true }
|
||||
expect(has_env.verify).to be true
|
||||
end
|
||||
it 'stringifies the queried variable name' do
|
||||
expect(environment).to receive(:key?).with(kind_of(String))
|
||||
has_env.verify
|
||||
end
|
||||
|
||||
it 'returns false when remote environment var is not defined' do
|
||||
allow(environment).to receive(:key?) { false }
|
||||
expect(has_env.verify).to be false
|
||||
it 'upcases the queried variable name' do
|
||||
expect(environment).to receive(:key?).with('SOME_VARIABLE_NAME')
|
||||
has_env.verify
|
||||
end
|
||||
|
||||
it 'returns true when remote environment var is defined' do
|
||||
allow(environment).to receive(:key?) { true }
|
||||
expect(has_env.verify).to be true
|
||||
end
|
||||
|
||||
it 'returns false when remote environment var is not defined' do
|
||||
allow(environment).to receive(:key?) { false }
|
||||
expect(has_env.verify).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,27 +1,29 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Producer::Core
|
||||
describe Tests::HasFile do
|
||||
let(:env) { Env.new }
|
||||
let(:filepath) { 'some_file' }
|
||||
subject(:has_file) { Tests::HasFile.new(env, filepath) }
|
||||
module Tests
|
||||
describe HasFile do
|
||||
let(:env) { Env.new }
|
||||
let(:filepath) { 'some_file' }
|
||||
subject(:has_file) { HasFile.new(env, filepath) }
|
||||
|
||||
it 'is a kind of test' do
|
||||
expect(has_file).to be_a Test
|
||||
end
|
||||
|
||||
describe '#verify', :ssh do
|
||||
before { sftp_story }
|
||||
|
||||
it 'delegates the call on remote FS' do
|
||||
expect(env.remote.fs).to receive(:file?).with(filepath)
|
||||
has_file.verify
|
||||
it 'is a kind of test' do
|
||||
expect(has_file).to be_a Test
|
||||
end
|
||||
|
||||
it 'returns the file existence' do
|
||||
existence = double 'existence'
|
||||
allow(env.remote.fs).to receive(:file?) { existence }
|
||||
expect(has_file.verify).to be existence
|
||||
describe '#verify', :ssh do
|
||||
before { sftp_story }
|
||||
|
||||
it 'delegates the call on remote FS' do
|
||||
expect(env.remote.fs).to receive(:file?).with(filepath)
|
||||
has_file.verify
|
||||
end
|
||||
|
||||
it 'returns the file existence' do
|
||||
existence = double 'existence'
|
||||
allow(env.remote.fs).to receive(:file?) { existence }
|
||||
expect(has_file.verify).to be existence
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user