Explorar el Código

Some initial tests

tags/v0.4.5
pezholio hace 6 años
padre
commit
3a1499524f
Se han modificado 6 ficheros con 69 adiciones y 3 borrados
  1. +2
    -0
      .rspec
  2. +3
    -0
      lib/uk_planning_scraper.rb
  3. +4
    -3
      lib/uk_planning_scraper/authority.rb
  4. +42
    -0
      spec/authority_spec.rb
  5. +16
    -0
      spec/spec_helper.rb
  6. +2
    -0
      uk_planning_scraper.gemspec

+ 2
- 0
.rspec Ver fichero

@@ -0,0 +1,2 @@
--require spec_helper
--format=documentation

+ 3
- 0
lib/uk_planning_scraper.rb Ver fichero

@@ -7,4 +7,7 @@ require 'logger'
module UKPlanningScraper
class SystemNotSupportedError < StandardError
end
class AuthorityNotFound < StandardError
end
end

+ 4
- 3
lib/uk_planning_scraper/authority.rb Ver fichero

@@ -72,8 +72,9 @@ module UKPlanningScraper
end
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

# Tagged x
@@ -99,7 +100,7 @@ module UKPlanningScraper

def self.load
# Don't run this method more than once
return unless @@authorities.empty?
return unless @@authorities.empty?
# FIXME hardcoded file path
CSV.foreach(File.join(File.dirname(__dir__), 'uk_planning_scraper', 'authorities.csv')) do |line|
@@authorities << Authority.new(


+ 42
- 0
spec/authority_spec.rb Ver fichero

@@ -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

+ 16
- 0
spec/spec_helper.rb Ver fichero

@@ -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

+ 2
- 0
uk_planning_scraper.gemspec Ver fichero

@@ -30,6 +30,8 @@ Gem::Specification.new do |spec|

spec.add_development_dependency "bundler", "~> 1.15"
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 "http"


Cargando…
Cancelar
Guardar