Skip to content

Commit

Permalink
Rename Configuration to Config
Browse files Browse the repository at this point in the history
  • Loading branch information
yujinakayama committed May 14, 2014
1 parent f5b615a commit 8ae29f7
Show file tree
Hide file tree
Showing 11 changed files with 342 additions and 342 deletions.
16 changes: 8 additions & 8 deletions lib/transpec/cli.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8

require 'transpec/commit_message'
require 'transpec/configuration'
require 'transpec/config'
require 'transpec/converter'
require 'transpec/dynamic_analyzer'
require 'transpec/option_parser'
Expand All @@ -13,21 +13,21 @@

module Transpec
class CLI
attr_reader :project, :configuration, :report
attr_reader :project, :config, :report

def self.run(args = ARGV)
new.run(args)
end

def initialize
@project = Project.new
@configuration = Configuration.new
@config = Config.new
@report = Report.new
end

def run(args)
begin
paths = OptionParser.new(configuration).parse(args)
paths = OptionParser.new(config).parse(args)
fail_if_should_not_continue!
rescue => error
warn error.message
Expand All @@ -51,7 +51,7 @@ def run(args)
def process(paths)
runtime_data = nil

unless configuration.skip_dynamic_analysis?
unless config.skip_dynamic_analysis?
runtime_data = run_dynamic_analysis(paths)
end

Expand All @@ -70,7 +70,7 @@ def process(paths)
def convert_spec(spec, spec_suite)
puts "Converting #{spec.path}"

converter = Converter.new(spec_suite, configuration, project.rspec_version)
converter = Converter.new(spec_suite, config, project.rspec_version)
converter.convert_file!(spec)

warn_annotations(converter.report)
Expand All @@ -83,7 +83,7 @@ def convert_spec(spec, spec_suite)
private

def fail_if_should_not_continue!
unless configuration.forced?
unless config.forced?
if Git.command_available? && Git.inside_of_repository? && !Git.clean?
fail 'The current Git repository is not clean. Aborting. ' \
'If you want to proceed forcibly, use -f/--force option.'
Expand All @@ -101,7 +101,7 @@ def run_dynamic_analysis(paths)

puts 'Copying the project for dynamic analysis...'

DynamicAnalyzer.new(rspec_command: configuration.rspec_command) do |analyzer|
DynamicAnalyzer.new(rspec_command: config.rspec_command) do |analyzer|
puts "Running dynamic analysis with command #{analyzer.rspec_command.inspect}..."
runtime_data = analyzer.analyze(paths)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/transpec/configuration.rb → lib/transpec/config.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8

module Transpec
class Configuration
class Config
NEGATIVE_FORMS_OF_TO = ['not_to', 'to_not'].freeze
FORMS_OF_BE_FALSEY = ['be_falsey', 'be_falsy'].freeze
BOOLEAN_MATCHER_TYPES = [:conditional, :exact].freeze
Expand Down
90 changes: 45 additions & 45 deletions lib/transpec/converter.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8

require 'transpec/base_rewriter'
require 'transpec/configuration'
require 'transpec/config'
require 'transpec/report'
require 'transpec/rspec_version'
require 'transpec/spec_suite'
Expand All @@ -13,15 +13,15 @@ module Transpec
class Converter < BaseRewriter # rubocop:disable ClassLength
include Syntax::Dispatcher

attr_reader :spec_suite, :configuration, :rspec_version, :report
attr_reader :spec_suite, :config, :rspec_version, :report

alias_method :convert_file!, :rewrite_file!
alias_method :convert_source, :rewrite_source
alias_method :convert, :rewrite

def initialize(spec_suite = nil, configuration = nil, rspec_version = nil)
def initialize(spec_suite = nil, config = nil, rspec_version = nil)
@spec_suite = spec_suite || SpecSuite.new
@configuration = configuration || Configuration.new
@config = config || Config.new
@rspec_version = rspec_version || Transpec.required_rspec_version
@report = Report.new
end
Expand All @@ -44,161 +44,161 @@ def process(ast, source_rewriter)
end

def process_should(should)
return unless configuration.convert_should?
should.expectize!(configuration.negative_form_of_to)
return unless config.convert_should?
should.expectize!(config.negative_form_of_to)
end

def process_oneliner_should(oneliner_should)
negative_form = configuration.negative_form_of_to
should_convert_have_items = configuration.convert_have_items? &&
negative_form = config.negative_form_of_to
should_convert_have_items = config.convert_have_items? &&
oneliner_should.have_matcher.conversion_target?

if should_convert_have_items
if configuration.convert_should?
if config.convert_should?
oneliner_should.convert_have_items_to_standard_expect!(negative_form)
else
oneliner_should.convert_have_items_to_standard_should!
end
elsif configuration.convert_oneliner? && rspec_version.oneliner_is_expected_available?
elsif config.convert_oneliner? && rspec_version.oneliner_is_expected_available?
oneliner_should.expectize!(negative_form)
end
end

def process_should_receive(should_receive)
if should_receive.useless_expectation?
if configuration.convert_deprecated_method?
if configuration.convert_stub?
should_receive.allowize_useless_expectation!(configuration.negative_form_of_to)
if config.convert_deprecated_method?
if config.convert_stub?
should_receive.allowize_useless_expectation!(config.negative_form_of_to)
else
should_receive.stubize_useless_expectation!
end
elsif configuration.convert_should_receive?
should_receive.expectize!(configuration.negative_form_of_to)
elsif config.convert_should_receive?
should_receive.expectize!(config.negative_form_of_to)
end
elsif configuration.convert_should_receive?
should_receive.expectize!(configuration.negative_form_of_to)
elsif config.convert_should_receive?
should_receive.expectize!(config.negative_form_of_to)
end
end

def process_double(double)
double.convert_to_double! if configuration.convert_deprecated_method?
double.convert_to_double! if config.convert_deprecated_method?
end

def process_method_stub(method_stub)
if configuration.convert_stub?
if config.convert_stub?
if !method_stub.hash_arg? ||
rspec_version.receive_messages_available? ||
configuration.convert_stub_with_hash_to_allow_to_receive_and_return?
config.convert_stub_with_hash_to_allow_to_receive_and_return?
method_stub.allowize!(rspec_version)
elsif configuration.convert_deprecated_method?
elsif config.convert_deprecated_method?
method_stub.convert_deprecated_method!
end
elsif configuration.convert_deprecated_method?
elsif config.convert_deprecated_method?
method_stub.convert_deprecated_method!
end

method_stub.remove_no_message_allowance! if configuration.convert_deprecated_method?
method_stub.remove_no_message_allowance! if config.convert_deprecated_method?
end

def process_operator(operator)
return unless configuration.convert_should?
return unless config.convert_should?
return if operator.expectation.is_a?(Syntax::OnelinerShould) &&
!rspec_version.oneliner_is_expected_available?
operator.convert_operator!(configuration.parenthesize_matcher_arg?)
operator.convert_operator!(config.parenthesize_matcher_arg?)
end

def process_be_boolean(be_boolean)
return unless rspec_version.be_truthy_available?
return unless configuration.convert_deprecated_method?
return unless config.convert_deprecated_method?

case configuration.boolean_matcher_type
case config.boolean_matcher_type
when :conditional
be_boolean.convert_to_conditional_matcher!(configuration.form_of_be_falsey)
be_boolean.convert_to_conditional_matcher!(config.form_of_be_falsey)
when :exact
be_boolean.convert_to_exact_matcher!
end
end

def process_be_close(be_close)
be_close.convert_to_be_within! if configuration.convert_deprecated_method?
be_close.convert_to_be_within! if config.convert_deprecated_method?
end

def process_raise_error(raise_error)
return unless raise_error
if configuration.convert_deprecated_method?
if config.convert_deprecated_method?
raise_error.remove_error_specification_with_negative_expectation!
end
end

def process_its(its)
its.convert_to_describe_subject_it! if configuration.convert_its?
its.convert_to_describe_subject_it! if config.convert_its?
end

def process_example(example)
return if !rspec_version.rspec_2_99? || !configuration.convert_pending?
return if !rspec_version.rspec_2_99? || !config.convert_pending?
example.convert_pending_to_skip!
end

def process_pending(pending)
return if !rspec_version.rspec_2_99? || !configuration.convert_pending?
return if !rspec_version.rspec_2_99? || !config.convert_pending?
pending.convert_deprecated_syntax!
end

def process_current_example(current_example)
return unless rspec_version.yielded_example_available?
current_example.convert! if configuration.convert_deprecated_method?
current_example.convert! if config.convert_deprecated_method?
end

def process_matcher_definition(matcher_definition)
return unless rspec_version.non_should_matcher_protocol_available?
matcher_definition.convert_deprecated_method! if configuration.convert_deprecated_method?
matcher_definition.convert_deprecated_method! if config.convert_deprecated_method?
end

def process_example_group(example_group)
return unless rspec_version.non_monkey_patch_example_group_available?
example_group.convert_to_non_monkey_patch! if configuration.convert_example_group?
example_group.convert_to_non_monkey_patch! if config.convert_example_group?
end

def process_rspec_configure(rspec_configure)
return unless spec_suite.main_rspec_configure_node?(rspec_configure.node)

if rspec_version.non_monkey_patch_example_group_available? &&
configuration.convert_example_group?
config.convert_example_group?
rspec_configure.expose_dsl_globally = false
end

if need_to_modify_yield_receiver_to_any_instance_implementation_blocks_config?
should_yield = configuration.add_receiver_arg_to_any_instance_implementation_block?
should_yield = config.add_receiver_arg_to_any_instance_implementation_block?
rspec_configure.mocks.yield_receiver_to_any_instance_implementation_blocks = should_yield
end
end

def process_have(have)
return if !have || !configuration.convert_have_items?
have.convert_to_standard_expectation!(configuration.parenthesize_matcher_arg)
return if !have || !config.convert_have_items?
have.convert_to_standard_expectation!(config.parenthesize_matcher_arg)
end

def process_hook(hook)
return if !configuration.convert_hook_scope? || !rspec_version.hook_scope_alias_available?
return if !config.convert_hook_scope? || !rspec_version.hook_scope_alias_available?
hook.convert_scope_name!
end

def process_useless_and_return(messaging_host)
return unless messaging_host
return unless configuration.convert_deprecated_method?
return unless config.convert_deprecated_method?
messaging_host.remove_useless_and_return!
end

def process_any_instance_block(messaging_host)
return unless messaging_host
return unless rspec_version.rspec_2_99?
return unless configuration.convert_deprecated_method?
return unless configuration.add_receiver_arg_to_any_instance_implementation_block?
return unless config.convert_deprecated_method?
return unless config.add_receiver_arg_to_any_instance_implementation_block?
messaging_host.add_receiver_arg_to_any_instance_implementation_block!
end

def need_to_modify_yield_receiver_to_any_instance_implementation_blocks_config?
rspec_version.rspec_2_99? && configuration.convert_deprecated_method? &&
rspec_version.rspec_2_99? && config.convert_deprecated_method? &&
spec_suite.need_to_modify_yield_receiver_to_any_instance_implementation_blocks_config?
end
end
Expand Down
26 changes: 13 additions & 13 deletions lib/transpec/option_parser.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding: utf-8

require 'transpec/configuration'
require 'transpec/config'
require 'transpec/git'
require 'transpec/version'
require 'optparse'
Expand Down Expand Up @@ -28,14 +28,14 @@ class OptionParser # rubocop:disable ClassLength

VALID_BOOLEAN_MATCHER_TYPES = %w(truthy,falsey truthy,falsy true,false)

attr_reader :configuration
attr_reader :config

def self.available_conversion_types
CONFIG_ATTRS_FOR_KEEP_TYPES.keys
end

def initialize(configuration = Configuration.new)
@configuration = configuration
def initialize(config = Config.new)
@config = config
setup_parser
end

Expand All @@ -55,11 +55,11 @@ def setup_parser # rubocop:disable MethodLength
@parser = create_parser

define_option('-f', '--force') do
configuration.forced = true
config.forced = true
end

define_option('-c', '--rspec-command COMMAND') do |command|
configuration.rspec_command = command
config.rspec_command = command
end

define_option('-k', '--keep TYPE[,TYPE...]') do |types|
Expand All @@ -71,28 +71,28 @@ def setup_parser # rubocop:disable MethodLength
end

define_option('-s', '--skip-dynamic-analysis') do
configuration.skip_dynamic_analysis = true
config.skip_dynamic_analysis = true
end

define_option('-n', '--negative-form FORM') do |form|
configuration.negative_form_of_to = form
config.negative_form_of_to = form
end

define_option('-b', '--boolean-matcher TYPE') do |type|
unless VALID_BOOLEAN_MATCHER_TYPES.include?(type)
types = VALID_BOOLEAN_MATCHER_TYPES.map(&:inspect).join(', ')
fail ArgumentError, "Boolean matcher type must be any of #{types}"
end
configuration.boolean_matcher_type = type.include?('truthy') ? :conditional : :exact
configuration.form_of_be_falsey = type.include?('falsy') ? 'be_falsy' : 'be_falsey'
config.boolean_matcher_type = type.include?('truthy') ? :conditional : :exact
config.form_of_be_falsey = type.include?('falsy') ? 'be_falsy' : 'be_falsey'
end

define_option('-a', '--no-yield-any-instance') do
configuration.add_receiver_arg_to_any_instance_implementation_block = false
config.add_receiver_arg_to_any_instance_implementation_block = false
end

define_option('-p', '--no-parentheses-matcher-arg') do
configuration.parenthesize_matcher_arg = false
config.parenthesize_matcher_arg = false
end

define_option('--no-color') do
Expand Down Expand Up @@ -222,7 +222,7 @@ def configure_conversion(type_to_attr_map, inputted_types, boolean)
inputted_types.split(',').each do |type|
config_attr = type_to_attr_map[type.to_sym]
fail ArgumentError, "Unknown syntax type #{type.inspect}" unless config_attr
configuration.send(config_attr, boolean)
config.send(config_attr, boolean)
end
end
end
Expand Down
Loading

0 comments on commit 8ae29f7

Please sign in to comment.