@@ -0,0 +1,2 @@ | |||||
--require spec_helper | |||||
--format=documentation |
@@ -7,4 +7,7 @@ require 'logger' | |||||
module UKPlanningScraper | module UKPlanningScraper | ||||
class SystemNotSupportedError < StandardError | class SystemNotSupportedError < StandardError | ||||
end | end | ||||
class AuthorityNotFound < StandardError | |||||
end | |||||
end | end |
@@ -72,8 +72,9 @@ module UKPlanningScraper | |||||
end | end | ||||
def self.named(name) | def self.named(name) | ||||
@@authorities.each { |a| return a if name == a.name } | |||||
nil | |||||
authority = @@authorities.find { |a| name == a.name } | |||||
raise AuthorityNotFound if authority.nil? | |||||
authority | |||||
end | end | ||||
# Tagged x | # Tagged x | ||||
@@ -99,7 +100,7 @@ module UKPlanningScraper | |||||
def self.load | def self.load | ||||
# Don't run this method more than once | # Don't run this method more than once | ||||
return unless @@authorities.empty? | |||||
return unless @@authorities.empty? | |||||
# FIXME hardcoded file path | # FIXME hardcoded file path | ||||
CSV.foreach(File.join(File.dirname(__dir__), 'uk_planning_scraper', 'authorities.csv')) do |line| | CSV.foreach(File.join(File.dirname(__dir__), 'uk_planning_scraper', 'authorities.csv')) do |line| | ||||
@@authorities << Authority.new( | @@authorities << Authority.new( | ||||
@@ -0,0 +1,42 @@ | |||||
require 'spec_helper' | |||||
describe UKPlanningScraper::Authority do | |||||
describe '#named' do | |||||
let(:authority) { described_class.named(authority_name) } | |||||
context 'when authority exists' do | |||||
let(:authority_name) { 'Westminster' } | |||||
it 'returns an authority' do | |||||
expect(authority).to be_a(UKPlanningScraper::Authority) | |||||
end | |||||
end | |||||
context 'when authority does not exist' do | |||||
let(:authority_name) { 'Westmonster' } | |||||
it 'raises an error' do | |||||
expect { authority }.to raise_error(UKPlanningScraper::AuthorityNotFound) | |||||
end | |||||
end | |||||
end | |||||
describe '#all' do | |||||
let(:all) { described_class.all } | |||||
it 'returns all authorities' do | |||||
expect(all.count).to eq(48) | |||||
end | |||||
it 'returns a list of authorities' do | |||||
all.each do |authority| | |||||
expect(authority).to be_a(UKPlanningScraper::Authority) | |||||
end | |||||
end | |||||
end | |||||
end |
@@ -0,0 +1,16 @@ | |||||
require 'simplecov' | |||||
SimpleCov.start | |||||
require 'uk_planning_scraper' | |||||
RSpec.configure do |config| | |||||
config.expect_with :rspec do |expectations| | |||||
expectations.include_chain_clauses_in_custom_matcher_descriptions = true | |||||
end | |||||
config.mock_with :rspec do |mocks| | |||||
mocks.verify_partial_doubles = true | |||||
end | |||||
config.shared_context_metadata_behavior = :apply_to_host_groups | |||||
end |
@@ -30,6 +30,8 @@ Gem::Specification.new do |spec| | |||||
spec.add_development_dependency "bundler", "~> 1.15" | spec.add_development_dependency "bundler", "~> 1.15" | ||||
spec.add_development_dependency "rake", "~> 10.0" | spec.add_development_dependency "rake", "~> 10.0" | ||||
spec.add_development_dependency "rspec", "~> 3.8.0" | |||||
spec.add_development_dependency "simplecov", "~> 0.16.1" | |||||
spec.add_runtime_dependency "mechanize", "~> 2.7" | spec.add_runtime_dependency "mechanize", "~> 2.7" | ||||
spec.add_runtime_dependency "http" | spec.add_runtime_dependency "http" | ||||