alephant-scout 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 426febd1ef7d655e339a07a119386a521b5c58a3
4
- data.tar.gz: ada16f35afc2d6b2e8f4e60636cd3637824a59a0
3
+ metadata.gz: 85b78e083608aaed93af7260ac8161a2b98fc790
4
+ data.tar.gz: f0ad36b38085673ef343c9de31dd3630258a7743
5
5
  SHA512:
6
- metadata.gz: cbdcf4bcf6d8d18e58d985224425c0218359d79bda29ceee61c284b7beda5aff3e612f655f7ec8396fe9cb0dcfb1f02b3e1067917d662cf49130837835bbe52a
7
- data.tar.gz: 72a91040e69b017d1c2c7169ef9e9f1abae2a9bdb42c70b374a1b74140a9368b606d24d5f2199fb7a0333e56f8ba89f5f9a8dc166eb3e2301c7239f43cc00331
6
+ metadata.gz: ef71e5fd065d54f3005f4ec9c1ce2e6713c736f6bb679d11052f7dbfc8066ade82855f6415f7c7ddae75e9ece7aab048ec9b8383cc2a7619e7445bbfab0d4815
7
+ data.tar.gz: 566c5d263ae1c292c4b24b7cdc4b7413945712c0c55888437a8a3da460c24222784ce7e746f04bee15a43aad895080c2089ffb55d4467e6437b0c39522e7e059
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Alephant::Scout
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/alephant-scout.svg)](http://badge.fury.io/rb/alephant-scout)
4
+
3
5
  This is a gem to allow Alephant based applications to check the validity of an arbitrary URL / URI
4
6
  before enqueuing messages to render content based on the content of said URL / URI, thereby protecting
5
7
  render nodes from having to handle bogus URLs / URIs.
@@ -23,33 +25,17 @@ Or install it yourself as:
23
25
  ```rb
24
26
  require 'alephant-scout'
25
27
 
28
+ Alephant::Scout::Url.valid? 'http://bbc.co.uk/persian/world'
26
29
  # => true
27
30
 
28
- good_url = 'http://www.bbc.co.uk/persian/world'
29
-
30
- # => "http://www.bbc.co.uk/persian/world"
31
-
32
- bad_url = 'http://www.bbc.co.uk/persian/lobster-hatstand'
33
-
34
- # => "http://www.bbc.co.uk/persian/lobster-hatstand"
35
-
36
- url_scout = Alephant::Scout::Url.new()
37
-
38
- # = > #<Alephant::Scout::Url:[ObjectId]>
39
-
40
- url_scout.valid?(good_url)
41
-
42
- # => true
43
-
44
- url_scout.valid?(bad_url)
45
-
31
+ Alephant::Scout::Url.valid? 'http://bbc.co.uk/batman'
46
32
  # => false
47
33
  ```
48
34
 
49
35
  ## Contributing
50
36
 
51
- 1. Fork it
52
- 2. Create your feature branch (`git checkout -b my-new-feature`)
53
- 3. Commit your changes (`git commit -am 'Add some feature'`)
54
- 4. Push to the branch (`git push origin my-new-feature`)
55
- 5. Create new Pull Request
37
+ 1. [Fork it!](https://github.com/bbc-news/alephant-scout/fork)
38
+ 2. Create your feature branch: `git checkout -b my-new-feature`
39
+ 3. Commit your changes: `git commit -am 'Add some feature'`
40
+ 4. Push to the branch: `git push origin my-new-feature`
41
+ 5. Create new [Pull Request](https://github.com/bbc-news/alephant-scout/pulls).
data/Rakefile CHANGED
@@ -1,9 +1,6 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__), 'lib')
2
2
 
3
- require 'rspec/core/rake_task'
4
3
  require 'bundler/gem_tasks'
5
- require 'alephant/scout'
6
-
7
- RSpec::Core::RakeTask.new(:spec)
4
+ require 'rake/rspec'
8
5
 
9
6
  task :default => :spec
@@ -20,6 +20,9 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", ">= 3.1"
24
+ spec.add_development_dependency "rspec-nc"
25
+ spec.add_development_dependency "rake-rspec"
23
26
 
24
27
  spec.add_runtime_dependency "httparty", "~> 0.13.1"
25
28
  spec.add_runtime_dependency "alephant-logger"
@@ -2,9 +2,9 @@ require "httparty"
2
2
 
3
3
  module Alephant
4
4
  module Scout
5
- class Url
6
- def valid?(url_to_scout)
7
- HTTParty.head(url_to_scout).code == 200
5
+ module Url
6
+ def self.valid?(url)
7
+ HTTParty.head(url).code == 200
8
8
  rescue
9
9
  false
10
10
  end
@@ -1,5 +1,5 @@
1
1
  module Alephant
2
2
  module Scout
3
- VERSION = "0.0.1"
3
+ VERSION = '1.0.0'
4
4
  end
5
5
  end
@@ -0,0 +1 @@
1
+ require_relative '../spec_helper'
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Alephant::Scout::Url do
4
+ describe '.valid?' do
5
+ context 'using a valid URL' do
6
+ let(:url) { 'http://bbc.co.uk/persian/world' }
7
+ specify { expect(described_class.valid? url).to be }
8
+ end
9
+
10
+ context 'using an invalid URL' do
11
+ let(:url) { 'http://bbc.co.uk/batman' }
12
+ specify { expect(described_class.valid? url).to be false}
13
+ end
14
+ end
15
+ end
@@ -1,30 +1,43 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Alephant::Scout::Url do
4
- describe ".valid?(url)" do
4
+ describe '.valid?' do
5
5
  let(:response) { double('HTTParty::Response') }
6
- it "is a valid url" do
7
- allow(response).to receive(:code).and_return(200)
8
- allow(HTTParty).to receive(:head).and_return(response)
9
- expect(subject.valid?('http://www.avalidurl.com')).to be true
6
+
7
+ context 'using a valid URL' do
8
+ let(:url) { 'http://a-valid-url.com' }
9
+ before do
10
+ allow(HTTParty).to receive(:head).once.with(url).and_return(response)
11
+ allow(response).to receive(:code).once.and_return(200)
12
+ end
13
+ specify { expect(described_class.valid? url).to be }
10
14
  end
11
15
 
12
- it "is a valid url with an issue" do
13
- allow(response).to receive(:code).and_return(500)
14
- allow(HTTParty).to receive(:head).and_return(response)
15
- expect(subject.valid?('http://www.notavalidurl.com')).to be false
16
+ context 'using a valid URL with a server error' do
17
+ let(:url) { 'http://a-valid-url.com/error' }
18
+ before do
19
+ allow(HTTParty).to receive(:head).once.with(url).and_return(response)
20
+ allow(response).to receive(:code).once.and_return(500)
21
+ end
22
+ specify { expect(described_class.valid? url).to be false}
16
23
  end
17
24
 
18
- it "is an invalid URL - i.e. host is resolved but resource does not exist" do
19
- allow(response).to receive(:code).and_return(404)
20
- allow(HTTParty).to receive(:head).and_return(response)
21
- expect(subject.valid?('http://www.avalidurl.com/but/a/nonexistent/resource')).to be false
25
+ context 'using a valid URL with a missing resource' do
26
+ let(:url) { 'http://a-valid-url.com/missing.gif' }
27
+ before do
28
+ allow(HTTParty).to receive(:head).once.with(url).and_return(response)
29
+ allow(response).to receive(:code).once.and_return(404)
30
+ end
31
+ specify { expect(described_class.valid? url).to be false}
22
32
  end
23
33
 
24
- it "is an invalid host - i.e. no DNS resolution" do
25
- allow(response).to receive(:code).and_return(500)
26
- allow(HTTParty).to receive(:head).and_raise("Hostname not found")
27
- expect(subject.valid?('test://www.notavalidurl.test')).to be false
34
+ context 'using an invalid URL' do
35
+ let(:url) { 'http://an-invalid-url.com' }
36
+ before do
37
+ allow(HTTParty).to receive(:head).once.with(url).and_return(response)
38
+ allow(response).to receive(:code).once.and_return(500)
39
+ end
40
+ specify { expect(described_class.valid? url).to be false}
28
41
  end
29
42
  end
30
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alephant-scout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - C. Oliver Godby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-05 00:00:00.000000000 Z
11
+ date: 2014-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,48 @@ dependencies:
38
38
  version: '0'
39
39
  prerelease: false
40
40
  type: :development
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '3.1'
53
+ prerelease: false
54
+ type: :development
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-nc
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ prerelease: false
68
+ type: :development
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake-rspec
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ prerelease: false
82
+ type: :development
41
83
  - !ruby/object:Gem::Dependency
42
84
  name: httparty
43
85
  version_requirements: !ruby/object:Gem::Requirement
@@ -97,6 +139,8 @@ files:
97
139
  - lib/alephant/scout.rb
98
140
  - lib/alephant/scout/url.rb
99
141
  - lib/alephant/scout/version.rb
142
+ - spec/integration/spec_helper.rb
143
+ - spec/integration/url_spec.rb
100
144
  - spec/spec_helper.rb
101
145
  - spec/url_spec.rb
102
146
  homepage: ''
@@ -124,5 +168,7 @@ signing_key:
124
168
  specification_version: 4
125
169
  summary: '"Scout URLs to see if they are valid"'
126
170
  test_files:
171
+ - spec/integration/spec_helper.rb
172
+ - spec/integration/url_spec.rb
127
173
  - spec/spec_helper.rb
128
174
  - spec/url_spec.rb