assert-url 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cbc3fcdf6ef6d4249a7acc90d7a50400daa6e653
4
+ data.tar.gz: 5c6d6af45be495d1608664f39e3d31a59343053a
5
+ SHA512:
6
+ metadata.gz: 93a675818fed1f17a8905e770e879e8cf1ff2f481f17a64770b1e6f0338df85a46a8da1e37695b7f02b296a5ea125905d58964b61d4842131c6887066e80fabb
7
+ data.tar.gz: ab51556324b3ef568297afb10ec4263ed01320d1f3dad068b9202780413cfd19f322a7161496eec5e72900a3a4f966099f3a73a400954c0b84b6e356c3abc00c
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Lucas Tolchinsky
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ assert-url
2
+ ==========
3
+
4
+ Semantical helpers to test your URLs in Ruby
@@ -0,0 +1,14 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "assert-url"
3
+ s.version = "0.0.1"
4
+ s.summary = "Semantical helpers to test your URLs in Ruby"
5
+ s.description = s.summary
6
+ s.authors = ["Lucas Tolchinsky"]
7
+ s.email = ["lucas.tolchinsky@gmail.com"]
8
+ s.homepage = "https://github.com/tonchis/assert-url"
9
+ s.license = "MIT"
10
+
11
+ s.files = `git ls-files`.split("\n")
12
+
13
+ s.add_development_dependency "cutest"
14
+ end
data/lib/assert_url.rb ADDED
@@ -0,0 +1,29 @@
1
+ require "uri"
2
+
3
+ module AssertUrl
4
+ PARTS = %W[scheme host port path query]
5
+
6
+ PARTS.each do |part|
7
+ error = const_set("#{part.capitalize}Error", Class.new(StandardError))
8
+
9
+ define_method(:"assert_#{part}") do |expected, value|
10
+ expected, value = urify(expected, value).map(&:"#{part}")
11
+
12
+ expected == value || (raise error, "expected #{expected}, got #{value}")
13
+ end
14
+ end
15
+
16
+ alias assert_hostname assert_host
17
+
18
+ def assert_url(expected, value)
19
+ expected, value = urify(expected, value)
20
+
21
+ PARTS.map { |part| send(:"assert_#{part}", expected, value) }.reduce(:&)
22
+ end
23
+
24
+ def urify(*args)
25
+ args.each_with_object([]) { |arg, accum| accum << (arg.kind_of?(URI) ? arg : URI(arg)) }
26
+ end
27
+ private :urify
28
+ end
29
+
@@ -0,0 +1,58 @@
1
+ require "cutest"
2
+ require "uri"
3
+ require_relative "../lib/assert_url"
4
+
5
+ include AssertUrl
6
+
7
+ setup do
8
+ "http://sub.example.org:8080/path/to/resource?foo=bar"
9
+ end
10
+
11
+ test "assert_url" do |url|
12
+ assert assert_url(url, url)
13
+
14
+ assert_raise do
15
+ assert_scheme("https://example.org", url)
16
+ end
17
+ end
18
+
19
+ test "assert_scheme" do |url|
20
+ assert assert_scheme("http://example.org", url)
21
+
22
+ assert_raise(AssertUrl::SchemeError) do
23
+ assert_scheme("ftp://example.org", url)
24
+ end
25
+ end
26
+
27
+ test "assert_host" do |url|
28
+ assert assert_host("https://sub.example.org", url)
29
+
30
+ assert_raise(AssertUrl::HostError) do
31
+ assert_host("http://example.org", url)
32
+ end
33
+ end
34
+
35
+ test "assert_port" do |url|
36
+ assert assert_port("http://place.org:8080", url)
37
+
38
+ assert_raise(AssertUrl::PortError) do
39
+ assert_port("ftp://example.org", url)
40
+ end
41
+ end
42
+
43
+ test "assert_path" do |url|
44
+ assert assert_path("http://wat.org/path/to/resource", url)
45
+
46
+ assert_raise(AssertUrl::PathError) do
47
+ assert_path("ftp://example.org", url)
48
+ end
49
+ end
50
+
51
+ test "assert_query" do |url|
52
+ assert assert_query("http://foo.bar/q?foo=bar", url)
53
+
54
+ assert_raise(AssertUrl::QueryError) do
55
+ assert_query("ftp://example.org", url)
56
+ end
57
+ end
58
+
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: assert-url
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Lucas Tolchinsky
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cutest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Semantical helpers to test your URLs in Ruby
28
+ email:
29
+ - lucas.tolchinsky@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE
35
+ - README.md
36
+ - assert_url.gemspec
37
+ - lib/assert_url.rb
38
+ - test/assert_url_test.rb
39
+ homepage: https://github.com/tonchis/assert-url
40
+ licenses:
41
+ - MIT
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.2.0
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Semantical helpers to test your URLs in Ruby
63
+ test_files: []