2011-11-18 18:13:04 -05:00
|
|
|
require 'bundler/setup'
|
2011-11-12 17:04:59 -05:00
|
|
|
require 'bundler/gem_tasks'
|
2010-12-13 17:28:59 -05:00
|
|
|
require 'rspec/core/rake_task'
|
|
|
|
require 'cucumber/rake/task'
|
2011-05-25 14:38:07 -04:00
|
|
|
require 'appraisal'
|
2014-04-04 13:11:46 -04:00
|
|
|
require 'erb'
|
|
|
|
require_relative 'lib/shoulda/matchers/version'
|
|
|
|
|
|
|
|
CURRENT_VERSION = Shoulda::Matchers::VERSION
|
2009-01-09 00:43:32 -05:00
|
|
|
|
2010-12-13 17:28:59 -05:00
|
|
|
RSpec::Core::RakeTask.new do |t|
|
2014-06-27 18:39:39 -04:00
|
|
|
t.ruby_opts = '-w -r ./spec/report_warnings'
|
2010-12-13 17:28:59 -05:00
|
|
|
t.pattern = "spec/**/*_spec.rb"
|
2010-12-14 18:35:12 -05:00
|
|
|
t.rspec_opts = '--color --format progress'
|
|
|
|
t.verbose = false
|
2010-12-13 17:28:59 -05:00
|
|
|
end
|
|
|
|
|
2010-12-13 15:56:37 -05:00
|
|
|
Cucumber::Rake::Task.new do |t|
|
Use same assertion class as Rails, if loaded
Given this scenario:
* Using Rails 4.1
* Gemfile has `gem 'shoulda-matchers', require: false`
* spec_helper has `require 'shoulda/matchers'` following
`require 'rspec/rails'`
* Using Spring to run tests
matchers that delegate to assertions in Rails (e.g. `render_template`
and `route`) will fail in the wrong way if used. They fail because in
order to use these assertions, we expect that the assertions will
raise a specific exception, an exception that corresponds to whichever
test framework that Rails is using. For Rails versions that used
Test::Unit, this is Test::Unit::AssertionFailedError. For current Rails
versions, which now use Minitest, this exception is Minitest::Assertion.
The problem is that instead of asking Rails which exception class it's
using, we are trying to detect this exception class ourselves (for
cases in which Rails is not being used). This leads to the wrong class
being detected: when using a Rails version that uses Minitest, we choose
Test::Unit::AssertionFailedError as the class. This happens using the
exact scenario above because even though shoulda-matchers is loaded
after rspec-rails, rspec-rails itself defines
Test::Unit::AssertionFailedError.
Also add Cucumber tests that confirms this exact scenario works.
2014-06-21 23:24:22 -04:00
|
|
|
options = []
|
|
|
|
|
|
|
|
options << '--format' << (ENV['CUCUMBER_FORMAT'] || 'progress')
|
|
|
|
|
|
|
|
if Bundler.definition.dependencies.none? { |dependency| dependency.name == 'spring' }
|
|
|
|
options << '--profile' << 'without_spring'
|
|
|
|
end
|
|
|
|
|
2011-05-25 14:38:07 -04:00
|
|
|
t.fork = false
|
Use same assertion class as Rails, if loaded
Given this scenario:
* Using Rails 4.1
* Gemfile has `gem 'shoulda-matchers', require: false`
* spec_helper has `require 'shoulda/matchers'` following
`require 'rspec/rails'`
* Using Spring to run tests
matchers that delegate to assertions in Rails (e.g. `render_template`
and `route`) will fail in the wrong way if used. They fail because in
order to use these assertions, we expect that the assertions will
raise a specific exception, an exception that corresponds to whichever
test framework that Rails is using. For Rails versions that used
Test::Unit, this is Test::Unit::AssertionFailedError. For current Rails
versions, which now use Minitest, this exception is Minitest::Assertion.
The problem is that instead of asking Rails which exception class it's
using, we are trying to detect this exception class ourselves (for
cases in which Rails is not being used). This leads to the wrong class
being detected: when using a Rails version that uses Minitest, we choose
Test::Unit::AssertionFailedError as the class. This happens using the
exact scenario above because even though shoulda-matchers is loaded
after rspec-rails, rspec-rails itself defines
Test::Unit::AssertionFailedError.
Also add Cucumber tests that confirms this exact scenario works.
2014-06-21 23:24:22 -04:00
|
|
|
t.cucumber_opts = options
|
2010-06-23 14:29:51 -04:00
|
|
|
end
|
|
|
|
|
2014-01-20 13:35:10 -05:00
|
|
|
task :default do
|
2013-03-04 16:10:54 -05:00
|
|
|
if ENV['BUNDLE_GEMFILE'] =~ /gemfiles/
|
2014-01-20 13:35:10 -05:00
|
|
|
Rake::Task['spec'].invoke
|
|
|
|
Rake::Task['cucumber'].invoke
|
2013-03-04 16:10:54 -05:00
|
|
|
else
|
2014-01-20 13:35:10 -05:00
|
|
|
Rake::Task['appraise'].invoke
|
2013-03-04 16:10:54 -05:00
|
|
|
end
|
2011-05-25 14:38:07 -04:00
|
|
|
end
|
2012-04-10 00:06:09 -04:00
|
|
|
|
2014-01-20 13:39:18 -05:00
|
|
|
task :appraise do
|
|
|
|
exec 'appraisal install && appraisal rake'
|
2013-03-04 16:10:54 -05:00
|
|
|
end
|
2014-04-04 13:11:46 -04:00
|
|
|
|
|
|
|
GH_PAGES_DIR = '.gh-pages'
|
|
|
|
|
|
|
|
namespace :docs do
|
|
|
|
file GH_PAGES_DIR do
|
|
|
|
sh "git clone git@github.com:thoughtbot/shoulda-matchers.git #{GH_PAGES_DIR} --branch gh-pages"
|
|
|
|
end
|
|
|
|
|
|
|
|
task :setup => GH_PAGES_DIR do
|
|
|
|
within_gh_pages do
|
|
|
|
sh 'git fetch origin'
|
|
|
|
sh 'git reset --hard origin/gh-pages'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Generate docs for a particular version'
|
|
|
|
task :generate, [:version, :latest_version] => :setup do |t, args|
|
|
|
|
generate_docs(args.version, latest_version: latest_version)
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Generate docs for a particular version and push them to GitHub'
|
|
|
|
task :publish, [:version, :latest_version] => :setup do |t, args|
|
|
|
|
generate_docs(args.version, latest_version: latest_version)
|
|
|
|
publish_docs(args.version, latest_version: latest_version)
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "Generate docs for version #{CURRENT_VERSION} and push them to GitHub"
|
|
|
|
task :publish_latest => :setup do
|
|
|
|
version = Gem::Version.new(CURRENT_VERSION)
|
|
|
|
|
|
|
|
unless version.prerelease?
|
|
|
|
latest_version = version.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
generate_docs(CURRENT_VERSION, latest_version: latest_version)
|
|
|
|
publish_docs(CURRENT_VERSION, latest_version: latest_version)
|
|
|
|
end
|
|
|
|
|
|
|
|
def rewrite_index_to_inject_version(ref, version)
|
|
|
|
within_gh_pages do
|
|
|
|
filename = "#{ref}/index.html"
|
|
|
|
content = File.read(filename)
|
|
|
|
content.sub!(%r{<h1>shoulda-matchers.+</h1>}, "<h1>shoulda-matchers (#{version})</h1>")
|
|
|
|
File.open(filename, 'w') {|f| f.write(content) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def generate_docs(version, options = {})
|
|
|
|
ref = determine_ref_from(version)
|
|
|
|
|
|
|
|
sh "rm -rf #{GH_PAGES_DIR}/#{ref}"
|
|
|
|
sh "bundle exec yard -o #{GH_PAGES_DIR}/#{ref}"
|
|
|
|
|
|
|
|
rewrite_index_to_inject_version(ref, version)
|
|
|
|
|
|
|
|
within_gh_pages do
|
|
|
|
sh "git add --ignore-removal #{ref}"
|
|
|
|
end
|
|
|
|
|
|
|
|
if options[:latest_version]
|
|
|
|
generate_file_that_redirects_to_latest_version(options[:latest_version])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def publish_docs(version, options = {})
|
|
|
|
message = build_commit_message(version)
|
|
|
|
|
|
|
|
within_gh_pages do
|
|
|
|
sh 'git clean -f'
|
|
|
|
sh "git commit -m '#{message}'"
|
|
|
|
sh 'git push'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def generate_file_that_redirects_to_latest_version(version)
|
|
|
|
ref = determine_ref_from(version)
|
|
|
|
locals = { ref: ref }
|
|
|
|
|
|
|
|
erb = ERB.new(File.read('doc_config/gh-pages/index.html.erb'))
|
|
|
|
|
|
|
|
within_gh_pages do
|
|
|
|
File.open('index.html', 'w') { |f| f.write(erb.result(binding)) }
|
|
|
|
sh 'git add index.html'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def determine_ref_from(version)
|
|
|
|
if version =~ /^\d+\.\d+\.\d+/
|
|
|
|
'v' + version
|
|
|
|
else
|
|
|
|
version
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_commit_message(version)
|
|
|
|
"Regenerated docs for version #{version}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def within_gh_pages(&block)
|
|
|
|
Dir.chdir(GH_PAGES_DIR, &block)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
task release: 'docs:publish_latest'
|