view · edit · sidebar · attach · print · history

20110418-testcases-oddb_org

<< | Index | >>


  1. Update testcases

Goal/Estimate/Evaluation
  • Testcases / 84% / 83.61%
Milestones
  • Update testcases
    1. src/view/drugs/register_download.rb (coverage: 100%) 8:30
    2. src/view/admin/address_suggestion.rb (coverage: 100%) 9:00
    3. src/plugin/csv_export.rb (coverage: 100%) 15:30
    4. src/state/paypal/checkout.rb (coverage: 18.98%)
    5. src/view/drugs/narcotic.rb (coverage: 67.88%)
Summary
Commits
  1. Patch from Bjoern Andersson for Exploding on write when NaN is encountered (spreadsheet)
  2. Updated testcases, mainly, test_view/admin/address_suggestion.rb, drugs/register_download.rb, test_plugin/csv_export.rb

Memo (replace constant in a testcase)

    def temporary_replace_constant(object, const, replace)
      require 'tempfile'
      $stderr = Tempfile.new('stderr')
      temp = nil
      object.instance_eval("temp = #{const}; #{const} = replace")
      yield
      object.instance_eval("#{const} = temp")
      $stderr.close
      $stderr = STDERR
    end

How to use

    def test_export_price_history
      export_server = flexmock('export_server', :export_price_history_csv => 'export_price_history_csv')
      package = flexmock('package',
                         :has_price? => true,
                         :odba_id    => 123
                        )
      flexmock(@app, :packages => [package])
      temporary_replace_constant(@plugin, 'ODDB::CsvExportPlugin::EXPORT_SERVER', export_server ) do
        assert_equal('export_price_history_csv', @plugin.export_price_history)
      end
    end

Note

  • In the CsvExportPlugin class, the EXPORT_SERVER constant is defined in the level of class as below
 module ODDB
  class CsvExportPlugin < Plugin
    EXPORT_SERVER = DRbObject.new(nil, EXPORT_URI)
  • This code is executed when the file is read
  • In such a case, it is difficult to replace the object by flexmock
    • and also, in fact, I can replace neither EXPORT_SERVER nor DRbObject by flexmock object in this case
  • because, I guess, the flexmock works when the instance is created after the loading of a Ruby script
  • The method above replaces a constant forcibly after the instance creation
  • A warning comes usually when a constant is replaced, but in the method above the warning message is thrown away to a temporary file
view · edit · sidebar · attach · print · history
Page last modified on April 19, 2011, at 07:19 AM