Skip to content

Commit

Permalink
Refactor spec_helper methods for complexity (style).
Browse files Browse the repository at this point in the history
  • Loading branch information
fnichol committed Aug 5, 2014
1 parent f59a762 commit 5ccfa98
Showing 1 changed file with 53 additions and 37 deletions.
90 changes: 53 additions & 37 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# -*- encoding: utf-8 -*-

gem 'minitest'
gem "minitest"

if ENV["CODECLIMATE_REPO_TOKEN"]
require "codeclimate-test-reporter"
CodeClimate::TestReporter.start
elsif ENV["COVERAGE"]
require 'simplecov'
SimpleCov.adapters.define 'gem' do
command_name 'Specs'
require "simplecov"
SimpleCov.adapters.define "gem" do
command_name "Specs"

add_filter '.gem/'
add_filter '/spec/'
add_filter ".gem/"
add_filter "/spec/"

add_group 'Libraries', '/lib/'
add_group "Libraries", "/lib/"
end
SimpleCov.start 'gem'
SimpleCov.start "gem"
end

require 'fakefs/safe'
require 'minitest/autorun'
require 'mocha/setup'
require "fakefs/safe"
require "minitest/autorun"
require "mocha/setup"

# Nasty hack to redefine IO.read in terms of File#read for fakefs
class IO
Expand All @@ -29,10 +29,11 @@ def self.read(*args)
end
end

require 'chef'
require 'chef/cookbook_site_streaming_uploader'
require "chef"
require "chef/cookbook_site_streaming_uploader"
class Chef
class CookbookSiteStreamingUploader
# Backwards compat
class MultipartStream
alias_method :read_original, :read

Expand All @@ -45,35 +46,16 @@ def read(how_much = nil)

module Emeril

# Common spec helpers
module SpecCommon

def make_cookbook!(opts = {}) # rubocop:disable Style/MethodLength
def make_cookbook!(opts = {})
FileUtils.mkdir_p("#{cookbook_path}/recipes")
remote_dir = File.join(File.dirname(cookbook_path), "remote")

File.open("#{cookbook_path}/metadata.rb", "wb") do |f|
f.write <<-METADATA_RB.gsub(/^ {10}/, '')
name "#{opts.fetch(:name, "emeril")}"
maintainer "Michael Bluth"
maintainer_email "michael@bluth.com"
license "Apache 2.0"
description "Doing stuff!"
long_description "Doing stuff!"
version "#{opts.fetch(:version, "4.1.1")}"
METADATA_RB
end
File.open("#{cookbook_path}/recipes/default.rb", "wb") do |f|
f.write <<-DEFAULT_RB.gsub(/^ {10}/, '')
directory "/tmp/yeah"
package "bash"
DEFAULT_RB
end
File.open("#{cookbook_path}/README.md", "wb") do |f|
f.write <<-README.gsub(/^ {10}/, '')
# The beast of the beasts
README
end
create_metadata(opts)
create_recipe
create_readme

run_cmd [
%{git init},
Expand All @@ -95,5 +77,39 @@ def make_client_key!
def run_cmd(cmd, opts = {})
%x{cd #{opts.fetch(:in, cookbook_path)} && #{cmd}}
end

private

def create_metadata(opts)
File.open("#{cookbook_path}/metadata.rb", "wb") do |f|
f.write <<-METADATA_RB.gsub(/^ {10}/, "")
name "#{opts.fetch(:name, "emeril")}"
maintainer "Michael Bluth"
maintainer_email "michael@bluth.com"
license "Apache 2.0"
description "Doing stuff!"
long_description "Doing stuff!"
version "#{opts.fetch(:version, "4.1.1")}"
METADATA_RB
end
end

def create_recipe
File.open("#{cookbook_path}/recipes/default.rb", "wb") do |f|
f.write <<-DEFAULT_RB.gsub(/^ {10}/, "")
directory "/tmp/yeah"
package "bash"
DEFAULT_RB
end
end

def create_readme
File.open("#{cookbook_path}/README.md", "wb") do |f|
f.write <<-README.gsub(/^ {10}/, "")
# The beast of the beasts
README
end
end
end
end

0 comments on commit 5ccfa98

Please sign in to comment.