module Transpec::Syntax::Have::DynamicAnalysis
Public Instance Methods
available_query_methods_inspection_code()
click to toggle source
# File lib/transpec/syntax/have/dynamic_analysis.rb, line 85 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()
click to toggle source
# File lib/transpec/syntax/have/dynamic_analysis.rb, line 46 def collection_accessor_inspection_code # `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. # # https://github.com/rspec/rspec-expectations/blob/v2.14.3/lib/rspec/matchers/built_in/have.rb#L48-L58 @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()
click to toggle source
# File lib/transpec/syntax/have/dynamic_analysis.rb, line 42 def subject_code explicit_subject? ? 'self' : 'subject' end