Module: Transpec::Syntax::Have::DynamicAnalysis
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/transpec/syntax/have/dynamic_analysis.rb
Instance Method Summary collapse
- #available_query_methods_inspection_code ⇒ Object
-
#collection_accessor_inspection_code ⇒ Object
rubocop:disable MethodLength.
- #subject_code ⇒ Object
Instance Method Details
#available_query_methods_inspection_code ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/transpec/syntax/have/dynamic_analysis.rb', line 83 def available_query_methods_inspection_code <<-END.gsub(/^\s+\|/, '').chomp |collection_accessor = #{collection_accessor_inspection_code} |target = if collection_accessor | #{subject_code}.__send__(collection_accessor) | else | #{subject_code} | end |target.methods & #{QUERY_METHOD_PRIORITIES.inspect} END end |
#collection_accessor_inspection_code ⇒ Object
rubocop:disable MethodLength
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 |
# File 'lib/transpec/syntax/have/dynamic_analysis.rb', line 42 def collection_accessor_inspection_code # rubocop:disable MethodLength # `expect(owner).to have(n).things` invokes private owner#things with Object#__send__ # if the owner does not respond to any of #size, #count and #length. # # rubocop:disable LineLength # https://github.com/rspec/rspec-expectations/blob/v2.14.3/lib/rspec/matchers/built_in/have.rb#L48-L58 # rubocop:enable LineLength @collection_accessor_inspection_code ||= <<-END.gsub(/^\s+\|/, '').chomp |begin | exact_name = #{items_name.inspect} | | inflector = if defined?(ActiveSupport::Inflector) && | ActiveSupport::Inflector.respond_to?(:pluralize) | ActiveSupport::Inflector | elsif defined?(Inflector) | Inflector | else | nil | end | | if inflector | pluralized_name = inflector.pluralize(exact_name).to_sym | respond_to_pluralized_name = #{subject_code}.respond_to?(pluralized_name) | end | | respond_to_query_methods = | !(#{subject_code}.methods & #{QUERY_METHOD_PRIORITIES.inspect}).empty? | | if #{subject_code}.respond_to?(exact_name) | exact_name | elsif respond_to_pluralized_name | pluralized_name | elsif respond_to_query_methods | nil | else | exact_name | end |end END end |
#subject_code ⇒ Object
38 39 40 |
# File 'lib/transpec/syntax/have/dynamic_analysis.rb', line 38 def subject_code explicit_subject? ? 'self' : 'subject' end |