Skip to content

Commit

Permalink
cleanup formatting of rspec tests and helpers [skip-ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
reset committed Dec 30, 2013
1 parent e35ee52 commit 4d270c7
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 81 deletions.
1 change: 1 addition & 0 deletions spec/support/git.rb
Expand Up @@ -82,6 +82,7 @@ def remote_path(repo)
end

private

# The path to store the local git clones.
#
# @return [Pathname]
Expand Down
73 changes: 37 additions & 36 deletions spec/support/mercurial.rb
Expand Up @@ -77,46 +77,47 @@ def remote_path(repo)
end

private
# The path to store the local git clones.
#
# @return [Pathname]
def clones
ensure_and_return(tmp_path.join('clones'))
end

# The path to store the git remotes.
#
# @return [Pathname]
def remotes
ensure_and_return(tmp_path.join('remotes'))
end
# The path to store the local git clones.
#
# @return [Pathname]
def clones
ensure_and_return(tmp_path.join('clones'))
end

# Generate a cookbook by the given name.
#
# @param [#to_s] name
# the name of the cookbook to create
# @param [Hash] options
# the list ooptions to pass to the generator
def generate_mercurial_cookbook(name, options = {})
options = {
skip_vagrant: true,
skip_test_kitchen: true,
force: true,
}.merge(options)
# The path to store the git remotes.
#
# @return [Pathname]
def remotes
ensure_and_return(tmp_path.join('remotes'))
end

Berkshelf::Cli.new.invoke(:cookbook, [name.to_s], options)
end
# Generate a cookbook by the given name.
#
# @param [#to_s] name
# the name of the cookbook to create
# @param [Hash] options
# the list ooptions to pass to the generator
def generate_mercurial_cookbook(name, options = {})
options = {
skip_vagrant: true,
skip_test_kitchen: true,
force: true,
}.merge(options)

# Make sure the given path exists and return the path
#
# @param [#to_s] path
# the path to create and return
#
# @return [Pathname]
def ensure_and_return(path)
FileUtils.mkdir(path) unless File.exist?(path)
return Pathname.new(path).expand_path
end
Berkshelf::Cli.new.invoke(:cookbook, [name.to_s], options)
end

# Make sure the given path exists and return the path
#
# @param [#to_s] path
# the path to create and return
#
# @return [Pathname]
def ensure_and_return(path)
FileUtils.mkdir(path) unless File.exist?(path)
return Pathname.new(path).expand_path
end
end
end
end
5 changes: 3 additions & 2 deletions spec/unit/berkshelf/cli_spec.rb
Expand Up @@ -4,12 +4,13 @@
let(:subject) { described_class.new }
let(:berksfile) { double('Berksfile') }
let(:cookbooks) { ['mysql'] }

describe '#upload' do
it 'calls to upload with params if passed in cli' do
Berkshelf::Berksfile.should_receive(:from_file).and_return(berksfile)
berksfile.should_receive(:upload).with(include(:skip_syntax_check => true, :freeze => false, :cookbooks => cookbooks))
berksfile.should_receive(:upload).with(include(skip_syntax_check: true, freeze: false, cookbooks: cookbooks))
subject.options[:skip_syntax_check] = true
subject.options[:no_freeze] = true
subject.options[:no_freeze] = true
subject.upload('mysql')
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/berkshelf/config_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'

describe Berkshelf::Config do
describe '.file' do
describe '::file' do
context 'when the file does not exist' do
before { File.stub(:exists?).and_return(false) }

Expand All @@ -11,13 +11,13 @@
end
end

describe '.instance' do
describe '::instance' do
it 'should be a Berkshelf::Config' do
expect(Berkshelf::Config.instance).to be_an_instance_of(Berkshelf::Config)
end
end

describe '.path' do
describe '::path' do
it 'is a string' do
expect(Berkshelf::Config.path).to be_a(String)
end
Expand Down
8 changes: 4 additions & 4 deletions spec/unit/berkshelf/formatters_spec.rb
Expand Up @@ -13,7 +13,7 @@
let(:format_id) { :rspec }
let(:format_klass) { Class.new { include Berkshelf::Formatters::AbstractFormatter } }

describe '.register' do
describe '::register' do
it 'adds the class of the includer to the list of registered formatters with the id' do
Berkshelf::Formatters.register(format_id, format_klass)

Expand Down Expand Up @@ -41,7 +41,7 @@
end
end

describe '.formatters' do
describe '::formatters' do
before do
Berkshelf::Formatters.register(format_id, format_klass)
end
Expand All @@ -54,7 +54,7 @@
end
end

describe '.get' do
describe '::get' do
before { Berkshelf::Formatters.register(format_id, format_klass) }

it 'returns the class constant of the given formatter ID' do
Expand All @@ -69,7 +69,7 @@
end

describe Berkshelf::Formatters::AbstractFormatter do
describe '.register_formatter' do
describe '::register_formatter' do
it 'delegates to Formatters' do
Berkshelf::Formatters.should_receive(:register).with(:rspec, format_klass)

Expand Down
16 changes: 8 additions & 8 deletions spec/unit/berkshelf/git_spec.rb
Expand Up @@ -3,7 +3,7 @@
describe Berkshelf::Git do
let(:git) { Berkshelf::Git }

describe '.find_git' do
describe '::find_git' do
it 'finds git' do
expect(Berkshelf::Git.find_git).to_not be_nil
end
Expand All @@ -17,7 +17,7 @@
end
end

describe '.clone' do
describe '::clone' do
let(:target) { clone_path('nginx') }

it 'clones the repository to the target path' do
Expand All @@ -29,7 +29,7 @@
end
end

describe '.checkout' do
describe '::checkout' do
let(:repo_path) { clone_path('nginx') }
let(:repo) {
origin_uri = git_origin_for('nginx', tags: ['1.0.1', '1.0.2'], branches: ['topic', 'next_topic'])
Expand Down Expand Up @@ -90,7 +90,7 @@
end
end

describe '.rev_parse' do
describe '::rev_parse' do
let(:repo_path) { clone_path('nginx') }
before(:each) do |example|
origin_uri = git_origin_for('nginx', tags: ['1.1.1'])
Expand All @@ -106,7 +106,7 @@
end
end

describe '.show_ref' do
describe '::show_ref' do
let(:repo_path) { clone_path('nginx') }
let(:tags) { ['1.0.1'] }
let(:branches) { ['topic'] }
Expand Down Expand Up @@ -140,7 +140,7 @@
end
end

describe '.revision_from_ref' do
describe '::revision_from_ref' do
let(:repo_path) { clone_path('nginx') }
let(:tags) { ['1.0.1'] }
let(:branches) { ['topic'] }
Expand Down Expand Up @@ -188,7 +188,7 @@
let(:http_uri) { 'http://github.com/reset/solve.git' }
let(:invalid_uri) { '/something/on/disk' }

describe '.validate_uri' do
describe '::validate_uri' do
context 'given a valid Git read-only URI' do
it 'returns true' do
expect(Berkshelf::Git.validate_uri(readonly_uri)).to be_true
Expand Down Expand Up @@ -262,7 +262,7 @@
end
end

describe '.validate_uri!' do
describe '::validate_uri!' do
context 'given a valid Git read-only URI' do
it 'returns true' do
expect(Berkshelf::Git.validate_uri!(readonly_uri)).to be_true
Expand Down
23 changes: 5 additions & 18 deletions spec/unit/berkshelf/locations/mercurial_location_spec.rb
@@ -1,23 +1,22 @@
require 'spec_helper'

describe Berkshelf::MercurialLocation do

include Berkshelf::RSpec::Mercurial

let(:cookbook_uri) { mercurial_origin_for('fake_cookbook', is_cookbook: true, tags: ["1.0.0"], branches: ["mybranch"]) }
let(:constraint) { double('comp-vconstraint', satisfies?: true) }
let(:dependency) { double('dep', name: "berkshelf-cookbook-fixture", version_constraint: constraint) }
let(:storage_path) { Berkshelf::CookbookStore.instance.storage_path }

describe '.initialize' do
describe '::initialize' do
it 'raises InvalidHgURI if given an invalid URI for options[:hg]' do
expect {
described_class.new(dependency, hg: '/something/on/disk')
}.to raise_error(Berkshelf::InvalidHgURI)
end
end

describe '.tmpdir' do
describe '::tmpdir' do
it 'creates a temporary directory within the Berkshelf temporary directory' do
expect(described_class.tmpdir).to include(Berkshelf.tmp_dir)
end
Expand All @@ -26,9 +25,7 @@
subject { described_class.new(dependency, hg: cookbook_uri) }

describe '#download' do

before() do
# recreate the fake repo
before do
clean_tmp_path
FileUtils.mkdir_p(storage_path)
cookbook_uri
Expand Down Expand Up @@ -113,13 +110,8 @@

context 'given a value for tag' do
let(:tag) { '1.0.0' }
subject { described_class.new(dependency, hg: cookbook_uri, tag: tag) }

subject do
described_class.new(dependency,
hg: cookbook_uri,
tag: tag
)
end
let(:cached) { subject.download }
let(:sha) { subject.rev }
let(:expected_path) { storage_path.join("#{cached.cookbook_name}-#{sha}") }
Expand All @@ -131,13 +123,8 @@

context 'give a value for branch' do
let(:branch) { 'mybranch' }
subject { described_class.new(dependency, hg: cookbook_uri, branch: branch) }

subject do
described_class.new(dependency,
hg: cookbook_uri,
branch: branch
)
end
let(:cached) { subject.download }
let(:sha) { subject.rev }
let(:expected_path) { storage_path.join("#{cached.cookbook_name}-#{sha}") }
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/berkshelf/lockfile_spec.rb
Expand Up @@ -8,7 +8,7 @@
File.stub(:read).and_return(content)
end

describe '.initialize' do
describe '::initialize' do
it 'does not throw an exception' do
expect {
Berkshelf::Lockfile.from_berksfile(berksfile)
Expand Down
13 changes: 6 additions & 7 deletions spec/unit/berkshelf/mercurial_spec.rb
@@ -1,12 +1,11 @@
require 'spec_helper'

describe Berkshelf::Mercurial do

include Berkshelf::RSpec::Mercurial

let(:hg) { Berkshelf::Mercurial }

describe '.find_hg' do
describe '::find_hg' do
it 'finds hg' do
expect(described_class.find_hg).to_not be_nil
end
Expand All @@ -20,7 +19,7 @@
end
end

describe '.clone' do
describe '::clone' do
let(:target) { clone_path('nginx') }

it 'clones the repository to the target path' do
Expand All @@ -33,7 +32,7 @@
end
end

describe '.checkout' do
describe '::checkout' do
let(:repo_path) { clone_path('nginx') }
let(:repo) {
origin_uri = mercurial_origin_for('nginx', tags: ['1.0.1', '1.0.2'], branches: ['topic', 'next_topic'])
Expand Down Expand Up @@ -94,7 +93,7 @@
end
end

describe '.rev_parse' do
describe '::rev_parse' do
let(:repo_path) { clone_path('nginx') }

before(:each) do
Expand All @@ -115,7 +114,7 @@
let(:http_uri) { 'http://hghub.com/reset/' }
let(:invalid_uri) { '/something/on/disk' }

describe '.validate_uri' do
describe '::validate_uri' do
context 'given an invalid URI' do
it 'returns false' do
expect(described_class.validate_uri(invalid_uri)).to be_false
Expand All @@ -141,7 +140,7 @@
end
end

describe '.validate_uri!' do
describe '::validate_uri!' do
context 'given an invalid URI' do
it 'raises InvalidHgURI' do
expect {
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/berkshelf_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'

describe Berkshelf do
describe '.formatter' do
describe '::formatter' do
context 'with default formatter' do
before { Berkshelf.instance_variable_set(:@formatter, nil) }

Expand Down Expand Up @@ -30,7 +30,7 @@ class CustomFormatter
end
end

describe '.log' do
describe '::log' do
it 'returns Berkshelf::Logger' do
expect(Berkshelf.log).to eq(Berkshelf::Logger)
end
Expand Down

0 comments on commit 4d270c7

Please sign in to comment.