Class: Transpec::Syntax::RSpecConfigure

Inherits:
Transpec::Syntax show all
Includes:
Mixin::RSpecRails, Mixin::Send, ConfigModification
Defined in:
lib/transpec/syntax/rspec_configure.rb,
lib/transpec/syntax/rspec_configure/mocks.rb,
lib/transpec/syntax/rspec_configure/framework.rb,
lib/transpec/syntax/rspec_configure/expectations.rb,
lib/transpec/syntax/rspec_configure/config_modification.rb

Defined Under Namespace

Modules: ConfigModification Classes: Expectations, Framework, Mocks

Constant Summary

Constants included from Util

Util::LITERAL_TYPES, Util::WHITESPACES

Instance Attribute Summary

Attributes inherited from Transpec::Syntax

#node, #report, #runtime_data, #source_rewriter

Instance Method Summary collapse

Methods included from Mixin::Send

#arg_node, #arg_nodes, #arg_range, #args_range, #method_name, #parentheses_range, #range_after_arg, #range_in_between_receiver_and_selector, #range_in_between_selector_and_arg, #receiver_node, #receiver_range, #selector_range

Methods included from Mixin::Send::TargetDetection

#conversion_target?

Methods included from Mixin::RSpecRails

#rspec_rails?

Methods included from ConfigModification::ConfigAddition

#add_config!, #block_node_to_insert_code, #body_indentation, #config_variable_name, #empty_block_body?, #generate_config_lines

Methods included from Util

beginning_of_line_range, block_node_taken_by_method, chainable_source, const_name, contain_here_document?, each_backward_chained_node, each_forward_chained_node, each_line_range, expand_range_to_adjacent_whitespaces, find_consecutive_whitespace_position, first_block_arg_name, here_document?, in_explicit_parentheses?, indentation_of_line, line_range, literal?, proc_literal?, range_from_arg

Methods inherited from Transpec::Syntax

#add_record, #conversion_target?, #dependent_syntaxes, #expression_range, #initialize, #inspect, #parent_node, snake_case_name, standalone?, #static_context_inspector

Methods included from Collection

#all_syntaxes, #inherited, #mixins, #require_all, #standalone_syntaxes

Methods included from DynamicAnalysis

#register_dynamic_analysis_request

Constructor Details

This class inherits a constructor from Transpec::Syntax

Instance Method Details

#block_arg_nameObject



108
109
110
# File 'lib/transpec/syntax/rspec_configure.rb', line 108

def block_arg_name
  first_block_arg_name(block_node)
end

#convert_deprecated_options!(rspec_version) ⇒ Object

rubocop:disable MethodLength



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
# File 'lib/transpec/syntax/rspec_configure.rb', line 68

def convert_deprecated_options!(rspec_version) # rubocop:disable MethodLength
  replace_config!(:backtrace_clean_patterns,  :backtrace_exclusion_patterns)
  replace_config!(:backtrace_clean_patterns=, :backtrace_exclusion_patterns=)
  replace_config!(:color_enabled=, :color=)

  if rspec_version.config_output_stream_available?
    replace_config!(:output,  :output_stream)
    replace_config!(:output=, :output_stream=)
    replace_config!(:out,     :output_stream)
    replace_config!(:out=,    :output_stream=)
  end

  if rspec_version.config_pattern_available?
    replace_config!(:filename_pattern,  :pattern)
    replace_config!(:filename_pattern=, :pattern=)
  end

  if rspec_version.config_backtrace_formatter_available?
    replace_config!(:backtrace_cleaner,  :backtrace_formatter)
  end

  if rspec_version.config_predicate_color_enabled_available?
    replace_config!(:color?, :color_enabled?)
  end

  if rspec_version.config_predicate_warnings_available?
    replace_config!(:warnings, :warnings?)
  end
end

#dynamic_analysis_target?Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/transpec/syntax/rspec_configure.rb', line 23

def dynamic_analysis_target?
  return false unless super
  const_name(receiver_node) == 'RSpec' && method_name == :configure && parent_node.block_type?
end

#expectationsObject



98
99
100
# File 'lib/transpec/syntax/rspec_configure.rb', line 98

def expectations
  @expectations ||= Expectations.new(self)
end

#expose_dsl_globally=(value) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/transpec/syntax/rspec_configure.rb', line 28

def expose_dsl_globally=(value)
  comment = <<-END.gsub(/^\s+\|/, '').chomp
    |Setting this config option `false` removes rspec-core's monkey patching of the
    |top level methods like `describe`, `shared_examples_for` and `shared_context`
    |on `main` and `Module`. The methods are always available through the `RSpec`
    |module like `RSpec.describe` regardless of this setting.
    |For backwards compatibility this defaults to `true`.
    |
    |https://relishapp.com/rspec/rspec-core/v/3-0/docs/configuration/global-namespace-dsl
  END
  set_config_value!(:expose_dsl_globally, value, comment)
end

#infer_spec_type_from_file_location!Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/transpec/syntax/rspec_configure.rb', line 41

def infer_spec_type_from_file_location!
  return if infer_spec_type_from_file_location?
  return unless rspec_rails?

  # Based on the deprecation warning in RSpec 2.99:
  # https://github.com/rspec/rspec-rails/blob/ab6313b/lib/rspec/rails/infer_type_configuration.rb#L13-L22
  # and the Myron's post:
  # http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#filetype_inference_disabled_by_default
  comment = <<-END.gsub(/^\s+\|/, '').chomp
    |rspec-rails 3 will no longer automatically infer an example group's spec type
    |from the file location. You can explicitly opt-in to the feature using this
    |config option.
    |To explicitly tag specs without using automatic inference, set the `:type`
    |metadata manually:
    |
    |    describe ThingsController, :type => :controller do
    |      # Equivalent to being in spec/controllers
    |    end
  END

  add_config!(:infer_spec_type_from_file_location!, nil, comment)
end

#infer_spec_type_from_file_location?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/transpec/syntax/rspec_configure.rb', line 64

def infer_spec_type_from_file_location?
  !find_config_node(:infer_spec_type_from_file_location!).nil?
end

#mocksObject



102
103
104
# File 'lib/transpec/syntax/rspec_configure.rb', line 102

def mocks
  @mocks ||= Mocks.new(self)
end