everypolitician / scraper_test

Data-driven scraper tests for Scraped
0 stars 0 forks source link

Better error message when missing class name #1

Open chrismytton opened 7 years ago

chrismytton commented 7 years ago

Problem

If you forget to specify the class name in the YAML the error message you get is quite hard to decipher.

$ bundle exec rake test
Run options: --seed 5248

# Running:

E

Finished in 0.006394s, 156.4078 runs/s, 0.0000 assertions/s.

  1) Error:
Scraper tests#test_0001_should contain the expected data:
TypeError: no implicit conversion of nil into String
    /Users/chris/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/bundler/gems/scraper_test-41fc622fe61a/lib/scraper_test.rb:32:in `const_get'
    /Users/chris/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/bundler/gems/scraper_test-41fc622fe61a/lib/scraper_test.rb:32:in `block (4 levels) in install_tasks'
    /Users/chris/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/bundler/gems/scraper_test-41fc622fe61a/lib/scraper_test.rb:29:in `each'
    /Users/chris/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/bundler/gems/scraper_test-41fc622fe61a/lib/scraper_test.rb:29:in `block (3 levels) in install_tasks'

1 runs, 0 assertions, 0 failures, 1 errors, 0 skips

Proposed solution

Check for the class key in the data file and if it's missing print a friendly error message if it's missing.

Acceptance criteria

Running the tests for data files that don't have a class property should produce a friendly error message.