unobtainium-nokogiri 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +28 -0
- data/.gitignore +39 -0
- data/.rubocop.yml +69 -0
- data/.travis.yml +8 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +70 -0
- data/LICENSE +30 -0
- data/README.md +22 -0
- data/Rakefile +25 -0
- data/lib/unobtainium-nokogiri/driver.rb +142 -0
- data/lib/unobtainium-nokogiri/unobtainium-nokogiri.rb +10 -0
- data/lib/unobtainium-nokogiri/version.rb +14 -0
- data/spec/data/foo.html +4 -0
- data/spec/driver_spec.rb +76 -0
- data/spec/spec_helper.rb +11 -0
- data/unobtainium-nokogiri.gemspec +53 -0
- metadata +180 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5796d7cfee2228a6a9d81331c5503a4f42909e7d
|
4
|
+
data.tar.gz: e2f50bec95dffef546ff86c6d58361405406adc0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e2e8dcc9c03f91caf20fac37491963b60ace477caece9830c31f28928eaf1eafd077a5855ec71682de7028a36523733044bd956d27445a9a70e75176994c0d37
|
7
|
+
data.tar.gz: 03554ca70bd4f6369a2772d1ffb0f87fa699d1655aa644e0d1538255a176b1aa98ab73380a13ad221ab6c27c42d1d1f389411742fc5c8e2c14594da84a81a3e4
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
---
|
2
|
+
engines:
|
3
|
+
bundler-audit:
|
4
|
+
enabled: true
|
5
|
+
duplication:
|
6
|
+
enabled: true
|
7
|
+
config:
|
8
|
+
languages:
|
9
|
+
- ruby
|
10
|
+
- javascript
|
11
|
+
- python
|
12
|
+
- php
|
13
|
+
fixme:
|
14
|
+
enabled: true
|
15
|
+
rubocop:
|
16
|
+
enabled: true
|
17
|
+
ratings:
|
18
|
+
paths:
|
19
|
+
- Gemfile.lock
|
20
|
+
- "**.inc"
|
21
|
+
- "**.js"
|
22
|
+
- "**.jsx"
|
23
|
+
- "**.module"
|
24
|
+
- "**.php"
|
25
|
+
- "**.py"
|
26
|
+
- "**.rb"
|
27
|
+
exclude_paths:
|
28
|
+
- spec/
|
data/.gitignore
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
## Specific to RubyMotion:
|
14
|
+
.dat*
|
15
|
+
.repl_history
|
16
|
+
build/
|
17
|
+
|
18
|
+
## Documentation cache and generated files:
|
19
|
+
/.yardoc/
|
20
|
+
/_yardoc/
|
21
|
+
/doc/
|
22
|
+
/rdoc/
|
23
|
+
|
24
|
+
## Environment normalization:
|
25
|
+
/.bundle/
|
26
|
+
/vendor/bundle
|
27
|
+
/lib/bundler/man/
|
28
|
+
|
29
|
+
# for a library or gem, you might want to ignore these files since the code is
|
30
|
+
# intended to run in multiple environments; otherwise, check them in:
|
31
|
+
# Gemfile.lock
|
32
|
+
# .ruby-version
|
33
|
+
# .ruby-gemset
|
34
|
+
|
35
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
36
|
+
.rvmrc
|
37
|
+
|
38
|
+
# Editor files
|
39
|
+
.*.sw*
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.2
|
3
|
+
|
4
|
+
# Metrics
|
5
|
+
|
6
|
+
Metrics/LineLength:
|
7
|
+
Max: 83
|
8
|
+
Details: >-
|
9
|
+
Line length of 80 is ideal for readability and compatibility; we'll accept
|
10
|
+
an extra 3 for minor edge cases.
|
11
|
+
|
12
|
+
Metrics/MethodLength:
|
13
|
+
Max: 35
|
14
|
+
|
15
|
+
Metrics/BlockNesting:
|
16
|
+
Max: 5
|
17
|
+
|
18
|
+
Metrics/AbcSize:
|
19
|
+
Max: 50
|
20
|
+
|
21
|
+
Metrics/PerceivedComplexity:
|
22
|
+
Max: 15
|
23
|
+
|
24
|
+
Metrics/CyclomaticComplexity:
|
25
|
+
Max: 15
|
26
|
+
|
27
|
+
Metrics/ClassLength:
|
28
|
+
Max: 300
|
29
|
+
|
30
|
+
# Style
|
31
|
+
|
32
|
+
Style/StringLiterals:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
Style/ConditionalAssignment:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
Style/EmptyLinesAroundModuleBody:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
Style/AndOr:
|
42
|
+
Enabled: false
|
43
|
+
|
44
|
+
Style/Not:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
Style/NegatedIf:
|
48
|
+
Enabled: false
|
49
|
+
|
50
|
+
Style/RedundantReturn:
|
51
|
+
Enabled: false
|
52
|
+
|
53
|
+
Style/IfUnlessModifier:
|
54
|
+
Enabled: false
|
55
|
+
|
56
|
+
Style/TrailingCommaInLiteral:
|
57
|
+
Enabled: false
|
58
|
+
|
59
|
+
Style/FirstParameterIndentation:
|
60
|
+
Enabled: false
|
61
|
+
|
62
|
+
Style/TrailingUnderscoreVariable:
|
63
|
+
Enabled: false
|
64
|
+
|
65
|
+
Style/NumericLiterals:
|
66
|
+
Enabled: false
|
67
|
+
|
68
|
+
Style/FileName:
|
69
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
unobtainium-nokogiri (0.1.0)
|
5
|
+
unobtainium (~> 0.3)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.2.0)
|
11
|
+
codeclimate-test-reporter (0.5.0)
|
12
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
13
|
+
diff-lcs (1.2.5)
|
14
|
+
docile (1.1.5)
|
15
|
+
json (1.8.3)
|
16
|
+
mini_portile2 (2.0.0)
|
17
|
+
nokogiri (1.6.7.2)
|
18
|
+
mini_portile2 (~> 2.0.0.rc2)
|
19
|
+
parser (2.3.1.0)
|
20
|
+
ast (~> 2.2)
|
21
|
+
powerpack (0.1.1)
|
22
|
+
rainbow (2.1.0)
|
23
|
+
rake (11.1.2)
|
24
|
+
rspec (3.4.0)
|
25
|
+
rspec-core (~> 3.4.0)
|
26
|
+
rspec-expectations (~> 3.4.0)
|
27
|
+
rspec-mocks (~> 3.4.0)
|
28
|
+
rspec-core (3.4.4)
|
29
|
+
rspec-support (~> 3.4.0)
|
30
|
+
rspec-expectations (3.4.0)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.4.0)
|
33
|
+
rspec-mocks (3.4.1)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.4.0)
|
36
|
+
rspec-support (3.4.1)
|
37
|
+
rubocop (0.39.0)
|
38
|
+
parser (>= 2.3.0.7, < 3.0)
|
39
|
+
powerpack (~> 0.1)
|
40
|
+
rainbow (>= 1.99.1, < 3.0)
|
41
|
+
ruby-progressbar (~> 1.7)
|
42
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
43
|
+
ruby-progressbar (1.8.0)
|
44
|
+
simplecov (0.11.2)
|
45
|
+
docile (~> 1.1.0)
|
46
|
+
json (~> 1.8)
|
47
|
+
simplecov-html (~> 0.10.0)
|
48
|
+
simplecov-html (0.10.0)
|
49
|
+
sys-proctable (1.0.0)
|
50
|
+
unicode-display_width (1.0.3)
|
51
|
+
unobtainium (0.3.0)
|
52
|
+
sys-proctable (~> 1.0)
|
53
|
+
yard (0.8.7.6)
|
54
|
+
|
55
|
+
PLATFORMS
|
56
|
+
ruby
|
57
|
+
|
58
|
+
DEPENDENCIES
|
59
|
+
bundler (~> 1.11)
|
60
|
+
codeclimate-test-reporter
|
61
|
+
nokogiri
|
62
|
+
rake (~> 11.1)
|
63
|
+
rspec (~> 3.4)
|
64
|
+
rubocop (~> 0.39)
|
65
|
+
simplecov (~> 0.11)
|
66
|
+
unobtainium-nokogiri!
|
67
|
+
yard (~> 0.8)
|
68
|
+
|
69
|
+
BUNDLED WITH
|
70
|
+
1.11.2
|
data/LICENSE
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
Copyright (c) Jens Finkhaeuser (http://finkhaeuser.de/) and other unobtainum
|
2
|
+
contributors. All rights not covered below are reserved.
|
3
|
+
|
4
|
+
The MIT +no-false-attribs License (MITNFA)
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
of this software and associated documentation files (the "Software"), to
|
8
|
+
deal in the Software without restriction, including without limitation the
|
9
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
10
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
11
|
+
furnished to do so, subject to the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
14
|
+
all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
Distributions of all or part of the Software intended to be used by the
|
17
|
+
recipients as they would use the unmodified Software, containing modifications
|
18
|
+
that substantially alter, remove, or disable functionality of the Software,
|
19
|
+
outside of the documented configuration mechanisms provided by the Software,
|
20
|
+
shall be modified such that the Original Author's bug reporting email addresses
|
21
|
+
and urls are either replaced with the contact information of the parties
|
22
|
+
responsible for the changes, or removed entirely.
|
23
|
+
|
24
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
25
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
26
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
27
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
28
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
29
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
30
|
+
IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# unobtainium-nokogiri
|
2
|
+
|
3
|
+
This gem provides a driver implementation for [unobtainium](https://github.com/jfinkhaeuser/unobtainium)
|
4
|
+
based on [nokogiri](http://www.nokogiri.org/).
|
5
|
+
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/unobtainium-nokogiri.svg)](https://badge.fury.io/rb/unobtainium-nokogiri)
|
7
|
+
[![Build status](https://travis-ci.org/jfinkhaeuser/unobtainium-nokogiri.svg?branch=master)](https://travis-ci.org/jfinkhaeuser/unobtainium-nokogiri)
|
8
|
+
[![Code Climate](https://codeclimate.com/github/jfinkhaeuser/unobtainium-nokogiri/badges/gpa.svg)](https://codeclimate.com/github/jfinkhaeuser/unobtainium-nokogiri)
|
9
|
+
[![Test Coverage](https://codeclimate.com/github/jfinkhaeuser/unobtainium-nokogiri/badges/coverage.svg)](https://codeclimate.com/github/jfinkhaeuser/unobtainium-nokogiri/coverage)
|
10
|
+
|
11
|
+
To use it, require it after requiring unobtainium, then create the appropriate driver:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
require 'unobtainium'
|
15
|
+
require 'unobtainium-nokogiri'
|
16
|
+
|
17
|
+
include Unobtainium::World
|
18
|
+
|
19
|
+
drv = driver(:nokogiri)
|
20
|
+
|
21
|
+
# do something with the driver
|
22
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Rubocop
|
2
|
+
require 'rubocop/rake_task'
|
3
|
+
RuboCop::RakeTask.new(:rubocop)
|
4
|
+
|
5
|
+
# Rspec
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
RSpec::Core::RakeTask.new(:rspec)
|
8
|
+
|
9
|
+
# Documentation
|
10
|
+
require 'yard'
|
11
|
+
YARD::Rake::YardocTask.new do |t|
|
12
|
+
t.files = ['lib/**/*.rb']
|
13
|
+
t.options = ['-m', 'markdown']
|
14
|
+
t.stats_options = ['--list-undoc']
|
15
|
+
end
|
16
|
+
|
17
|
+
# Combined test task
|
18
|
+
desc "Test all the things!"
|
19
|
+
task :test do
|
20
|
+
Rake::Task[:rubocop].invoke
|
21
|
+
Rake::Task[:rspec].invoke
|
22
|
+
end
|
23
|
+
|
24
|
+
# Default is the test task
|
25
|
+
task default: :test
|
@@ -0,0 +1,142 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
#
|
3
|
+
# unobtainium-nokogiri
|
4
|
+
# https://github.com/jfinkhaeuser/unobtainium-nokogiri
|
5
|
+
#
|
6
|
+
# Copyright (c) 2016 Jens Finkhaeuser and other unobtainium-nokogiri contributors.
|
7
|
+
# All rights reserved.
|
8
|
+
#
|
9
|
+
|
10
|
+
require 'unobtainium'
|
11
|
+
|
12
|
+
module Unobtainium
|
13
|
+
module Nokogiri
|
14
|
+
|
15
|
+
##
|
16
|
+
# TODO
|
17
|
+
class Driver
|
18
|
+
class << self
|
19
|
+
##
|
20
|
+
# Return true if the given label matches this driver implementation,
|
21
|
+
# false otherwise.
|
22
|
+
def matches?(label)
|
23
|
+
return :nokogiri == label.to_sym
|
24
|
+
end
|
25
|
+
|
26
|
+
##
|
27
|
+
# Ensure that the driver's preconditions are fulfilled.
|
28
|
+
def ensure_preconditions(_, _)
|
29
|
+
require 'nokogiri'
|
30
|
+
require 'open-uri'
|
31
|
+
rescue LoadError => err
|
32
|
+
raise LoadError, "#{err.message}: you need to add "\
|
33
|
+
"'nokogiri' to your Gemfile to use this driver!",
|
34
|
+
err.backtrace
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# Create and return a driver instance
|
39
|
+
def create(_, _)
|
40
|
+
driver = ::Unobtainium::Nokogiri::Driver.new
|
41
|
+
return driver
|
42
|
+
end
|
43
|
+
end # class << self
|
44
|
+
|
45
|
+
##
|
46
|
+
# "Go to" the given URI, i.e. open it and retain contents.
|
47
|
+
def goto(uri)
|
48
|
+
reset
|
49
|
+
|
50
|
+
# Fetch content
|
51
|
+
open(uri) do |f|
|
52
|
+
@meta[:uri] = uri.dup
|
53
|
+
if f.respond_to?(:meta)
|
54
|
+
@meta[:headers] = f.meta.dup
|
55
|
+
@meta[:status] = f.status.dup
|
56
|
+
@meta[:base_uri] = f.base_uri.dup
|
57
|
+
end
|
58
|
+
|
59
|
+
if f.respond_to?(:metas)
|
60
|
+
@meta[:split_headers] = f.metas.dup
|
61
|
+
end
|
62
|
+
|
63
|
+
@content = f.read
|
64
|
+
end
|
65
|
+
|
66
|
+
# Pass content to Nokigiri
|
67
|
+
@parsed = ::Nokogiri.send(@parse_method, @content) do |config|
|
68
|
+
config.options = @options
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
##
|
73
|
+
# @return (String) The raw page content, or nil
|
74
|
+
attr_reader :content
|
75
|
+
|
76
|
+
##
|
77
|
+
# @return (Hash) Any page metadata, or an empty Hash
|
78
|
+
attr_reader :meta
|
79
|
+
|
80
|
+
##
|
81
|
+
# @return (::Nokogiri::XML::ParseOptions) parser options for all subsequent
|
82
|
+
# requests.
|
83
|
+
attr_accessor :options
|
84
|
+
|
85
|
+
##
|
86
|
+
# Set one of :XML or :HTML, deciding which parsing method nokogiri is to
|
87
|
+
# use.
|
88
|
+
def parse_method=(method)
|
89
|
+
if not [:XML, :HTML].include?(method)
|
90
|
+
raise ArgumentError, "parse_method must be one of :XML, :HTML!"
|
91
|
+
end
|
92
|
+
@parse_method = method
|
93
|
+
end
|
94
|
+
|
95
|
+
##
|
96
|
+
# @return (Symbol) one of :HTML, :XML
|
97
|
+
attr_reader :parse_method
|
98
|
+
|
99
|
+
##
|
100
|
+
# Map any missing method to nokogiri
|
101
|
+
def respond_to?(meth)
|
102
|
+
if not @parsed.nil? and @parsed.respond_to?(meth)
|
103
|
+
return true
|
104
|
+
end
|
105
|
+
return super
|
106
|
+
end
|
107
|
+
|
108
|
+
##
|
109
|
+
# Map any missing method to nokogiri
|
110
|
+
def method_missing(meth, *args, &block)
|
111
|
+
if not @parsed.nil? and @parsed.respond_to?(meth)
|
112
|
+
return @parsed.send(meth.to_s, *args, &block)
|
113
|
+
end
|
114
|
+
return super
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
##
|
120
|
+
# Private initialize to force use of Driver#create.
|
121
|
+
def initialize
|
122
|
+
reset
|
123
|
+
|
124
|
+
@parse_method = :HTML
|
125
|
+
@options = ::Nokogiri::XML::ParseOptions::DEFAULT_HTML
|
126
|
+
end
|
127
|
+
|
128
|
+
##
|
129
|
+
# Clear all data
|
130
|
+
def reset
|
131
|
+
@content = nil
|
132
|
+
@meta = {}
|
133
|
+
@parsed = nil
|
134
|
+
end
|
135
|
+
end # class Driver
|
136
|
+
|
137
|
+
end # module Nokogiri
|
138
|
+
end # module Unobtainium
|
139
|
+
|
140
|
+
::Unobtainium::Driver.register_implementation(
|
141
|
+
::Unobtainium::Nokogiri::Driver,
|
142
|
+
__FILE__)
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
#
|
3
|
+
# unobtainium-nokogiri
|
4
|
+
# https://github.com/jfinkhaeuser/unobtainium-nokogiri
|
5
|
+
#
|
6
|
+
# Copyright (c) 2016 Jens Finkhaeuser and other unobtainium-nokogiri contributors.
|
7
|
+
# All rights reserved.
|
8
|
+
#
|
9
|
+
|
10
|
+
require 'unobtainium-nokogiri/driver'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
#
|
3
|
+
# unobtainium-nokogiri
|
4
|
+
# https://github.com/jfinkhaeuser/unobtainium-nokogiri
|
5
|
+
#
|
6
|
+
# Copyright (c) 2016 Jens Finkhaeuser and other unobtainium-nokogiri contributors.
|
7
|
+
# All rights reserved.
|
8
|
+
#
|
9
|
+
module Unobtainium
|
10
|
+
module Nokogiri
|
11
|
+
# The current release version
|
12
|
+
VERSION = "0.1.0".freeze
|
13
|
+
end # module Nokogiri
|
14
|
+
end # module Unobtainium
|
data/spec/data/foo.html
ADDED
data/spec/driver_spec.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
#
|
3
|
+
# unobtainium-nokogiri
|
4
|
+
# https://github.com/jfinkhaeuser/unobtainium-nokogiri
|
5
|
+
#
|
6
|
+
# Copyright (c) 2016 Jens Finkhaeuser and other unobtainium-nokogiri contributors.
|
7
|
+
# All rights reserved.
|
8
|
+
#
|
9
|
+
require 'spec_helper'
|
10
|
+
|
11
|
+
describe 'Unobtainium::Nokogiri::Driver' do
|
12
|
+
it "passes unobtainium's interface checks" do
|
13
|
+
expect do
|
14
|
+
require_relative '../lib/unobtainium-nokogiri/driver'
|
15
|
+
end.to_not raise_error(LoadError)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "can be created" do
|
19
|
+
expect do
|
20
|
+
::Unobtainium::Driver.create(:nokogiri)
|
21
|
+
end.to_not raise_error
|
22
|
+
|
23
|
+
drv = ::Unobtainium::Driver.create(:nokogiri)
|
24
|
+
expect(drv).to_not be_nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "opens a file" do
|
28
|
+
drv = ::Unobtainium::Driver.create(:nokogiri)
|
29
|
+
|
30
|
+
test_uri = "spec/data/foo.html"
|
31
|
+
expect { drv.goto(test_uri) }.to_not raise_error
|
32
|
+
expect(drv.meta[:uri]).to eql test_uri
|
33
|
+
end
|
34
|
+
|
35
|
+
it "opens a web page" do
|
36
|
+
drv = ::Unobtainium::Driver.create(:nokogiri)
|
37
|
+
|
38
|
+
test_uri = "http://finkhaeuser.de"
|
39
|
+
expect { drv.goto(test_uri) }.to_not raise_error
|
40
|
+
expect(drv.meta[:uri]).to eql test_uri
|
41
|
+
|
42
|
+
expect(drv.meta[:headers]).not_to be_nil
|
43
|
+
expect(drv.meta[:headers]).not_to be_empty
|
44
|
+
end
|
45
|
+
|
46
|
+
it "delegates to nokogiri" do
|
47
|
+
drv = ::Unobtainium::Driver.create(:nokogiri)
|
48
|
+
|
49
|
+
test_uri = "spec/data/foo.html"
|
50
|
+
expect { drv.goto(test_uri) }.to_not raise_error
|
51
|
+
|
52
|
+
expect(drv.xpath('//foo')).not_to be_nil
|
53
|
+
expect(drv.xpath('//foo')).not_to be_empty
|
54
|
+
end
|
55
|
+
|
56
|
+
it "rejects the wrong parse method" do
|
57
|
+
drv = ::Unobtainium::Driver.create(:nokogiri)
|
58
|
+
|
59
|
+
expect { drv.parse_method = :HTML }.not_to raise_error(ArgumentError)
|
60
|
+
expect { drv.parse_method = :XML }.not_to raise_error(ArgumentError)
|
61
|
+
|
62
|
+
expect { drv.parse_method = :foo }.to raise_error(ArgumentError)
|
63
|
+
expect { drv.parse_method = 'XML' }.to raise_error(ArgumentError)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "accepts and interprets configuration" do
|
67
|
+
drv = ::Unobtainium::Driver.create(:nokogiri)
|
68
|
+
|
69
|
+
drv.parse_method = :XML
|
70
|
+
drv.options = ::Nokogiri::XML::ParseOptions::STRICT | \
|
71
|
+
::Nokogiri::XML::ParseOptions::PEDANTIC
|
72
|
+
|
73
|
+
test_uri = "spec/data/foo.html"
|
74
|
+
expect { drv.goto(test_uri) }.to raise_error(Nokogiri::XML::SyntaxError)
|
75
|
+
end
|
76
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# Only start CodeClimate from travis
|
2
|
+
if ENV['CODECLIMATE_REPO_TOKEN']
|
3
|
+
require 'codeclimate-test-reporter'
|
4
|
+
CodeClimate::TestReporter.start
|
5
|
+
end
|
6
|
+
|
7
|
+
# Always start SimpleCov
|
8
|
+
require 'simplecov'
|
9
|
+
SimpleCov.start do
|
10
|
+
# add_filter 'unobtainium/drivers'
|
11
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
#
|
3
|
+
# unobtainium-nokogiri
|
4
|
+
# https://github.com/jfinkhaeuser/unobtainium-nokogiri
|
5
|
+
#
|
6
|
+
# Copyright (c) 2016 Jens Finkhaeuser and other unobtainium-nokogiri contributors.
|
7
|
+
# All rights reserved.
|
8
|
+
#
|
9
|
+
|
10
|
+
lib = File.expand_path('../lib', __FILE__)
|
11
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
12
|
+
require 'unobtainium-nokogiri/version'
|
13
|
+
|
14
|
+
# rubocop:disable Style/UnneededPercentQ, Style/ExtraSpacing
|
15
|
+
# rubocop:disable Style/SpaceAroundOperators
|
16
|
+
Gem::Specification.new do |spec|
|
17
|
+
spec.name = "unobtainium-nokogiri"
|
18
|
+
spec.version = Unobtainium::Nokogiri::VERSION
|
19
|
+
spec.authors = ["Jens Finkhaeuser"]
|
20
|
+
spec.email = ["jens@finkhaeuser.de"]
|
21
|
+
spec.description = %q(
|
22
|
+
The unobtainium-nokogiri gem is a nokogiri-based driver implementation for
|
23
|
+
unobtainium.
|
24
|
+
|
25
|
+
Unlike built-in driver implementations, it does not provide a Selenium-like
|
26
|
+
API, but rather one mostly identical to plain nokogiri.
|
27
|
+
)
|
28
|
+
spec.summary = %q(
|
29
|
+
The unobtainium-nokogiri gem is a nokogiri-based driver implementation for
|
30
|
+
unobtainium.
|
31
|
+
)
|
32
|
+
spec.homepage = "https://github.com/jfinkhaeuser/unobtainium-nokogiri"
|
33
|
+
spec.license = "MITNFA"
|
34
|
+
|
35
|
+
spec.files = `git ls-files -z`.split("\x0")
|
36
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
37
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
38
|
+
spec.require_paths = ["lib"]
|
39
|
+
|
40
|
+
spec.required_ruby_version = '>= 2.0'
|
41
|
+
|
42
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
43
|
+
spec.add_development_dependency "rubocop", "~> 0.39"
|
44
|
+
spec.add_development_dependency "rake", "~> 11.1"
|
45
|
+
spec.add_development_dependency "rspec", "~> 3.4"
|
46
|
+
spec.add_development_dependency "simplecov", "~> 0.11"
|
47
|
+
spec.add_development_dependency "yard", "~> 0.8"
|
48
|
+
spec.add_development_dependency "nokogiri"
|
49
|
+
|
50
|
+
spec.add_dependency "unobtainium", "~> 0.3"
|
51
|
+
end
|
52
|
+
# rubocop:enable Style/SpaceAroundOperators
|
53
|
+
# rubocop:enable Style/UnneededPercentQ, Style/ExtraSpacing
|
metadata
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: unobtainium-nokogiri
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jens Finkhaeuser
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.39'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.39'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '11.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '11.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.11'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.11'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: yard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.8'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.8'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: nokogiri
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: unobtainium
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.3'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.3'
|
125
|
+
description: "\n The unobtainium-nokogiri gem is a nokogiri-based driver implementation
|
126
|
+
for\n unobtainium.\n\n Unlike built-in driver implementations, it does not
|
127
|
+
provide a Selenium-like\n API, but rather one mostly identical to plain nokogiri.\n
|
128
|
+
\ "
|
129
|
+
email:
|
130
|
+
- jens@finkhaeuser.de
|
131
|
+
executables: []
|
132
|
+
extensions: []
|
133
|
+
extra_rdoc_files: []
|
134
|
+
files:
|
135
|
+
- ".codeclimate.yml"
|
136
|
+
- ".gitignore"
|
137
|
+
- ".rubocop.yml"
|
138
|
+
- ".travis.yml"
|
139
|
+
- Gemfile
|
140
|
+
- Gemfile.lock
|
141
|
+
- LICENSE
|
142
|
+
- README.md
|
143
|
+
- Rakefile
|
144
|
+
- lib/unobtainium-nokogiri/driver.rb
|
145
|
+
- lib/unobtainium-nokogiri/unobtainium-nokogiri.rb
|
146
|
+
- lib/unobtainium-nokogiri/version.rb
|
147
|
+
- spec/data/foo.html
|
148
|
+
- spec/driver_spec.rb
|
149
|
+
- spec/spec_helper.rb
|
150
|
+
- unobtainium-nokogiri.gemspec
|
151
|
+
homepage: https://github.com/jfinkhaeuser/unobtainium-nokogiri
|
152
|
+
licenses:
|
153
|
+
- MITNFA
|
154
|
+
metadata: {}
|
155
|
+
post_install_message:
|
156
|
+
rdoc_options: []
|
157
|
+
require_paths:
|
158
|
+
- lib
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '2.0'
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
requirements: []
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 2.4.5.1
|
172
|
+
signing_key:
|
173
|
+
specification_version: 4
|
174
|
+
summary: The unobtainium-nokogiri gem is a nokogiri-based driver implementation for
|
175
|
+
unobtainium.
|
176
|
+
test_files:
|
177
|
+
- spec/data/foo.html
|
178
|
+
- spec/driver_spec.rb
|
179
|
+
- spec/spec_helper.rb
|
180
|
+
has_rdoc:
|