view · edit · sidebar · attach · print · history

20110324-testcases-oddb_org

<< | Index | >>


Goal/Estimate/Evaluation
  • test-cases coverage oddb.org / 78% / 77.86%
Milestones
  1. test_plugin/doctors.rb (coverage: 95.77%) 11:30
  2. test_view/centeredsearchform.rb (coverage: 100%) 15:20
  3. test_view/interactions/basket.rb (coverage: 95.49%)
Commits

Tips

To replace a constant in a method

  keep = ODDB::Doctors::DoctorPlugin::PARSER
  eval 'ODDB::Doctors::DoctorPlugin::PARSER = xxx'
  assert_equal(something)
  eval 'ODDB::Doctors::DoctorPlugin::PARSER = keep'

Note

  • Flexmock does not work to replace a constant
  • The constant must be restore by the original value, otherwise it may influence the other test files
  • Many DRbObject instances are set in constants in oddb.org probject
  • This tip is useful for the test-cases that calles DRbObject

This is useful to avoid outputting warning message

  def stderr_null
    require 'tempfile'
    $stderr = Tempfile.open('stderr')
    yield
    $stderr.close
    $stderr = STDERR
  end

  def replace_constant(constant, temp)
    stderr_null do
      keep = eval constant
      eval "#{constant} = temp"
      yield
      eval "#{constant} = keep"
    end
  end

Example

 module ODDB
  module Doctors
    class DoctorPlugin < Plugin
      RECIPIENTS = []
      PARSER = DRbObject.new(nil, DOCPARSE_URI)
 ...
      def get_doctor_data(doc_id)
        retry_count = 3
        begin
          self::class::PARSER.doc_data_add_ean(doc_id)
 ...
  • test-case
  def test_get_doctor_data
    parser = flexmock('parser', :doc_data_add_ean => 'doc_data_add_ean')
    replace_constant('ODDB::Doctors::DoctorPlugin::PARSER', parser) do
      assert_equal('doc_data_add_ean', @plugin.get_doctor_data('doc_id'))
    end
  end
view · edit · sidebar · attach · print · history
Page last modified on March 24, 2011, at 04:54 PM