Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 227 lines (192 sloc) 6.622 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'rake/gempackagetask'
require 'cucumber/rake/task'

desc 'Default: run unit tests.'
task :default => [:test, "cucumber:rails:all"]

desc 'Test the hoptoad_notifier gem.'
Rake::TestTask.new(:test) do |t|
  t.libs << 'lib'
  t.pattern = 'test/**/*_test.rb'
  t.verbose = true
end

desc 'Run ginger tests'
task :ginger do
  $LOAD_PATH << File.join(*%w[vendor ginger lib])
  ARGV.clear
  ARGV << 'test'
  load File.join(*%w[vendor ginger bin ginger])
end

namespace :changeling do
  desc "Bumps the version by a minor or patch version, depending on what was passed in."
  task :bump, :part do |t, args|
    # Thanks, Jeweler!
    if HoptoadNotifier::VERSION =~ /^(\d+)\.(\d+)\.(\d+)(?:\.(.*?))?$/
      major = $1.to_i
      minor = $2.to_i
      patch = $3.to_i
      build = $4
    else
      abort
    end

    case args[:part]
    when /minor/
      minor += 1
      patch = 0
    when /patch/
      patch += 1
    else
      abort
    end

    version = [major, minor, patch, build].compact.join('.')

    File.open(File.join("lib", "hoptoad_notifier", "version.rb"), "w") do |f|
      f.write <<EOF
module HoptoadNotifier
VERSION = "#{version}".freeze
end
EOF
    end
  end

  desc "Writes out the new CHANGELOG and prepares the release"
  task :change do
    load 'lib/hoptoad_notifier/version.rb'
    file = "CHANGELOG"
    old = File.read(file)
    version = HoptoadNotifier::VERSION
    message = "Bumping to version #{version}"

    File.open(file, "w") do |f|
      f.write <<EOF
Version #{version} - #{Time.now}
===============================================================================

#{`git log $(git tag | tail -1)..HEAD | git shortlog`}
#{old}
EOF
    end

    exec ["#{ENV["EDITOR"]} #{file}",
          "git commit -aqm '#{message}'",
          "git tag -a -m '#{message}' v#{version}",
          "echo '\n\n\033[32mMarked v#{version} /' `git show-ref -s refs/heads/master` 'for release. Run: rake changeling:push\033[0m\n\n'"].join(' && ')
  end

  desc "Bump by a minor version (1.2.3 => 1.3.0)"
  task :minor do |t|
    Rake::Task['changeling:bump'].invoke(t.name)
    Rake::Task['changeling:change'].invoke
  end

  desc "Bump by a patch version, (1.2.3 => 1.2.4)"
  task :patch do |t|
    Rake::Task['changeling:bump'].invoke(t.name)
    Rake::Task['changeling:change'].invoke
  end

  desc "Push the latest version and tags"
  task :push do |t|
    system("git push origin master")
    system("git push origin $(git tag | tail -1)")
  end
end

begin
  require 'yard'
  YARD::Rake::YardocTask.new do |t|
    t.files = ['lib/**/*.rb', 'TESTING.rdoc']
  end
rescue LoadError
end

GEM_ROOT = File.dirname(__FILE__).freeze
VERSION_FILE = File.join(GEM_ROOT, 'lib', 'hoptoad_notifier', 'version')

require VERSION_FILE

gemspec = Gem::Specification.new do |s|
  s.name = %q{hoptoad_notifier}
  s.version = HoptoadNotifier::VERSION
  s.summary = %q{Send your application errors to our hosted service and reclaim your inbox.}

  s.files = FileList['[A-Z]*', 'generators/**/*.*', 'lib/**/*.rb',
                            'test/**/*.rb', 'rails/**/*.rb', 'script/*',
                            'lib/templates/*.erb']
  s.require_path = 'lib'
  s.test_files = Dir[*['test/**/*_test.rb']]

  s.add_runtime_dependency("builder")
  s.add_runtime_dependency("activesupport")
  s.add_development_dependency("activerecord")
  s.add_development_dependency("actionpack")
  s.add_development_dependency("bourne")
  s.add_development_dependency("nokogiri")
  s.add_development_dependency("shoulda")

  s.authors = ["thoughtbot, inc"]
  s.email = %q{support@hoptoadapp.com}
  s.homepage = "http://www.hoptoadapp.com"

  s.platform = Gem::Platform::RUBY
end

Rake::GemPackageTask.new gemspec do |pkg|
  pkg.need_tar = true
  pkg.need_zip = true
end

desc "Clean files generated by rake tasks"
task :clobber => [:clobber_rdoc, :clobber_package]

desc "Generate a gemspec file"
task :gemspec do
  File.open("#{gemspec.name}.gemspec", 'w') do |f|
    f.write gemspec.to_ruby
  end
end

LOCAL_GEM_ROOT = File.join(GEM_ROOT, 'tmp', 'local_gems').freeze
RAILS_VERSIONS = IO.read('SUPPORTED_RAILS_VERSIONS').strip.split("\n")
LOCAL_GEMS = [['sham_rack', nil], ['capistrano', nil], ['sqlite3-ruby', nil], ['sinatra', nil]] +
  RAILS_VERSIONS.collect { |version| ['rails', version] }

desc "Vendor test gems: Run this once to prepare your test environment"
task :vendor_test_gems do
  old_gem_path = ENV['GEM_PATH']
  old_gem_home = ENV['GEM_HOME']
  ENV['GEM_PATH'] = LOCAL_GEM_ROOT
  ENV['GEM_HOME'] = LOCAL_GEM_ROOT
  LOCAL_GEMS.each do |gem_name, version|
    gem_file_pattern = [gem_name, version || '*'].compact.join('-')
    version_option = version ? "-v #{version}" : ''
    pattern = File.join(LOCAL_GEM_ROOT, 'gems', "#{gem_file_pattern}")
    existing = Dir.glob(pattern).first
    unless existing
      command = "gem install -i #{LOCAL_GEM_ROOT} --no-ri --no-rdoc --backtrace #{version_option} #{gem_name}"
      puts "Vendoring #{gem_file_pattern}..."
      unless system("#{command} 2>&1")
        puts "Command failed: #{command}"
        exit(1)
      end
    end
  end
  ENV['GEM_PATH'] = old_gem_path
  ENV['GEM_HOME'] = old_gem_home
end

Cucumber::Rake::Task.new(:cucumber) do |t|
  t.fork = true
  t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
end

task :cucumber => [:gemspec, :vendor_test_gems]

def run_rails_cucumbr_task(version, additional_cucumber_args)
  puts "Testing Rails #{version}"
  if version.empty?
    raise "No Rails version specified - make sure ENV['RAILS_VERSION'] is set, e.g. with `rake cucumber:rails:all`"
  end
  ENV['RAILS_VERSION'] = version
  system("cucumber --format #{ENV['CUCUMBER_FORMAT'] || 'progress'} #{additional_cucumber_args} features/rails.feature features/rails_with_js_notifier.feature")
end

def define_rails_cucumber_tasks(additional_cucumber_args = '')
  namespace :rails do
    RAILS_VERSIONS.each do |version|
      desc "Test integration of the gem with Rails #{version}"
      task version => [:gemspec, :vendor_test_gems] do
        exit 1 unless run_rails_cucumbr_task(version, additional_cucumber_args)
      end
    end

    desc "Test integration of the gem with all Rails versions"
    task :all do
      results = RAILS_VERSIONS.map do |version|
        run_rails_cucumbr_task(version, additional_cucumber_args)
      end

      exit 1 unless results.all?
    end
  end
end

namespace :cucumber do
  namespace :wip do
    define_rails_cucumber_tasks('--tags @wip')
  end

  define_rails_cucumber_tasks
end
Something went wrong with that request. Please try again.