Skip to content

Commit

Permalink
Fix Rubocop offenses (#6)
Browse files Browse the repository at this point in the history
* Except rspec describe and context block lenghts
* Add Rubocop to the Gemfile
* Add Rubocop check to Travis
  • Loading branch information
janosrusiczki committed Apr 1, 2019
1 parent fd9128d commit 5e9ec85
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
AllCops:
TargetRubyVersion: 2.3
Metrics/BlockLength:
ExcludedMethods: ['describe', 'context']
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ rvm:
- 2.6
script:
- bundle exec rspec
- bundle exec rubocop
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# frozen_string_literal: true

source 'https://rubygems.org'

group :development do
gem 'rspec', '~> 3.5.0'
end

group :test do
gem 'simplecov', require: false
gem 'coveralls', require: false
gem 'rubocop', require: false
gem 'simplecov', require: false
gem 'webmock'
end

Expand Down
3 changes: 3 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# frozen_string_literal: true

require 'rspec/core'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
end
Expand Down
11 changes: 10 additions & 1 deletion lib/underpass.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ module Underpass
# Example usage
#
# require 'underpass'
# wkt = <<-WKT
# POLYGON ((
# 23.669 47.65,
# 23.725 47.65,
# 23.725 47.674,
# 23.669 47.674,
# 23.669 47.65
# ))
# WKT
# f = RGeo::Geographic.spherical_factory
# bbox = f.parse_wkt('POLYGON ((23.669 47.65, 23.725 47.65, 23.725 47.674, 23.669 47.674, 23.669 47.65))')
# bbox = f.parse_wkt(wkt)
# op_query = 'way["heritage:operator"="lmi"]["ref:ro:lmi"="MM-II-m-B-04508"];'
# Underpass::QL::Query.perform(bbox, op_query)
4 changes: 2 additions & 2 deletions lib/underpass/ql/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ module Underpass
module QL
# Deals with performing the Overpass API request
class Request
API_URI = 'https://overpass-api.de/api/interpreter'.freeze
QUERY_TEMPLATE = <<-TEMPLATE.freeze
API_URI = 'https://overpass-api.de/api/interpreter'
QUERY_TEMPLATE = <<-TEMPLATE
[out:json][timeout:25]BBOX;
(
QUERY
Expand Down
10 changes: 6 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'simplecov'
SimpleCov.start do
add_filter '/spec/'
Expand Down Expand Up @@ -87,10 +89,10 @@
# file, and it's useful to allow more verbose output when running an
# individual spec file.
# if config.files_to_run.one?
# Use the documentation formatter for detailed output,
# unless a formatter has already been configured
# (e.g. via a command-line flag).
# config.default_formatter = "doc"
# Use the documentation formatter for detailed output,
# unless a formatter has already been configured
# (e.g. via a command-line flag).
# config.default_formatter = "doc"
# end

# Print the 10 slowest examples and example groups at the
Expand Down
3 changes: 2 additions & 1 deletion spec/underpass/ql/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
instance.instance_variable_set(:@ways, a: 1, b: 2)
end
it 'calls polygon from way and returns matches' do
expect(Underpass::QL::Shape).to receive(:polygon_from_way).twice.and_return('test')
expect(Underpass::QL::Shape).to receive(:polygon_from_way)
.twice.and_return('test')
expect(instance.matches.size).to eq(2)
end
end
Expand Down
15 changes: 11 additions & 4 deletions spec/underpass/ql/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,24 @@

describe '#perform' do
before do
stub_request(:post, 'https://overpass-api.de/api/interpreter').
to_return(body: File.read('spec/support/files/response.json'), status: 200)
stub_request(:post, 'https://overpass-api.de/api/interpreter')
.to_return(
body: File.read('spec/support/files/response.json'),
status: 200
)
end
it 'does what it has to' do
f = RGeo::Geographic.spherical_factory
bbox = f.parse_wkt('POLYGON ((-1 1, 1 1, 1 -1, -1 -1, -1 1))')
op_query = 'way["something"];'
results = subject.perform(bbox, op_query)
expect(results.size).to eq(1)
expect(results.first.class).to eq(RGeo::Geographic::SphericalPolygonImpl)
expect(results.first.as_text).to eq('POLYGON ((1.0 -1.0, 1.0 1.0, -1.0 1.0, -1.0 -1.0, 1.0 -1.0))')
expect(results.first.class).to eq(
RGeo::Geographic::SphericalPolygonImpl
)
expect(results.first.as_text).to eq(
'POLYGON ((1.0 -1.0, 1.0 1.0, -1.0 1.0, -1.0 -1.0, 1.0 -1.0))'
)
end
end
end
8 changes: 6 additions & 2 deletions spec/underpass/ql/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@

describe '#initialize' do
it 'sets the correct instance variables' do
expect(instance.instance_variable_get(:@overpass_query)).to eq('query_test')
expect(instance.instance_variable_get(:@global_bbox)).to eq('[bbox_test]')
expect(
instance.instance_variable_get(:@overpass_query)
).to eq('query_test')
expect(
instance.instance_variable_get(:@global_bbox)
).to eq('[bbox_test]')
end
end

Expand Down
16 changes: 12 additions & 4 deletions spec/underpass/ql/shape_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@
let(:way) { NodesAndWays::POLYGON_WAY }
it 'converts a way and its nodes to a polygon' do
polygon = Underpass::QL::Shape.polygon_from_way(way, nodes)
expect(polygon.class).to eq(RGeo::Geographic::SphericalPolygonImpl)
expect(polygon.as_text).to eq('POLYGON ((1.0 -1.0, 1.0 1.0, -1.0 1.0, 1.0 -1.0))')
expect(polygon.class).to eq(
RGeo::Geographic::SphericalPolygonImpl
)
expect(polygon.as_text).to eq(
'POLYGON ((1.0 -1.0, 1.0 1.0, -1.0 1.0, 1.0 -1.0))'
)
end
end

describe '#line_string_from_way' do
let(:way) { NodesAndWays::LINE_STRING_WAY }
it 'converts a way and its nodes to a linestring' do
line_string = Underpass::QL::Shape.line_string_from_way(way, nodes)
expect(line_string.class).to eq(RGeo::Geographic::SphericalLineStringImpl)
expect(line_string.as_text).to eq('LINESTRING (1.0 -1.0, 1.0 1.0, -1.0 1.0)')
expect(line_string.class).to eq(
RGeo::Geographic::SphericalLineStringImpl
)
expect(line_string.as_text).to eq(
'LINESTRING (1.0 -1.0, 1.0 1.0, -1.0 1.0)'
)
end
end
end

0 comments on commit 5e9ec85

Please sign in to comment.