view · edit · sidebar · attach · print · history

20130826-debug-brand2csv

<< | Index | >>


Summary

Commits / Patches

Index / Status


Debug NoMethodError at Download

I got error with any ruby version.

% bundle exec bin/brand2csv 01.01.2010-30.02.2010
Info: Suche meldet <Die Suchkriterien sind teilweise unzul> 
Info: Suche meldet <Erweiterte Suche> 
/path/to/brand2csv/lib/brand2csv.rb:424:in `initialize': undefined method `[]' for nil:NilClass (NoMethodError)
        from /path/to/brand2csv/lib/brand2csv.rb:488:in `new'
        from /path/to/brand2csv/lib/brand2csv.rb:488:in `getAllHits'
        from /path/to/brand2csv/lib/brand2csv.rb:527:in `fetchresult'
        from /path/to/brand2csv/lib/brand2csv.rb:560:in `run'
        from bin/brand2csv:47:in `<main>'

The result page does not have Seite \d+ von \d+ - Treffer ... text. (pagination).

[1] 2.0.0-p247(#<Brand2csv::Swissreg::Vereinfachte>)> doc.text.length
=> 8212
[2] 2.0.0-p247(#<Brand2csv::Swissreg::Vereinfachte>)> m = HitRegexpDE.match(doc.text)
=> nil
[14] 2.0.0-p247(#<Brand2csv::Swissreg::Vereinfachte>)> doc.text =~ /Seite\s/
=> nil

And I found this Validation Error in result.
This means date format is wrong. (In this case, I gave only Publikationsdatum)

Die Suchkriterien sind teilweise unzulässig (siehe Hinweiszeichen neben den Suchfeldern). Bitte korrigieren Sie Ihre Eingaben.

Swissreg.ch does not handle 30.02.2010 as 28.02.2010.
(Last day of month must be correcct. And 2010 is not leap year, last day is 28)

Note

It works fine. (with 01.01.2010-28.02.2010)

% bundle exec bin/brand2csv 01.01.2010-28.02.2010    
Info: Suche meldet <Vereinfachte Trefferliste anzeigen> 
Info: Suche meldet <Erweiterte Suche> 
[1] 2.0.0-p247(#<Brand2csv::Swissreg::Vereinfachte>)> m
=> #<MatchData
 "Seite 1 von 9 - Treffer 1-250 von 2'001"
 1:"1"
 2:"9"
 3:"1"
 4:"250"
 5:"2'001">

Create date validator

Get last day of month with Date class of Ruby

Swissreg.ch does not care about last day of month. It is too sensitive ... :(.
Then I updated to check date parameter for brand2csv with Date class of Ruby.

[1] 2.0.0-p247(main)> Date.new(2010,10,-1)
#<Date: 2010-10-31 ((2455501j,0s,0n),+0s,2299161j)>
[2] 2.0.0-p247(main)> Date.new(2010,02,-1)
#<Date: 2010-02-28 ((2455256j,0s,0n),+0s,2299161j)>

It creates last day of month with negative value (z.B. -1 )
Validator "Did you mean ?"

% bundle exec bin/brand2csv 01.01.2010-30.02.2010
Did you mean 01.01.2010-28.02.2010 ?
commit

link


Debug web test

The swissreg_spec send real request to swissreg.ch.
Now following example fails.

% bundle exec rspec                          
........getAllHits: returned 2 hits 
F.......

Failures:

  1) Get some simple example from swissreg should get correct results from swissreg
     Failure/Error: results.size.should == 1
       expected: 1
            got: 2 (using ==)
     # ./spec/swissreg_spec.rb:16:in `block (2 levels) in <top (required)>'

Finished in 8.45 seconds
16 examples, 1 failure

Failed examples:

rspec ./spec/swissreg_spec.rb:10 # Get some simple example from swissreg should get correct results from swissreg

I updated to pass this example with webmock.

commit
  • not yet

How to debug this gem

This gem uses Hoe for build & release.
So it does not contain gemspec.

For debug (without hoe), make gemspec like this.

% cd brand2csv
% bundle exec rake debug_gem > brand2csv.gemspec

% cd /tmp
% mkdir test
% cd test
% bundle init
% # add `gem "brand2csv", :path => "/path/to/brand2csv"`
% bundle install --path .bundle/gems
% bundle exec brand2csv "..." # before do this, please comment out line `if $0 == __FILE__` in bin/brand2csv
view · edit · sidebar · attach · print · history
Page last modified on August 26, 2013, at 10:55 AM