Commit aaeab039 by Cuong Tran

Merge pull request #324 from ryanfox1985/develop

Add ruby head to travis and integrate with rubocop
parents 477b641b 9ba5d511
inherit_from: ./.rubocop_todo.yml
AllCops:
Include:
- '**/Rakefile'
- '**/config.ru'
Exclude:
- 'bin/**/*'
......@@ -6,5 +6,12 @@ rvm:
- 2.1
- 2.2
- 2.3.0
- ruby-head
matrix:
allow_failures:
- rvm: ruby-head
before_install:
- rvm @global do gem install bundler
script:
- bundle exec rspec
- bundle exec rubocop
source 'https://rubygems.org'
gem 'rake', '>= 10.4.2', :require => false
gem 'activerecord', '>= 4.2.5', :require => false
gem 'rake', '>= 10.4.2', require: false
gem 'activerecord', '>= 4.2.5', require: false
group :development do
gem 'mg', :require => false
gem 'mg', require: false
gem 'bump'
platforms :mri do
gem 'yard', :require => false
gem 'yard', require: false
end
end
group :development, :test do
gem 'rspec', :require => false
gem 'guard-rspec', :require => false
gem 'terminal-notifier-guard', :require => false
gem 'rspec', require: false
gem 'guard-rspec', require: false
gem 'terminal-notifier-guard', require: false
gem 'simplecov', require: false
gem 'rubocop', require: false unless RUBY_VERSION =~ /^1.8/
gem 'coveralls'
gem 'codeclimate-test-reporter'
platforms :mri do
gem 'pry', :require => false
gem 'pry-coolline', :require => false
gem 'pry', require: false
gem 'pry-coolline', require: false
end
end
group :test do
gem 'wrong', :require => false
gem 'files', :require => false
gem 'wrong', require: false
gem 'files', require: false
end
== Annotate (aka AnnotateModels)
{<img src="https://badge.fury.io/rb/annotate.svg" alt="Gem Version" />}[http://badge.fury.io/rb/annotate]
{<img src="https://img.shields.io/gem/dt/annotate_models.svg?style=flat" />}[https://rubygems.org/gems/annotate_models]
{<img src="https://travis-ci.org/ctran/annotate_models.png" />}[https://travis-ci.org/ctran/annotate_models]
{<img src="https://codeclimate.com/github/ctran/annotate_models/badges/gpa.svg" />}[https://codeclimate.com/github/ctran/annotate_models]
{<img src="https://gemnasium.com/ctran/annotate_models.png" />}[https://gemnasium.com/ctran/annotate_models]
Add a comment summarizing the current schema to the top or bottom of each of
......
def exit_exception(e)
$stderr.puts e.message
exit e.status_code
end
# Note : this causes annoying psych warnings under Ruby 1.9.2-p180; to fix, upgrade to 1.9.3
begin
require 'bundler'
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
$stderr.puts 'Run `bundle install` to install missing gems'
exit_exception(e)
end
using_dsl = false
......@@ -14,18 +18,16 @@ begin
using_dsl = true
rescue Exception => e
# We might just be on an old version of Rake...
exit_exception(e)
end
require 'rake'
if(using_dsl)
include Rake::DSL
end
include Rake::DSL if using_dsl
require "./lib/annotate"
require "mg"
require './lib/annotate'
require 'mg'
begin
MG.new("annotate.gemspec")
rescue Exception => e
rescue Exception
STDERR.puts("WARNING: Couldn't read gemspec. As such, a number of tasks may be unavailable to you until you run 'rake gem:gemspec' to correct the issue.")
# Gemspec is probably in a broken state, so let's give ourselves a chance to
# build a new one...
......@@ -88,7 +90,7 @@ namespace :jeweler do
FileUtils.rm_f("pkg")
end
end
task :clobber => :'jeweler:clobber'
task clobber: :'jeweler:clobber'
require "rspec/core/rake_task" # RSpec 2.0
RSpec::Core::RakeTask.new(:spec) do |t|
......@@ -111,7 +113,7 @@ namespace :gemsets do
end
end
end
task :clobber => :'gemsets:empty'
task clobber: :'gemsets:empty'
namespace :integration do
desc "Remove any cruft generated by manual debugging runs which is .gitignore'd."
......@@ -120,19 +122,19 @@ namespace :integration do
end
desc "Reset any changed files, and remove any untracked files in spec/integration/*/, plus run integration:clean."
task :clobber => [:integration_environment, :'integration:clean'] do
task clobber: [:integration_environment, :'integration:clean'] do
Annotate::Integration.reset_dirty_files
Annotate::Integration.clear_untracked_files
end
task :symlink => [:integration_environment] do
task symlink: [:integration_environment] do
require 'digest/md5'
integration_dir = File.expand_path(File.join(File.dirname(__FILE__), 'spec', 'integration'))
fixture_dir = File.expand_path(File.join(File.dirname(__FILE__), 'spec', 'fixtures'))
# fixture_dir = File.expand_path(File.join(File.dirname(__FILE__), 'spec', 'fixtures'))
target_dir = File.expand_path(ENV['TARGET']) if(ENV['TARGET'])
raise "Must specify TARGET=x, where x is an integration test scenario!" unless(target_dir && Dir.exist?(target_dir))
raise "TARGET directory must be within spec/integration/!" unless(target_dir.start_with?(integration_dir))
raise "Must specify TARGET=x, where x is an integration test scenario!" unless target_dir && Dir.exist?(target_dir)
raise "TARGET directory must be within spec/integration/!" unless target_dir.start_with?(integration_dir)
candidates = {}
FileList[
"#{target_dir}/.rvmrc",
......@@ -156,7 +158,7 @@ namespace :integration do
candidates[digest] << fname
end
fixtures = {}
FileList["spec/fixtures/**/*"].each do |fname|
FileList['spec/fixtures/**/*'].each do |fname|
fixtures[Digest::MD5.hexdigest(File.read(fname))] = File.expand_path(fname)
end
......@@ -190,7 +192,7 @@ namespace :yard do
FileUtils.rm_f("doc")
end
end
task :clobber => :'yard:clobber'
task clobber: :'yard:clobber'
namespace :rubinius do
task :clobber do
......@@ -198,7 +200,7 @@ namespace :rubinius do
FileList[".rbx/**/*"].each { |fname| FileUtils.rm_f(fname) }
end
end
task :clobber => :'rubinius:clobber'
task clobber: :'rubinius:clobber'
# want other tests/tasks run by default? Add them to the list
task :default => [:spec]
task default: [:spec]
#!/usr/bin/env ruby
unless File.exists?('./Rakefile') || File.exists?('./Gemfile')
abort "Please run annotate from the root of the project."
unless File.exist?('./Rakefile') || File.exist?('./Gemfile')
abort 'Please run annotate from the root of the project.'
end
require 'rubygems'
......@@ -20,58 +20,55 @@ Annotate.bootstrap_rake
has_set_position = {}
target_action = :do_annotations
positions = %w(before top after bottom)
OptionParser.new do |opts|
opts.banner = "Usage: annotate [options] [model_file]*"
opts.on('-d', '--delete',
"Remove annotations from all model files or the routes.rb file") do
opts.banner = 'Usage: annotate [options] [model_file]*'
opts.on('-d', '--delete', 'Remove annotations from all model files or the routes.rb file') do
target_action = :remove_annotations
end
opts.on('-p', '--position [before|top|after|bottom]', ['before', 'top', 'after', 'bottom'],
"Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s)") do |p|
opts.on('-p', '--position [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s)') do |p|
ENV['position'] = p
[
'position_in_class','position_in_factory','position_in_fixture','position_in_test', 'position_in_routes', 'position_in_serializer'
].each do |key|
%w(position_in_class position_in_factory position_in_fixture position_in_test position_in_routes position_in_serializer).each do |key|
ENV[key] = p unless(has_set_position[key])
end
end
opts.on('--pc', '--position-in-class [before|top|after|bottom]', ['before', 'top', 'after', 'bottom'],
"Place the annotations at the top (before) or the bottom (after) of the model file") do |p|
opts.on('--pc', '--position-in-class [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of the model file') do |p|
ENV['position_in_class'] = p
has_set_position['position_in_class'] = true
end
opts.on('--pf', '--position-in-factory [before|top|after|bottom]', ['before', 'top', 'after', 'bottom'],
"Place the annotations at the top (before) or the bottom (after) of any factory files") do |p|
opts.on('--pf', '--position-in-factory [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of any factory files') do |p|
ENV['position_in_factory'] = p
has_set_position['position_in_factory'] = true
end
opts.on('--px', '--position-in-fixture [before|top|after|bottom]', ['before', 'top', 'after', 'bottom'],
"Place the annotations at the top (before) or the bottom (after) of any fixture files") do |p|
opts.on('--px', '--position-in-fixture [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of any fixture files') do |p|
ENV['position_in_fixture'] = p
has_set_position['position_in_fixture'] = true
end
opts.on('--pt', '--position-in-test [before|top|after|bottom]', ['before', 'top', 'after', 'bottom'],
"Place the annotations at the top (before) or the bottom (after) of any test files") do |p|
opts.on('--pt', '--position-in-test [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of any test files') do |p|
ENV['position_in_test'] = p
has_set_position['position_in_test'] = true
end
opts.on('--pr', '--position-in-routes [before|top|after|bottom]', ['before', 'top', 'after', 'bottom'],
"Place the annotations at the top (before) or the bottom (after) of the routes.rb file") do |p|
opts.on('--pr', '--position-in-routes [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of the routes.rb file') do |p|
ENV['position_in_routes'] = p
has_set_position['position_in_routes'] = true
end
opts.on('--ps', '--position-in-serializer [before|top|after|bottom]', ['before', 'top', 'after', 'bottom'],
"Place the annotations at the top (before) or the bottom (after) of the serializer files") do |p|
opts.on('--ps', '--position-in-serializer [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of the serializer files') do |p|
ENV['position_in_serializer'] = p
has_set_position['position_in_serializer'] = true
end
......@@ -89,34 +86,32 @@ OptionParser.new do |opts|
ENV['wrapper_close'] = p
end
opts.on('-r', '--routes',
"Annotate routes.rb with the output of 'rake routes'") do
opts.on('-r', '--routes', "Annotate routes.rb with the output of 'rake routes'") do
ENV['routes'] = 'true'
end
opts.on('-v', '--version',
"Show the current version of this gem") do
'Show the current version of this gem') do
puts "annotate v#{Annotate.version}"; exit
end
opts.on('-m', '--show-migration',
"Include the migration version number in the annotation") do
ENV['include_version'] = "yes"
opts.on('-m', '--show-migration', 'Include the migration version number in the annotation') do
ENV['include_version'] = 'yes'
end
opts.on('-k', '--show-foreign-keys',
"List the table's foreign key constraints in the annotation") do
ENV['show_foreign_keys'] = "yes"
ENV['show_foreign_keys'] = 'yes'
end
opts.on('-i', '--show-indexes',
"List the table's database indexes in the annotation") do
ENV['show_indexes'] = "yes"
ENV['show_indexes'] = 'yes'
end
opts.on('-s', '--simple-indexes',
"Concat the column's related indexes in the annotation") do
ENV['simple_indexes'] = "yes"
ENV['simple_indexes'] = 'yes'
end
opts.on('--model-dir dir',
......@@ -131,17 +126,17 @@ OptionParser.new do |opts|
opts.on('--ignore-model-subdirects',
"Ignore subdirectories of the models directory") do |dir|
ENV['ignore_model_sub_dir'] = "yes"
ENV['ignore_model_sub_dir'] = 'yes'
end
opts.on('--sort',
"Sort columns alphabetically, rather than in creation order") do |dir|
ENV['sort'] = "yes"
ENV['sort'] = 'yes'
end
opts.on('--classified-sort',
"Sort columns alphabetically, but first goes id, then the rest columns, then the timestamp columns and then the association columns") do |dir|
ENV['classified_sort'] = "yes"
ENV['classified_sort'] = 'yes'
end
opts.on('-R', '--require path',
......@@ -155,10 +150,10 @@ OptionParser.new do |opts|
opts.on('-e', '--exclude [tests,fixtures,factories,serializers]', Array, "Do not annotate fixtures, test files, factories, and/or serializers") do |exclusions|
exclusions ||= %w(tests fixtures factories)
exclusions.each { |exclusion| ENV["exclude_#{exclusion}"] = "yes" }
exclusions.each { |exclusion| ENV["exclude_#{exclusion}"] = 'yes' }
end
opts.on('-f', '--format [bare|rdoc|markdown]', ['bare', 'rdoc', 'markdown'], 'Render Schema Infomation as plain/RDoc/Markdown') do |fmt|
opts.on('-f', '--format [bare|rdoc|markdown]', %w(bare rdoc markdown), 'Render Schema Infomation as plain/RDoc/Markdown') do |fmt|
ENV["format_#{fmt}"] = 'yes'
end
......@@ -186,8 +181,8 @@ OptionParser.new do |opts|
ENV['hide_limit_column_types'] = "#{values}"
end
opts.on('--ignore-unknown-models', "don't display warnings for bad model files" ) do |values|
ENV['ignore_unknown_models'] = "true"
opts.on('--ignore-unknown-models', "don't display warnings for bad model files" ) do |_values|
ENV['ignore_unknown_models'] = 'true'
end
end.parse!
......
......@@ -158,22 +158,23 @@ module Annotate
def self.bootstrap_rake
begin
require 'rake/dsl_definition'
rescue Exception
rescue Exception => e
# We might just be on an old version of Rake...
puts e.message
exit e.status_code
end
require 'rake'
if File.exists?('./Rakefile')
load './Rakefile'
end
load './Rakefile' if File.exist?('./Rakefile')
Rake::Task[:environment].invoke rescue nil
if(!defined?(Rails))
unless defined?(Rails)
# Not in a Rails project, so time to load up the parts of
# ActiveSupport we need.
require 'active_support'
require 'active_support/core_ext/class/subclasses'
require 'active_support/core_ext/string/inflections'
end
self.load_tasks
Rake::Task[:set_annotation_options].invoke
end
......
......@@ -375,12 +375,14 @@ module AnnotateModels
old_content.sub!(magic_comment_matcher, '')
old_content.sub!(PATTERN, '')
new_content = %w(after bottom).include?(options[position].to_s) ?
(magic_comments.join + (old_content.rstrip + "\n\n" + wrapped_info_block)) :
(magic_comments.join + wrapped_info_block + "\n" + old_content)
if %w(after bottom).include?(options[position].to_s)
new_content = magic_comments.join + (old_content.rstrip + "\n\n" + wrapped_info_block)
else
new_content = magic_comments.join + wrapped_info_block + "\n" + old_content
end
end
File.open(file_name, "wb") { |f| f.puts new_content }
File.open(file_name, 'wb') { |f| f.puts new_content }
return true
end
else
......@@ -391,14 +393,13 @@ module AnnotateModels
def remove_annotation_of_file(file_name)
if File.exist?(file_name)
content = File.read(file_name)
content.sub!(PATTERN, '')
File.open(file_name, "wb") { |f| f.puts content }
File.open(file_name, 'wb') { |f| f.puts content }
return true
true
else
return false
false
end
end
......@@ -628,12 +629,12 @@ module AnnotateModels
associations = []
id = nil
cols = cols.each do |c|
if c.name.eql?("id")
cols.each do |c|
if c.name.eql?('id')
id = c
elsif (c.name.eql?("created_at") || c.name.eql?("updated_at"))
elsif (c.name.eql?('created_at') || c.name.eql?('updated_at'))
timestamps << c
elsif c.name[-3,3].eql?("_id")
elsif c.name[-3,3].eql?('_id')
associations << c
else
rest_cols << c
......
......@@ -18,7 +18,7 @@
# Released under the same license as Ruby. No Support. No Warranty.
#
module AnnotateRoutes
PREFIX = "# == Route Map"
PREFIX = '# == Route Map'
def self.do_annotations(options={})
return unless(routes_exists?)
......@@ -37,8 +37,8 @@ module AnnotateRoutes
routes_map.reject!{|line| line.match(/#{options[:ignore_routes]}/)} if options[:ignore_routes]
header = [
"#{PREFIX}" + (options[:timestamp] ? " (Updated #{Time.now.strftime("%Y-%m-%d %H:%M")})" : ""),
"#"
"#{PREFIX}" + (options[:timestamp] ? " (Updated #{Time.now.strftime('%Y-%m-%d %H:%M')})" : ''),
'#'
] + routes_map.map { |line| "# #{line}".rstrip }
existing_text = File.read(routes_file)
......@@ -49,7 +49,7 @@ module AnnotateRoutes
# middle of the file. If the number is
# zero, no annotation was found.
if(position_after)
if position_after
# Ensure we have adequate trailing newlines at the end of the file to
# ensure a blank line separating the content from the annotation.
content << '' if(content.last != '')
......@@ -89,12 +89,12 @@ module AnnotateRoutes
protected
def self.routes_file
@routes_rb ||= File.join("config", "routes.rb")
@routes_rb ||= File.join('config', 'routes.rb')
end
def self.routes_exists?
routes_exists = File.exists?(routes_file)
puts "Can`t find routes.rb" if(!routes_exists)
puts "Can't find routes.rb" if(!routes_exists)
return routes_exists
end
......@@ -105,7 +105,7 @@ protected
return false if existing_text == new_text
File.open(routes_file, "wb") { |f| f.puts(new_text) }
File.open(routes_file, 'wb') { |f| f.puts(new_text) }
return true
end
......@@ -117,13 +117,13 @@ protected
content.split(/\n/, -1).each do |line|
line_number += 1
begin
if(mode == :header)
if(line !~ /\s*#/)
if mode == :header
if line !~ /\s*#/
mode = :content
raise unless (line == '')
end
elsif(mode == :content)
if(line =~ /^\s*#\s*== Route.*$/)
elsif mode == :content
if line =~ /^\s*#\s*== Route.*$/
header_found_at = line_number
mode = :header
else
......@@ -147,9 +147,9 @@ protected
end
def self.strip_on_removal(content, where_header_found)
if(where_header_found == :before)
if where_header_found == :before
content.shift while(content.first == '')
elsif(where_header_found == :after)
elsif where_header_found == :after
content.pop while(content.last == '')
end
# TODO: If the user buried it in the middle, we should probably see about
......
......@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../spec_helper.rb'
require 'annotate/annotate_routes'
describe AnnotateRoutes do
ROUTE_FILE = "config/routes.rb"
ROUTE_FILE = 'config/routes.rb'
ANNOTATION_ADDED = "#{ROUTE_FILE} annotated."
ANNOTATION_REMOVED = "Removed annotations from #{ROUTE_FILE}."
FILE_UNCHANGED = "#{ROUTE_FILE} unchanged."
......@@ -11,28 +11,28 @@ describe AnnotateRoutes do
@mock_file ||= double(File, stubs)
end
it "should check if routes.rb exists" do
it 'should check if routes.rb exists' do
expect(File).to receive(:exists?).with(ROUTE_FILE).and_return(false)
expect(AnnotateRoutes).to receive(:puts).with("Can`t find routes.rb")
expect(AnnotateRoutes).to receive(:puts).with("Can't find routes.rb")
AnnotateRoutes.do_annotations
end
describe "When adding" do
describe 'When adding' do
before(:each) do
expect(File).to receive(:exists?).with(ROUTE_FILE).and_return(true)
expect(AnnotateRoutes).to receive(:`).with("rake routes").and_return("")
expect(AnnotateRoutes).to receive(:`).with('rake routes').and_return('')
end
it "should insert annotations if file does not contain annotations" do
it 'should insert annotations if file does not contain annotations' do
expect(File).to receive(:read).with(ROUTE_FILE).and_return("")
expect(File).to receive(:open).with(ROUTE_FILE, "wb").and_yield(mock_file)
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
expect(@mock_file).to receive(:puts).with("\n# == Route Map\n#\n")
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED)
AnnotateRoutes.do_annotations
end
it "should skip annotations if file does already contain annotation" do
it 'should skip annotations if file does already contain annotation' do
expect(File).to receive(:read).with(ROUTE_FILE).and_return("\n# == Route Map\n#\n")
expect(AnnotateRoutes).to receive(:puts).with(FILE_UNCHANGED)
......@@ -41,22 +41,22 @@ describe AnnotateRoutes do
end
describe "When adding with older Rake versions" do
describe 'When adding with older Rake versions' do
before(:each) do
expect(File).to receive(:exists?).with(ROUTE_FILE).and_return(true)
expect(AnnotateRoutes).to receive(:`).with("rake routes").and_return("(in /bad/line)\ngood line")
expect(File).to receive(:open).with(ROUTE_FILE, "wb").and_yield(mock_file)
expect(AnnotateRoutes).to receive(:`).with('rake routes').and_return("(in /bad/line)\ngood line")
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED)
end
it "should annotate and add a newline!" do
it 'should annotate and add a newline!' do
expect(File).to receive(:read).with(ROUTE_FILE).and_return("ActionController::Routing...\nfoo")
expect(@mock_file).to receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# good line\n/)
AnnotateRoutes.do_annotations
end
it "should not add a newline if there are empty lines" do
it 'should not add a newline if there are empty lines' do
expect(File).to receive(:read).with(ROUTE_FILE).and_return("ActionController::Routing...\nfoo\n")
expect(@mock_file).to receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# good line\n/)
AnnotateRoutes.do_annotations
......@@ -64,29 +64,29 @@ describe AnnotateRoutes do
end
describe "When adding with newer Rake versions" do
describe 'When adding with newer Rake versions' do
before(:each) do
expect(File).to receive(:exists?).with(ROUTE_FILE).and_return(true)
expect(AnnotateRoutes).to receive(:`).with("rake routes").and_return("another good line\ngood line")
expect(File).to receive(:open).with(ROUTE_FILE, "wb").and_yield(mock_file)
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED)
end
it "should annotate and add a newline!" do
it 'should annotate and add a newline!' do
expect(File).to receive(:read).with(ROUTE_FILE).and_return("ActionController::Routing...\nfoo")
expect(@mock_file).to receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# another good line\n# good line\n/)
AnnotateRoutes.do_annotations
end
it "should not add a newline if there are empty lines" do
it 'should not add a newline if there are empty lines' do
expect(File).to receive(:read).with(ROUTE_FILE).and_return("ActionController::Routing...\nfoo\n")
expect(@mock_file).to receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# another good line\n# good line\n/)
AnnotateRoutes.do_annotations
end
it "should add a timestamp when :timestamp is passed" do
it 'should add a timestamp when :timestamp is passed' do
expect(File).to receive(:read).with(ROUTE_FILE).and_return("ActionController::Routing...\nfoo")
expect(@mock_file).to receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map \(Updated \d{4}-\d{2}-\d{2} \d{2}:\d{2}\)\n#\n# another good line\n# good line\n/)
AnnotateRoutes.do_annotations :timestamp => true
......@@ -94,21 +94,21 @@ describe AnnotateRoutes do
end
describe "When removing" do
describe 'When removing' do
before(:each) do
expect(File).to receive(:exists?).with(ROUTE_FILE).and_return(true)
expect(File).to receive(:open).with(ROUTE_FILE, "wb").and_yield(mock_file)
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_REMOVED)
end
it "should remove trailing annotation and trim trailing newlines, but leave leading newlines alone" do
it 'should remove trailing annotation and trim trailing newlines, but leave leading newlines alone' do
expect(File).to receive(:read).with(ROUTE_FILE).and_return("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nActionController::Routing...\nfoo\n\n\n\n\n\n\n\n\n\n\n# == Route Map\n#\n# another good line\n# good line\n")
expect(@mock_file).to receive(:puts).with(/\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nActionController::Routing...\nfoo\n/)
AnnotateRoutes.remove_annotations
end
it "should remove prepended annotation and trim leading newlines, but leave trailing newlines alone" do
it 'should remove prepended annotation and trim leading newlines, but leave trailing newlines alone' do
expect(File).to receive(:read).with(ROUTE_FILE).and_return("# == Route Map\n#\n# another good line\n# good line\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nActionController::Routing...\nfoo\n\n\n\n\n\n\n\n\n\n\n")
expect(@mock_file).to receive(:puts).with(/ActionController::Routing...\nfoo\n\n\n\n\n\n\n\n\n\n\n/)
AnnotateRoutes.remove_annotations
......
......@@ -57,10 +57,10 @@ module Annotate
def self.apply_annotation(test_rig, fname, annotation, place_before=true)
corpus = File.read(File.join(test_rig, fname))
if(place_before)
corpus = annotation + "\n" + corpus
if place_before
annotation + "\n" + corpus
else
corpus = corpus + "\n" + annotation
corpus + "\n" + annotation
end
end
end
......
......@@ -16,25 +16,23 @@ ENV['rvm_pretty_print_flag'] = '0'
ENV['BUNDLE_GEMFILE'] = './Gemfile'
describe "annotate inside Rails, using #{CURRENT_RUBY}" do
here = File.expand_path('..', __FILE__)
chosen_scenario = nil
if(!ENV['SCENARIO'].blank?)
if !ENV['SCENARIO'].blank?
chosen_scenario = File.expand_path(ENV['SCENARIO'])
raise "Can't find specified scenario '#{chosen_scenario}'!" unless(File.directory?(chosen_scenario))
end
Annotate::Integration::SCENARIOS.each do |test_rig, base_dir, test_name|
next if(chosen_scenario && chosen_scenario != test_rig)
it "works under #{test_name}" do
if(!USING_RVM)
skip "Must have RVM installed."
if !USING_RVM
skip 'Must have RVM installed.'
next
end
# Don't proceed if the working copy is dirty!
expect(Annotate::Integration.is_clean?(test_rig)).to eq(true)
skip "temporarily ignored until Travis can run them"
skip 'temporarily ignored until Travis can run them'
Bundler.with_clean_env do
dir base_dir do
......
require 'coveralls'
require 'codeclimate-test-reporter'
require 'simplecov'
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
Coveralls::SimpleCov::Formatter,
SimpleCov::Formatter::HTMLFormatter,
CodeClimate::TestReporter::Formatter
]
SimpleCov.start
require 'rubygems'
require 'bundler'
Bundler.setup
......@@ -18,10 +30,7 @@ module Annotate
module Integration
ABSOLUTE_GEM_ROOT=File.expand_path('../../', __FILE__)
CRUFT_PATTERNS=[
"%SCENARIO%/bin/*", "%SCENARIO%/log/*", "%SCENARIO%/tmp/*",
"%SCENARIO%/.bundle"
]
CRUFT_PATTERNS= %w(%SCENARIO%/bin/* %SCENARIO%/log/* %SCENARIO%/tmp/* %SCENARIO%/.bundle)
SCENARIO_HOME=File.join(File.dirname(__FILE__), 'integration')
SCENARIOS=Dir.glob("#{SCENARIO_HOME}/*").
select { |candidate| File.directory?(candidate) }.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment