Fix coding standards (module nesting) in specs

This commit is contained in:
Thibault Jouan 2014-02-08 17:59:33 +00:00
parent 115561ee88
commit 48a9da9365
14 changed files with 590 additions and 559 deletions

View File

@ -1,10 +1,11 @@
require 'spec_helper'
module Producer::Core
describe Actions::Echo do
module Actions
describe Echo do
let(:env) { Env.new(output: StringIO.new) }
let(:text) { 'hello' }
subject(:echo) { Actions::Echo.new(env, text) }
subject(:echo) { Echo.new(env, text) }
describe '#apply' do
it 'writes the given string to env output with a record separator' do
@ -14,3 +15,4 @@ module Producer::Core
end
end
end
end

View File

@ -1,11 +1,12 @@
require 'spec_helper'
module Producer::Core
describe Actions::FileWriter do
module Actions
describe FileWriter do
let(:env) { Env.new }
let(:path) { 'some_path' }
let(:content) { 'some_content' }
subject(:writer) { Actions::FileWriter.new(env, path, content) }
subject(:writer) { FileWriter.new(env, path, content) }
describe '#apply' do
it 'writes content to file on remote filesystem' do
@ -27,3 +28,4 @@ module Producer::Core
end
end
end
end

View File

@ -1,10 +1,11 @@
require 'spec_helper'
module Producer::Core
describe Actions::Mkdir do
module Actions
describe Mkdir do
let(:env) { Env.new }
let(:path) { 'some_path' }
subject(:mkdir) { Actions::Mkdir.new(env, path) }
subject(:mkdir) { Mkdir.new(env, path) }
describe '#apply' do
it 'creates directory on remote filesystem' do
@ -20,3 +21,4 @@ module Producer::Core
end
end
end
end

View File

@ -1,11 +1,12 @@
require 'spec_helper'
module Producer::Core
describe Actions::ShellCommand do
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) { Actions::ShellCommand.new(env, command) }
subject(:sh) { ShellCommand.new(env, command) }
describe '#apply' do
it 'executes the remote command' do
@ -21,3 +22,4 @@ module Producer::Core
end
end
end
end

View File

@ -1,10 +1,11 @@
require 'spec_helper'
module Producer::Core
describe Condition::DSL do
class Condition
describe DSL do
let(:block) { proc { :some_condition_code } }
let(:env) { double 'env' }
subject(:dsl) { Condition::DSL.new(env, &block) }
subject(:dsl) { DSL.new(env, &block) }
%w[file_contains has_dir has_env has_file].each do |test|
it "has `#{test}' test defined" do
@ -15,7 +16,7 @@ module Producer::Core
describe '.define_test' do
let(:some_test_class) { Test }
before { Condition::DSL.define_test(:some_test, some_test_class) }
before { described_class.define_test(:some_test, some_test_class) }
it 'defines a new test keyword' do
expect(dsl).to respond_to :some_test
@ -75,3 +76,4 @@ module Producer::Core
end
end
end
end

View File

@ -1,12 +1,13 @@
require 'spec_helper'
module Producer::Core
describe Recipe::DSL do
class Recipe
describe DSL do
include FixturesHelpers
let(:code) { proc { :some_recipe_code } }
let(:env) { Env.new }
subject(:dsl) { Recipe::DSL.new(env, &code) }
subject(:dsl) { DSL.new(env, &code) }
describe '#initialize' do
it 'assigns the given env' do
@ -116,3 +117,4 @@ module Producer::Core
end
end
end
end

View File

@ -1,11 +1,12 @@
require 'spec_helper'
module Producer::Core
describe Remote::Environment do
class Remote
describe Environment do
let(:variables) { { 'FOO' => 'bar', 'BAZ' => 'qux' } }
let(:string) { "FOO=bar\nBAZ=qux" }
let(:argument) { variables }
subject(:environment) { Remote::Environment.new(argument) }
subject(:environment) { Environment.new(argument) }
describe '.string_to_hash' do
it 'converts key=value pairs separated by new lines to a hash' do
@ -47,3 +48,4 @@ module Producer::Core
end
end
end
end

View File

@ -1,9 +1,10 @@
require 'spec_helper'
module Producer::Core
describe Remote::FS do
class Remote
describe FS do
let(:remote) { Remote.new('some_host.example') }
subject(:fs) { Remote::FS.new(remote) }
subject(:fs) { FS.new(remote) }
describe '#new' do
it 'assigns the remote given as argument' do
@ -181,3 +182,4 @@ module Producer::Core
end
end
end
end

View File

@ -1,10 +1,11 @@
require 'spec_helper'
module Producer::Core
describe Task::DSL do
class Task
describe DSL do
let(:block) { proc {} }
let(:env) { Env.new }
subject(:dsl) { Task::DSL.new(env, &block) }
subject(:dsl) { DSL.new(env, &block) }
%w[echo sh mkdir file_write].each do |action|
it "has `#{action}' action defined" do
@ -112,3 +113,4 @@ module Producer::Core
end
end
end
end

View File

@ -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

View File

@ -1,11 +1,12 @@
require 'spec_helper'
module Producer::Core
describe Tests::FileContains do
module Tests
describe FileContains do
let(:env) { Env.new }
let(:filepath) { 'some_file' }
let(:content) { 'some_content' }
subject(:test) { Tests::FileContains.new(env, filepath, content) }
subject(:test) { FileContains.new(env, filepath, content) }
it 'is a kind of test' do
expect(test).to be_a Test
@ -17,7 +18,10 @@ module Producer::Core
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" } }
before do
allow(fs)
.to receive(:file_read).with(filepath) { "foo#{content}bar" }
end
it 'returns true' do
expect(test.verify).to be true
@ -25,7 +29,9 @@ module Producer::Core
end
context 'when file does not contain the content' do
before { allow(fs).to receive(:file_read).with(filepath) { 'foo bar' } }
before do
allow(fs).to receive(:file_read).with(filepath) { 'foo bar' }
end
it 'returns false' do
expect(test.verify).to be false
@ -42,3 +48,4 @@ module Producer::Core
end
end
end
end

View File

@ -1,10 +1,11 @@
require 'spec_helper'
module Producer::Core
describe Tests::HasDir do
module Tests
describe HasDir do
let(:env) { Env.new }
let(:path) { 'some_directory' }
subject(:has_dir) { Tests::HasDir.new(env, path) }
subject(:has_dir) { HasDir.new(env, path) }
it 'is a kind of test' do
expect(has_dir).to be_a Test
@ -26,3 +27,4 @@ module Producer::Core
end
end
end
end

View File

@ -1,10 +1,11 @@
require 'spec_helper'
module Producer::Core
describe Tests::HasEnv do
module Tests
describe HasEnv do
let(:env) { Env.new }
let(:variable_name) { :some_variable_name }
subject(:has_env) { Tests::HasEnv.new(env, variable_name) }
subject(:has_env) { HasEnv.new(env, variable_name) }
it 'is a kind of test' do
expect(has_env).to be_a Test
@ -39,3 +40,4 @@ module Producer::Core
end
end
end
end

View File

@ -1,10 +1,11 @@
require 'spec_helper'
module Producer::Core
describe Tests::HasFile do
module Tests
describe HasFile do
let(:env) { Env.new }
let(:filepath) { 'some_file' }
subject(:has_file) { Tests::HasFile.new(env, filepath) }
subject(:has_file) { HasFile.new(env, filepath) }
it 'is a kind of test' do
expect(has_file).to be_a Test
@ -26,3 +27,4 @@ module Producer::Core
end
end
end
end