Module: CommonLib::ActiveSupportExtension::TestCase

Defined in:
lib/common_lib/active_support_extension/test_case.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
# File 'lib/common_lib/active_support_extension/test_case.rb', line 3

def self.included(base)
  # basically to include the model_name method to the CLASS
  base.extend ActiveModel::Naming
  base.extend(ClassMethods)
end

Instance Method Details

#assert_changes(expression, message = nil, &block) ⇒ Object

basically a copy of assert_difference, but without any explicit comparison as it is simply stating that something will change (designed for updated_at)



170
171
172
173
174
175
176
177
178
179
180
# File 'lib/common_lib/active_support_extension/test_case.rb', line 170

def assert_changes(expression, message = nil, &block)
  b = block.send(:binding)
  exps = Array.wrap(expression)
  before = exps.map { |e| eval(e, b) }
  yield
  exps.each_with_index do |e, i|
    error = "#{e.inspect} didn't change"
    error = "#{message}.\n#{error}" if message
    assert_not_equal(before[i], eval(e, b), error)
  end
end

#deny_changes(expression, message = nil, &block) ⇒ Object

Just a negation of assert_changes



183
184
185
186
187
188
189
190
191
192
193
# File 'lib/common_lib/active_support_extension/test_case.rb', line 183

def deny_changes(expression, message = nil, &block)
  b = block.send(:binding)
  exps = Array.wrap(expression)
  before = exps.map { |e| eval(e, b) }
  yield
  exps.each_with_index do |e, i|
    error = "#{e.inspect} changed"
    error = "#{message}.\n#{error}" if message
    assert_equal(before[i], eval(e, b), error)
  end
end

#turn_off_paperclip_loggingObject



195
196
197
198
199
# File 'lib/common_lib/active_support_extension/test_case.rb', line 195

def turn_off_paperclip_logging
  #  Is there I way to silence the paperclip output?  Yes...
  Paperclip.options[:log] = false
  #  Is there I way to capture the paperclip output for comparison?  Don't know.
end