class RSpec::ActiveRecord::Expectations::MessageBuilder::TransactionPhrases

Attributes

matcher[R]

Public Class Methods

new(matcher) click to toggle source
# File lib/rspec/activerecord/expectations/message_builder.rb, line 93
def initialize(matcher)
  @matcher = matcher
end

Public Instance Methods

negative_suffix() click to toggle source
# File lib/rspec/activerecord/expectations/message_builder.rb, line 130
def negative_suffix
  if matcher.comparison == :exactly
    "did so"
  else
    suffix
  end
end
prefix() click to toggle source
# File lib/rspec/activerecord/expectations/message_builder.rb, line 97
def prefix
  nouns = matcher.quantifier == 1 ? "transaction" : "transactions"
  verb  = case matcher.query_type
    when :transaction_queries then "execute"
    when :rollback_queries then "roll back"
    when :commit_queries then "commit"
  end

  "#{verb} #{comparison} #{nouns}"
end
suffix() click to toggle source
# File lib/rspec/activerecord/expectations/message_builder.rb, line 108
def suffix
  singular_verb  = case matcher.query_type
    when :transaction_queries then "execute"
    when :rollback_queries then "roll back"
    when :commit_queries then "commit"
  end

  plural_verb  = case matcher.query_type
    when :transaction_queries then "executed"
    when :rollback_queries then "rolled back"
    when :commit_queries then "committed"
  end

  if matcher.actual_count == 0
    "didn't #{singular_verb} any"
  elsif matcher.actual_count == 1
    "#{plural_verb} one"
  else
    "#{plural_verb} #{matcher.actual_count}"
  end
end

Private Instance Methods

comparison() click to toggle source
# File lib/rspec/activerecord/expectations/message_builder.rb, line 140
def comparison
  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