Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Upgrade to Guard::RSpec v3.x

  • Loading branch information...
commit abf0802df37f701ae0584a20c6d440545c05c854 1 parent 04a868e
@njonsson authored
View
2  Gemfile
@@ -14,7 +14,7 @@ end
group :tooling do
gem 'guard-cucumber', '~> 1'
- gem 'guard-rspec', '~> 2'
+ gem 'guard-rspec', '~> 3'
if RUBY_PLATFORM =~ /darwin/i
gem 'rb-fsevent', '~> 0', :require => false
end
View
12 lib/cape/deprecation.rb
@@ -0,0 +1,12 @@
+::Dir.glob(::File.expand_path('../deprecation/*.rb', __FILE__)) do |f|
+ require "cape/deprecation/#{::File.basename f, '.rb'}"
+end
+
+module Cape
+
+ # Contains implementations of deprecation stream printers.
+ #
+ # @api private
+ module Deprecation; end
+
+end
View
59 lib/cape/deprecation/base.rb
@@ -0,0 +1,59 @@
+require 'cape/xterm'
+
+module Cape
+
+ module Deprecation
+
+ # Prints to a stream a message related to deprecated API usage.
+ #
+ # @abstract
+ class Base
+
+ # Sets the value of {#stream}.
+ #
+ # @param [IO] value a new value for {#stream}
+ #
+ # @return [IO] _value_
+ attr_writer :stream
+
+ # Formats {#message_content} for display.
+ #
+ # @return [String] the full message
+ def formatted_message
+ [].tap do |fragments|
+ fragments << XTerm.bold_and_foreground_red('*** DEPRECATED:')
+ fragments << ' '
+ fragments << XTerm.bold(message_content)
+ end.join
+ end
+
+ # Prepares a message based on deprecated API usage.
+ #
+ # @raise [NotImplementedError]
+ #
+ # @abstract
+ def message_content
+ raise ::NotImplementedError
+ end
+
+ # The stream to which deprecation messages are printed. Defaults to
+ # $stderr.
+ #
+ # @return [IO]
+ def stream
+ @stream ||= $stderr
+ end
+
+ # Writes {#formatted_message} to {#stream}.
+ #
+ # @return [Base] the object
+ def write_formatted_message_to_stream
+ stream.puts formatted_message
+ self
+ end
+
+ end
+
+ end
+
+end
View
168 lib/cape/deprecation/capistrano_deprecated_define_rake_wrapper.rb
@@ -0,0 +1,168 @@
+require 'cape/deprecation/base'
+require 'cape/hash_list'
+
+module Cape
+
+ module Deprecation
+
+ # Prints to a stream a message related to deprecated usage of
+ # {CapistranoDeprecated#define_rake_wrapper}.
+ class CapistranoDeprecatedDefineRakeWrapper < Base
+
+ # The _task_ argument to {CapistranoDeprecated#define_rake_wrapper}.
+ #
+ # @return [Symbol, String]
+ attr_accessor :task
+
+ # Environment variable names and values set in a call to
+ # {CapistranoDeprecated#define_rake_wrapper}.
+ #
+ # @return [HashList]
+ def env
+ @env ||= HashList.new
+ end
+
+ # Prepares a message based on deprecated usage of
+ # {CapistranoDeprecated#define_rake_wrapper}.
+ #
+ # @return [String] a deprecation message
+ def message_content
+ [].tap do |fragments|
+ fragments << message_content_actual
+ fragments << '. '
+ fragments << message_content_expected
+ end.join
+ end
+
+ # The _named_arguments_ argument to
+ # {CapistranoDeprecated#define_rake_wrapper}.
+ #
+ # @return [HashList]
+ def named_arguments
+ @named_arguments ||= HashList.new
+ end
+
+ # Sets the value of {#named_arguments}.
+ #
+ # @param [Hash] value a new value for {#named_arguments}
+ #
+ # @return [HashList] _value_
+ def named_arguments=(value)
+ @named_arguments = HashList.new(value)
+ end
+
+ private
+
+ def binding_named_arguments
+ named_arguments.select do |name, value|
+ name == :binding
+ end
+ end
+
+ def message_content_env_actual
+ [].tap do |fragments|
+ env_entries = env.collect do |name, value|
+ "env[#{name.inspect}] = #{value.inspect}"
+ end
+ unless env_entries.empty?
+ fragments << ' { |env| '
+ fragments << env_entries.join('; ')
+ fragments << ' }'
+ end
+ end.join
+ end
+
+ def message_content_options_and_env_expected
+ [].tap do |fragments|
+ unless named_arguments.empty? && env.empty?
+ fragments << ' { |recipes| '
+
+ options_entries = options.collect do |name, value|
+ "recipes.options[#{name.inspect}] = #{value.inspect}"
+ end
+ env_entries = env.collect do |name, value|
+ "recipes.env[#{name.inspect}] = #{value.inspect}"
+ end
+ fragments << (options_entries + env_entries).join('; ')
+
+ fragments << ' }'
+ end
+ end.join
+ end
+
+ def message_content_actual
+ [].tap do |fragments|
+ fragments << '`'
+ fragments << message_content_method_name
+ fragments << message_content_task_and_named_arguments_actual
+ fragments << message_content_env_actual
+ fragments << '`'
+ end.join
+ end
+
+ def message_content_expected
+ [].tap do |fragments|
+ fragments << 'Use this instead: '
+ fragments << '`'
+ fragments << message_content_method_name
+ fragments << message_content_task_and_named_arguments_expected
+ fragments << message_content_options_and_env_expected
+ fragments << '`'
+ end.join
+ end
+
+ def message_content_method_name
+ 'define_rake_wrapper'
+ end
+
+ def message_content_task_and_named_arguments_actual
+ [].tap do |fragments|
+ arguments = []
+ arguments << task.inspect unless task.nil?
+ named_arguments_entries = named_arguments.collect do |name, value|
+ "#{name.inspect} => #{value.inspect}"
+ end
+ unless named_arguments_entries.empty?
+ arguments << named_arguments_entries.join(', ')
+ end
+ unless arguments.empty?
+ if env.empty?
+ fragments << " #{arguments.join ', '}"
+ else
+ fragments << "(#{arguments.join ', '})"
+ end
+ end
+ end.join
+ end
+
+ def message_content_task_and_named_arguments_expected
+ [].tap do |fragments|
+ arguments = []
+ arguments << task.inspect unless task.nil?
+ binding_named_arguments_entries = binding_named_arguments.collect do |name, value|
+ "#{name.inspect} => #{value.inspect}"
+ end
+ unless binding_named_arguments_entries.empty?
+ arguments << binding_named_arguments_entries.join(', ')
+ end
+ unless arguments.empty?
+ if options.empty? && env.empty?
+ fragments << " #{arguments.join ', '}"
+ else
+ fragments << "(#{arguments.join ', '})"
+ end
+ end
+ end.join
+ end
+
+ def options
+ named_arguments.reject do |name, value|
+ name == :binding
+ end
+ end
+
+ end
+
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.