saper 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +2 -0
- data/lib/lib/nokogiri.rb +2 -0
- data/lib/saper/actions/append_with.rb +1 -1
- data/lib/saper/core/action.rb +3 -1
- data/lib/saper/core/browser.rb +27 -8
- data/lib/saper/core/dsl.rb +6 -1
- data/lib/saper/core/item.rb +5 -0
- data/lib/saper/core/namespace.rb +11 -3
- data/lib/saper/core/runtime.rb +1 -1
- data/lib/saper/items/atom.rb +4 -16
- data/lib/saper/items/document.rb +4 -0
- data/lib/saper/items/html.rb +0 -4
- data/lib/saper/items/json.rb +16 -22
- data/lib/saper/items/time.rb +2 -2
- data/lib/saper/items/url.rb +8 -6
- data/lib/saper/items/xml.rb +0 -4
- data/lib/saper/version.rb +1 -1
- data/spec/actions/append_with_spec.rb +41 -11
- data/spec/actions/convert_to_html_spec.rb +24 -9
- data/spec/actions/convert_to_json_spec.rb +24 -9
- data/spec/actions/convert_to_markdown_spec.rb +12 -9
- data/spec/actions/convert_to_time_spec.rb +31 -16
- data/spec/actions/convert_to_xml_spec.rb +1 -7
- data/spec/actions/create_atom_spec.rb +8 -12
- data/spec/actions/fetch_spec.rb +9 -1
- data/spec/actions/find_first_spec.rb +46 -1
- data/spec/actions/find_spec.rb +45 -1
- data/spec/actions/prepend_with_spec.rb +0 -6
- data/spec/items/document_spec.rb +19 -1
- data/spec/items/html_spec.rb +35 -1
- data/spec/items/json_spec.rb +11 -1
- data/spec/items/text_spec.rb +29 -1
- data/spec/items/url_spec.rb +7 -1
- data/spec/items/xml_spec.rb +28 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e3837b908a7c2e26f770d28ba24bc8e5ceb5beb
|
4
|
+
data.tar.gz: 1a442deae6a10374bab445b695f1d83597ce37f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55844e966392ebd596d8a62ace3a9fc70831ea7b60ebfb2df81fc7ddbaad2aacac9c431adc5ff4dbd504fbe7b951670780c2778395473111adbbda2ca9c3e3d5
|
7
|
+
data.tar.gz: 3da6224447204cd0784d7abcc4806a68aa086ea89fe23401cde51eb3d5968b8b83a307be80ffcd4506979791b6c22f01cf99e1dc704a71c4b86c9e9c7623d884
|
data/Rakefile
CHANGED
data/lib/lib/nokogiri.rb
CHANGED
data/lib/saper/core/action.rb
CHANGED
@@ -201,9 +201,11 @@ module Saper
|
|
201
201
|
self.class.run || Proc.new { |input, *args| input }
|
202
202
|
end
|
203
203
|
|
204
|
+
# Returns string representation of Action.
|
205
|
+
# @return [String]
|
204
206
|
def to_string
|
205
207
|
"\t%s %s" % [self.class.type, @arguments.map(&:to_string).join(", ")]
|
206
208
|
end
|
207
209
|
|
208
210
|
end
|
209
|
-
end
|
211
|
+
end
|
data/lib/saper/core/browser.rb
CHANGED
@@ -1,10 +1,20 @@
|
|
1
1
|
module Saper
|
2
2
|
class Browser
|
3
3
|
|
4
|
-
|
4
|
+
# Array of requested URLs.
|
5
|
+
attr_reader :history
|
5
6
|
|
6
|
-
|
7
|
+
# Approximate number of bytes received.
|
8
|
+
attr_reader :received
|
7
9
|
|
10
|
+
# Approximate number of bytes sent.
|
11
|
+
attr_reader :sent
|
12
|
+
|
13
|
+
# Returns a new Browser instance.
|
14
|
+
# @option options [Symbol] :agent User agent
|
15
|
+
# @option options [Hash] :headers Additional request headers
|
16
|
+
# @option options [Logger] :logger Logger instance
|
17
|
+
# @return [Saper::Browser]
|
8
18
|
def initialize(options = {})
|
9
19
|
@agent = options.delete(:agent)
|
10
20
|
@headers = options.delete(:headers)
|
@@ -31,17 +41,22 @@ module Saper
|
|
31
41
|
end
|
32
42
|
end
|
33
43
|
|
34
|
-
# Returns number of HTTP requests
|
44
|
+
# Returns the number of HTTP requests.
|
45
|
+
# @return [Integer]
|
35
46
|
def requests
|
36
47
|
@history.size
|
37
48
|
end
|
38
49
|
|
39
|
-
#
|
50
|
+
# Returns additional request headers.
|
51
|
+
# @return [Hash]
|
40
52
|
def headers
|
41
53
|
@headers.respond_to?(:to_hash) ? @headers : {}
|
42
54
|
end
|
43
55
|
|
44
|
-
#
|
56
|
+
# Performs a GET request and returns Saper::Document.
|
57
|
+
# @param url [String] URL to request
|
58
|
+
# @param query [Hash] query options
|
59
|
+
# @return [Saper::Document]
|
45
60
|
def get(url, query = {})
|
46
61
|
@logger.download(url)
|
47
62
|
@history.push url
|
@@ -49,7 +64,10 @@ module Saper
|
|
49
64
|
Saper::Items::Document.new data
|
50
65
|
end
|
51
66
|
|
52
|
-
#
|
67
|
+
# Performs a POST request and returns Saper::Document.
|
68
|
+
# @param url [String] URL to request
|
69
|
+
# @param query [Hash] payload
|
70
|
+
# @return [Saper::Document]
|
53
71
|
def post(url, query = {})
|
54
72
|
@logger.download(url)
|
55
73
|
@history.push url
|
@@ -57,7 +75,8 @@ module Saper
|
|
57
75
|
Saper::Items::Document.new data
|
58
76
|
end
|
59
77
|
|
60
|
-
#
|
78
|
+
# Returns User-Agent string used with requests.
|
79
|
+
# @return [String]
|
61
80
|
def agent
|
62
81
|
case @agent
|
63
82
|
when :ie6
|
@@ -84,4 +103,4 @@ module Saper
|
|
84
103
|
end
|
85
104
|
|
86
105
|
end
|
87
|
-
end
|
106
|
+
end
|
data/lib/saper/core/dsl.rb
CHANGED
@@ -1,14 +1,19 @@
|
|
1
1
|
module Saper
|
2
2
|
module DSL
|
3
3
|
|
4
|
+
# Returns a new empty module with embedded parsing methods.
|
5
|
+
# @return [Object]
|
4
6
|
def self.new
|
5
7
|
Module.new.extend(Methods)
|
6
8
|
end
|
7
9
|
|
10
|
+
# Enables recipe parsing in modules that include Saper::DSL.
|
11
|
+
# @return [void]
|
8
12
|
def self.included(base)
|
9
13
|
base.extend(Methods)
|
10
14
|
end
|
11
15
|
|
16
|
+
# A mixin module with a set of parsing methods
|
12
17
|
module Methods
|
13
18
|
|
14
19
|
def namespace
|
@@ -65,4 +70,4 @@ module Saper
|
|
65
70
|
|
66
71
|
end
|
67
72
|
end
|
68
|
-
end
|
73
|
+
end
|
data/lib/saper/core/item.rb
CHANGED
data/lib/saper/core/namespace.rb
CHANGED
@@ -1,11 +1,19 @@
|
|
1
1
|
module Saper
|
2
2
|
|
3
|
-
|
3
|
+
# Runs a recipe saved in a file.
|
4
|
+
# @param file [String] file name
|
5
|
+
# @param recipe [Symbol] recipe name
|
6
|
+
# @param input [Object] input for recipe
|
7
|
+
# @return [Saper::Runtime]
|
8
|
+
def self.run(file, recipe, input = nil)
|
4
9
|
load(file).run(recipe, input)
|
5
10
|
end
|
6
11
|
|
7
|
-
|
8
|
-
|
12
|
+
# Parses recipes saved in a file.
|
13
|
+
# @param file [String] file name
|
14
|
+
# @return [Saper::Namespace]
|
15
|
+
def self.load(file)
|
16
|
+
Namespace.parse File.read(path)
|
9
17
|
end
|
10
18
|
|
11
19
|
# Namespace is a parsing / storage utility for recipes
|
data/lib/saper/core/runtime.rb
CHANGED
@@ -175,7 +175,7 @@ module Saper
|
|
175
175
|
# Returns runtime results as JSON.
|
176
176
|
# @return [Array]
|
177
177
|
def to_json(*args)
|
178
|
-
JSON.generate(
|
178
|
+
JSON.generate non_native_results.map(&:serialize)
|
179
179
|
end
|
180
180
|
|
181
181
|
# Returns runtime results as Saper::Item instances.
|
data/lib/saper/items/atom.rb
CHANGED
@@ -15,24 +15,16 @@ module Saper
|
|
15
15
|
@atts = hash
|
16
16
|
end
|
17
17
|
|
18
|
-
def serialize
|
19
|
-
@atts.dup
|
20
|
-
end
|
21
|
-
|
22
18
|
def to_hash
|
23
19
|
@atts.dup
|
24
20
|
end
|
25
21
|
|
26
|
-
def delete(name)
|
27
|
-
@atts.delete(name)
|
28
|
-
end
|
29
|
-
|
30
22
|
def [](name)
|
31
23
|
@atts[name]
|
32
24
|
end
|
33
25
|
|
34
|
-
def
|
35
|
-
@atts.
|
26
|
+
def serialize
|
27
|
+
@atts.dup
|
36
28
|
end
|
37
29
|
|
38
30
|
def to_native(object = nil)
|
@@ -51,12 +43,8 @@ module Saper
|
|
51
43
|
object
|
52
44
|
end
|
53
45
|
|
54
|
-
def to_json
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
def to_s
|
59
|
-
"{ %s }" % @atts.map { |key, value| "%s = %s" % [key, value] }.join(", ")
|
46
|
+
def to_json
|
47
|
+
JSON.new(@hash, true)
|
60
48
|
end
|
61
49
|
|
62
50
|
end
|
data/lib/saper/items/document.rb
CHANGED
data/lib/saper/items/html.rb
CHANGED
data/lib/saper/items/json.rb
CHANGED
@@ -2,12 +2,14 @@ module Saper
|
|
2
2
|
module Items
|
3
3
|
class JSON < Item
|
4
4
|
|
5
|
-
def self.new(item)
|
5
|
+
def self.new(item, bypass = false)
|
6
6
|
super case item
|
7
7
|
when Text
|
8
8
|
parse(item.to_s)
|
9
9
|
when String
|
10
10
|
parse(item)
|
11
|
+
when Hash
|
12
|
+
bypass ? item : raise(InvalidItem, item)
|
11
13
|
else
|
12
14
|
raise(InvalidItem, item)
|
13
15
|
end
|
@@ -25,43 +27,35 @@ module Saper
|
|
25
27
|
@hash = hash
|
26
28
|
end
|
27
29
|
|
28
|
-
def [](name)
|
29
|
-
value = @hash[name.to_s]
|
30
|
-
case value
|
31
|
-
when Hash
|
32
|
-
self.class.new(value)
|
33
|
-
when Array
|
34
|
-
self.class.new(value)
|
35
|
-
else
|
36
|
-
value
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
30
|
def find(xpath)
|
41
31
|
find_all(xpath).first
|
42
32
|
end
|
43
33
|
|
44
34
|
def find_all(xpath)
|
45
|
-
JSONSearch.find(@hash, xpath)
|
46
|
-
|
47
|
-
|
35
|
+
sanitize JSONSearch.find(@hash, xpath)
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_s
|
39
|
+
::JSON.dump(@hash)
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_native
|
43
|
+
to_s
|
48
44
|
end
|
49
45
|
|
46
|
+
private
|
47
|
+
|
50
48
|
def sanitize(item)
|
51
49
|
case item
|
52
50
|
when Hash
|
53
|
-
self.class.new(item)
|
51
|
+
self.class.new(item, true)
|
54
52
|
when Array
|
55
53
|
item.map { |i| sanitize(i) }
|
56
54
|
else
|
57
|
-
item
|
55
|
+
Text.new(item.to_s)
|
58
56
|
end
|
59
57
|
end
|
60
58
|
|
61
|
-
def to_native
|
62
|
-
@hash
|
63
|
-
end
|
64
|
-
|
65
59
|
end
|
66
60
|
end
|
67
61
|
end
|
data/lib/saper/items/time.rb
CHANGED
data/lib/saper/items/url.rb
CHANGED
@@ -3,18 +3,20 @@ module Saper
|
|
3
3
|
class URL < Item
|
4
4
|
|
5
5
|
def self.new(item)
|
6
|
-
|
6
|
+
super case item
|
7
7
|
when Text
|
8
|
-
item.to_s
|
8
|
+
parse(item.to_s)
|
9
9
|
when String
|
10
|
-
item
|
10
|
+
parse(item)
|
11
11
|
else
|
12
12
|
raise(InvalidItem, item)
|
13
13
|
end
|
14
|
-
|
15
|
-
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.parse(string)
|
17
|
+
unless string =~ /^#{URI::regexp}$/
|
18
|
+
raise(InvalidItem, string)
|
16
19
|
end
|
17
|
-
super(item)
|
18
20
|
end
|
19
21
|
|
20
22
|
def initialize(url)
|
data/lib/saper/items/xml.rb
CHANGED
data/lib/saper/version.rb
CHANGED
@@ -3,27 +3,57 @@ require './spec/spec_helper'
|
|
3
3
|
describe Saper::Actions::AppendWith do
|
4
4
|
|
5
5
|
let(:action) do
|
6
|
-
Saper::
|
6
|
+
Saper::Actions::AppendWith.new('!')
|
7
7
|
end
|
8
8
|
|
9
|
-
context ".
|
10
|
-
it "
|
11
|
-
Saper::Actions::AppendWith.
|
9
|
+
context ".new(nil)" do
|
10
|
+
it "raises InvalidArgument" do
|
11
|
+
expect { Saper::Actions::AppendWith.new(nil) }.to raise_error(Saper::InvalidArgument)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
context ".new" do
|
16
|
-
it "raises InvalidArgument
|
17
|
-
expect {
|
15
|
+
context ".new(Number)" do
|
16
|
+
it "raises InvalidArgument" do
|
17
|
+
expect { Saper::Actions::AppendWith.new(2) }.to raise_error(Saper::InvalidArgument)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context ".new(String)" do
|
22
|
+
it "raises no errors" do
|
23
|
+
expect { Saper::Actions::AppendWith.new("!") }.to_not raise_error
|
24
|
+
end
|
25
|
+
it "returns Action instance" do
|
26
|
+
Saper::Actions::AppendWith.new("!").should be_a(Saper::Action)
|
18
27
|
end
|
19
28
|
end
|
20
29
|
|
21
|
-
context "#run" do
|
22
|
-
it "raises InvalidInput
|
30
|
+
context "#run(nil)" do
|
31
|
+
it "raises InvalidInput" do
|
23
32
|
expect { action.run(nil) }.to raise_error(Saper::InvalidInput)
|
24
33
|
end
|
25
|
-
|
26
|
-
|
34
|
+
end
|
35
|
+
|
36
|
+
context "#run(String)" do
|
37
|
+
let(:input) do
|
38
|
+
'string'
|
39
|
+
end
|
40
|
+
it "returns valid output" do
|
41
|
+
action.run(input).should == 'string!'
|
42
|
+
end
|
43
|
+
it "returns Text instance" do
|
44
|
+
action.run(input).should be_a(Saper::Items::Text)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "#run(Text)" do
|
49
|
+
let(:input) do
|
50
|
+
Saper::Items::Text.new('string')
|
51
|
+
end
|
52
|
+
it "returns valid output" do
|
53
|
+
action.run(input).should == 'string!'
|
54
|
+
end
|
55
|
+
it "returns Text instance" do
|
56
|
+
action.run(input).should be_a(Saper::Items::Text)
|
27
57
|
end
|
28
58
|
end
|
29
59
|
|
@@ -3,21 +3,36 @@ require './spec/spec_helper'
|
|
3
3
|
describe Saper::Actions::ConvertToHTML do
|
4
4
|
|
5
5
|
let(:action) do
|
6
|
-
Saper::
|
6
|
+
Saper::Actions::ConvertToHTML.new
|
7
7
|
end
|
8
8
|
|
9
|
-
context "
|
10
|
-
it "
|
11
|
-
|
9
|
+
context "#run(nil)" do
|
10
|
+
it "raises InvalidInput" do
|
11
|
+
expect { action.run(nil) }.to raise_error(Saper::InvalidInput)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
context "#run" do
|
16
|
-
|
17
|
-
|
15
|
+
context "#run(String)" do
|
16
|
+
let(:input) do
|
17
|
+
'<p>test</p>'
|
18
|
+
end
|
19
|
+
it "raises no errors" do
|
20
|
+
expect { action.run(input) }.to_not raise_error
|
21
|
+
end
|
22
|
+
it "returns HTML instance" do
|
23
|
+
action.run(input).should be_a(Saper::Items::HTML)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "#run(Text)" do
|
28
|
+
let(:input) do
|
29
|
+
Saper::Items::Text.new('<p>test</p>')
|
30
|
+
end
|
31
|
+
it "raises no errors" do
|
32
|
+
expect { action.run(input) }.to_not raise_error
|
18
33
|
end
|
19
|
-
it "
|
20
|
-
|
34
|
+
it "returns HTML instance" do
|
35
|
+
action.run(input).should be_a(Saper::Items::HTML)
|
21
36
|
end
|
22
37
|
end
|
23
38
|
|
@@ -3,21 +3,36 @@ require './spec/spec_helper'
|
|
3
3
|
describe Saper::Actions::ConvertToJSON do
|
4
4
|
|
5
5
|
let(:action) do
|
6
|
-
Saper::
|
6
|
+
Saper::Actions::ConvertToJSON.new
|
7
7
|
end
|
8
8
|
|
9
|
-
context "
|
10
|
-
it "
|
11
|
-
|
9
|
+
context "#run(nil)" do
|
10
|
+
it "raises InvalidInput" do
|
11
|
+
expect { action.run(nil) }.to raise_error(Saper::InvalidInput)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
context "#run" do
|
16
|
-
|
17
|
-
|
15
|
+
context "#run(String)" do
|
16
|
+
let(:input) do
|
17
|
+
'{"test":"ok"}'
|
18
|
+
end
|
19
|
+
it "raises no errors" do
|
20
|
+
expect { action.run(input) }.to_not raise_error
|
21
|
+
end
|
22
|
+
it "returns JSON instance" do
|
23
|
+
action.run(input).should be_a(Saper::Items::JSON)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "#run(String)" do
|
28
|
+
let(:input) do
|
29
|
+
Saper::Items::Text.new('{"test":"ok"}')
|
30
|
+
end
|
31
|
+
it "raises no errors" do
|
32
|
+
expect { action.run(input) }.to_not raise_error
|
18
33
|
end
|
19
|
-
it "
|
20
|
-
|
34
|
+
it "returns JSON instance" do
|
35
|
+
action.run(input).should be_a(Saper::Items::JSON)
|
21
36
|
end
|
22
37
|
end
|
23
38
|
|
@@ -3,21 +3,24 @@ require './spec/spec_helper'
|
|
3
3
|
describe Saper::Actions::ConvertToMarkdown do
|
4
4
|
|
5
5
|
let(:action) do
|
6
|
-
Saper::
|
6
|
+
Saper::Actions::ConvertToMarkdown.new
|
7
7
|
end
|
8
8
|
|
9
|
-
context "
|
10
|
-
it "
|
11
|
-
|
9
|
+
context "#run(nil)" do
|
10
|
+
it "raises InvalidInput" do
|
11
|
+
expect { action.run(nil) }.to raise_error(Saper::InvalidInput)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
context "#run" do
|
16
|
-
|
17
|
-
|
15
|
+
context "#run(HTML)" do
|
16
|
+
let(:input) do
|
17
|
+
Saper::Items::HTML.new('<p>test</p>')
|
18
|
+
end
|
19
|
+
it "returns valid output" do
|
20
|
+
action.run(input).should == 'test'
|
18
21
|
end
|
19
|
-
it "returns
|
20
|
-
action.run(Saper::Items::
|
22
|
+
it "returns Markdown instance" do
|
23
|
+
action.run(input).should be_a(Saper::Items::Markdown)
|
21
24
|
end
|
22
25
|
end
|
23
26
|
|
@@ -1,36 +1,51 @@
|
|
1
1
|
require './spec/spec_helper'
|
2
2
|
|
3
3
|
describe Saper::Actions::ConvertToTime do
|
4
|
-
|
4
|
+
|
5
5
|
let(:action_without_tz) do
|
6
|
-
Saper::
|
6
|
+
Saper::Actions::ConvertToTime.new('%d-%m-%Y %H:%M')
|
7
7
|
end
|
8
8
|
|
9
9
|
let(:action_with_tz) do
|
10
|
-
Saper::
|
10
|
+
Saper::Actions::ConvertToTime.new('%d-%m-%Y %H:%M', 'Europe/Moscow')
|
11
11
|
end
|
12
12
|
|
13
|
-
context ".new" do
|
14
|
-
it "raises InvalidArgument
|
15
|
-
expect {
|
13
|
+
context ".new(nil, nil)" do
|
14
|
+
it "raises InvalidArgument" do
|
15
|
+
expect { Saper::Actions::ConvertToTime.new }.to raise_error(Saper::InvalidArgument)
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
19
|
-
context ".
|
20
|
-
it "
|
21
|
-
Saper::Actions::ConvertToTime.
|
18
|
+
|
19
|
+
context ".new(format, nil)" do
|
20
|
+
it "raises no errors" do
|
21
|
+
expect { Saper::Actions::ConvertToTime.new("%H") }.to_not raise_error
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
context "#run" do
|
26
|
-
it "raises InvalidInput
|
25
|
+
context "#run(nil)" do
|
26
|
+
it "raises InvalidInput" do
|
27
27
|
expect { action_without_tz.run(nil) }.to raise_error(Saper::InvalidInput)
|
28
28
|
end
|
29
|
-
|
30
|
-
|
29
|
+
end
|
30
|
+
|
31
|
+
context "#run(valid date)" do
|
32
|
+
let(:input) do
|
33
|
+
'19-04-2014 18:56'
|
34
|
+
end
|
35
|
+
it "returns valid output if TZ is set" do
|
36
|
+
action_with_tz.run(input).should == '2014-04-19T18:56:00+04:00'
|
37
|
+
end
|
38
|
+
it "returns valid output if TZ is missing" do
|
39
|
+
action_without_tz.run(input).should == '2014-04-19T18:56:00+00:00'
|
31
40
|
end
|
32
|
-
it "returns
|
33
|
-
|
41
|
+
it "returns Time instance" do
|
42
|
+
action_with_tz.run(input).should be_a(Saper::Items::Time)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "#run(invalid date)" do
|
47
|
+
it "raises InvalidItem" do
|
48
|
+
expect { action_with_tz.run("ABCDEF") }.to raise_error(Saper::InvalidItem)
|
34
49
|
end
|
35
50
|
end
|
36
51
|
|
@@ -3,13 +3,7 @@ require './spec/spec_helper'
|
|
3
3
|
describe Saper::Actions::ConvertToXML do
|
4
4
|
|
5
5
|
let(:action) do
|
6
|
-
Saper::
|
7
|
-
end
|
8
|
-
|
9
|
-
context ".accepts" do
|
10
|
-
it "returns acceptable input types" do
|
11
|
-
Saper::Actions::ConvertToXML.accepts.should == [:text, :document]
|
12
|
-
end
|
6
|
+
Saper::Actions::ConvertToXML.new
|
13
7
|
end
|
14
8
|
|
15
9
|
context "#run" do
|
@@ -3,24 +3,20 @@ require './spec/spec_helper'
|
|
3
3
|
describe Saper::Actions::CreateAtom do
|
4
4
|
|
5
5
|
let(:action) do
|
6
|
-
Saper::
|
6
|
+
Saper::Actions::CreateAtom.new
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
context ".accepts" do
|
14
|
-
it "returns acceptable input types" do
|
15
|
-
Saper::Actions::CreateAtom.accepts.should == [:atom, :document, :html, :json, :markdown, :nothing, :text, :time, :url, :xml]
|
9
|
+
context "#run(nil)" do
|
10
|
+
it "raises RuntimeMissing" do
|
11
|
+
expect { action.run(nil) }.to raise_error(Saper::RuntimeMissing)
|
16
12
|
end
|
17
13
|
end
|
18
14
|
|
19
|
-
context "#run" do
|
20
|
-
|
21
|
-
|
15
|
+
context "#run(nil, Runtime)" do
|
16
|
+
let(:runtime) do
|
17
|
+
Saper::Runtime.new
|
22
18
|
end
|
23
|
-
it "raises no errors
|
19
|
+
it "raises no errors" do
|
24
20
|
expect { action.run(nil, runtime) }.to_not raise_error
|
25
21
|
end
|
26
22
|
it "returns Saper::Atom" do
|
data/spec/actions/fetch_spec.rb
CHANGED
@@ -2,6 +2,14 @@ require './spec/spec_helper'
|
|
2
2
|
|
3
3
|
describe Saper::Actions::Fetch do
|
4
4
|
|
5
|
-
|
5
|
+
let(:action) do
|
6
|
+
Saper::Actions::Fetch.new
|
7
|
+
end
|
8
|
+
|
9
|
+
context "#run(nil)" do
|
10
|
+
it "raises InvalidInput" do
|
11
|
+
expect { action.run(nil) }.to raise_error(Saper::InvalidInput)
|
12
|
+
end
|
13
|
+
end
|
6
14
|
|
7
15
|
end
|
@@ -2,6 +2,51 @@ require './spec/spec_helper'
|
|
2
2
|
|
3
3
|
describe Saper::Actions::FindFirst do
|
4
4
|
|
5
|
-
|
5
|
+
let(:action) do
|
6
|
+
Saper::Actions::FindFirst.new("//p")
|
7
|
+
end
|
8
|
+
|
9
|
+
context ".new(nil)" do
|
10
|
+
it "raises InvalidArgument" do
|
11
|
+
expect { Saper::Actions::FindFirst.new(nil) }.to raise_error(Saper::InvalidArgument)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context ".new(CSS)" do
|
16
|
+
it "raises no errors" do
|
17
|
+
expect { Saper::Actions::FindFirst.new("a") }.to_not raise_error
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "#run(nil)" do
|
22
|
+
it "raises InvalidInput" do
|
23
|
+
expect { action.run(nil) }.to raise_error(Saper::InvalidInput)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "#run(HTML)" do
|
28
|
+
let(:input) do
|
29
|
+
Saper::Items::HTML.new('<div><p>test</p></div>')
|
30
|
+
end
|
31
|
+
it "returns HTML instance" do
|
32
|
+
action.run(input).should be_a(Saper::Items::HTML)
|
33
|
+
end
|
34
|
+
it "returns valid output" do
|
35
|
+
action.run(input).name.should == 'p'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "#run(JSON)" do
|
40
|
+
let(:input) do
|
41
|
+
Saper::Items::JSON.new('{"p":{"a":0}}')
|
42
|
+
end
|
43
|
+
it "returns JSON instance" do
|
44
|
+
action.run(input).should be_a(Saper::Items::JSON)
|
45
|
+
end
|
46
|
+
it "returns valid output" do
|
47
|
+
action.run(input).to_s.should == '{"a":0}'
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
6
51
|
|
7
52
|
end
|
data/spec/actions/find_spec.rb
CHANGED
@@ -2,6 +2,50 @@ require './spec/spec_helper'
|
|
2
2
|
|
3
3
|
describe Saper::Actions::Find do
|
4
4
|
|
5
|
-
|
5
|
+
let(:action) do
|
6
|
+
Saper::Actions::Find.new("//p")
|
7
|
+
end
|
8
|
+
|
9
|
+
context ".new(nil)" do
|
10
|
+
it "raises InvalidArgument" do
|
11
|
+
expect { Saper::Actions::Find.new(nil) }.to raise_error(Saper::InvalidArgument)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context ".new(CSS)" do
|
16
|
+
it "raises no errors" do
|
17
|
+
expect { Saper::Actions::Find.new("a") }.to_not raise_error
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "#run(nil)" do
|
22
|
+
it "raises InvalidInput" do
|
23
|
+
expect { action.run(nil) }.to raise_error(Saper::InvalidInput)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "#run(HTML)" do
|
28
|
+
let(:input) do
|
29
|
+
Saper::Items::HTML.new('<div><p>test</p><p>test</p></div>')
|
30
|
+
end
|
31
|
+
it "returns an array of results" do
|
32
|
+
action.run(input).should be_a(Array)
|
33
|
+
end
|
34
|
+
it "returns an array with first item an HTML instance" do
|
35
|
+
action.run(input).first.should be_a(Saper::Items::HTML)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "#run(JSON)" do
|
40
|
+
let(:input) do
|
41
|
+
Saper::Items::JSON.new('{"p":{"a":0},"z":{"a":1}}')
|
42
|
+
end
|
43
|
+
it "returns an array of results" do
|
44
|
+
action.run(input).should be_a(Array)
|
45
|
+
end
|
46
|
+
it "returns an array with first item a JSON instance" do
|
47
|
+
action.run(input).first.should be_a(Saper::Items::JSON)
|
48
|
+
end
|
49
|
+
end
|
6
50
|
|
7
51
|
end
|
@@ -6,12 +6,6 @@ describe Saper::Actions::PrependWith do
|
|
6
6
|
Saper::Action.new(:prepend_with, '!')
|
7
7
|
end
|
8
8
|
|
9
|
-
context ".accepts" do
|
10
|
-
it "returns acceptable input types" do
|
11
|
-
Saper::Actions::AppendWith.accepts.should == [:text]
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
9
|
context ".new" do
|
16
10
|
it "raises InvalidArgument when argument is missing" do
|
17
11
|
expect { subject }.to raise_error(Saper::InvalidArgument)
|
data/spec/items/document_spec.rb
CHANGED
@@ -2,6 +2,24 @@ require './spec/spec_helper'
|
|
2
2
|
|
3
3
|
describe Saper::Items::Document do
|
4
4
|
|
5
|
-
|
5
|
+
context ".new" do
|
6
6
|
|
7
|
+
end
|
8
|
+
|
9
|
+
context "#to_html" do
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
context "#to_markdown" do
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
context "#to_text" do
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
context "#to_xml" do
|
22
|
+
|
23
|
+
end
|
24
|
+
|
7
25
|
end
|
data/spec/items/html_spec.rb
CHANGED
@@ -2,6 +2,40 @@ require './spec/spec_helper'
|
|
2
2
|
|
3
3
|
describe Saper::Items::HTML do
|
4
4
|
|
5
|
-
|
5
|
+
context ".new" do
|
6
6
|
|
7
|
+
end
|
8
|
+
|
9
|
+
context "#[]" do
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
context "#find" do
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
context "#find_all" do
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
context "#inner_html" do
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
context "#inner_text" do
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
context "#remove_children_preserving_content" do
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
context "#remove_children_with_content" do
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
context "#to_markdown" do
|
38
|
+
|
39
|
+
end
|
40
|
+
|
7
41
|
end
|
data/spec/items/json_spec.rb
CHANGED
data/spec/items/text_spec.rb
CHANGED
@@ -14,4 +14,32 @@ describe Saper::Items::Text do
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
context "#gsub" do
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
context "#split" do
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
context "#to_json" do
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
context "#to_html" do
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
context "#to_s" do
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
context "#to_time" do
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
context "#to_xml" do
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
data/spec/items/url_spec.rb
CHANGED
data/spec/items/xml_spec.rb
CHANGED
@@ -14,4 +14,32 @@ describe Saper::Items::XML do
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
context "#[]" do
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
context "#find" do
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
context "#find_all" do
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
context "#inner_html" do
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
context "#inner_text" do
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
context "#remove_children_preserving_content" do
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
context "#remove_children_with_content" do
|
42
|
+
|
43
|
+
end
|
44
|
+
|
17
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Serebryakov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mechanize
|