class RSpec::ActiveRecord::Expectations::MessageBuilder::QueryPhrases
TODO: expect {}.not_to execute.less_than_or_equal_to(3).insert_queries expected block not to execute at most 3 insert queries, but it executed 0
Attributes
matcher[R]
Public Class Methods
new(matcher)
click to toggle source
# File lib/rspec/activerecord/expectations/message_builder.rb, line 31 def initialize(matcher) @matcher = matcher end
Public Instance Methods
negative_suffix()
click to toggle source
using positive suffix from above can cause double negatives
# File lib/rspec/activerecord/expectations/message_builder.rb, line 50 def negative_suffix if matcher.comparison == :exactly "did so" elsif matcher.actual_count == 1 "executed one" else "executed #{matcher.actual_count}" end end
prefix()
click to toggle source
# File lib/rspec/activerecord/expectations/message_builder.rb, line 35 def prefix "execute #{comparison_phrase} #{query_type_name}" end
suffix()
click to toggle source
# File lib/rspec/activerecord/expectations/message_builder.rb, line 39 def suffix if matcher.actual_count == 0 "didn't execute any" elsif matcher.actual_count == 1 "executed one" else "executed #{matcher.actual_count}" end end
Private Instance Methods
comparison_phrase()
click to toggle source
# File lib/rspec/activerecord/expectations/message_builder.rb, line 70 def comparison_phrase quant = if matcher.quantifier == 1 && matcher.comparison == :exactly "a" elsif matcher.quantifier == 1 "one" else matcher.quantifier end case matcher.comparison when :exactly then quant when :greater_than then "more than #{quant}" when :greater_than_or_equal_to then "at least #{quant}" when :less_than then "less than #{quant}" when :less_than_or_equal_to then "at most #{quant}" else raise ArgumentError, "unsupported comparison matcher #{matcher.comparison}" end end
query_type_name()
click to toggle source
# File lib/rspec/activerecord/expectations/message_builder.rb, line 62 def query_type_name if matcher.quantifier == 1 matcher.query_type.to_s.gsub("_", " ").gsub("queries", "query") else matcher.query_type.to_s.gsub("_", " ") end end