saper 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/Rakefile +7 -5
- data/bin/saper +51 -1
- data/lib/saper/actions/create_atom.rb +0 -5
- data/lib/saper/actions/nothing.rb +2 -0
- data/lib/saper/actions/remove_matching.rb +1 -1
- data/lib/saper/actions/run_recipe.rb +5 -5
- data/lib/saper/actions/run_recipe_and_save.rb +5 -5
- data/lib/saper/actions/select_matching.rb +1 -1
- data/lib/saper/actions/set_input.rb +0 -5
- data/lib/saper/core/action.rb +69 -53
- data/lib/saper/core/argument.rb +3 -0
- data/lib/saper/core/browser.rb +3 -2
- data/lib/saper/core/error.rb +4 -1
- data/lib/saper/core/keychain.rb +2 -2
- data/lib/saper/core/logger.rb +9 -54
- data/lib/saper/core/recipe.rb +36 -5
- data/lib/saper/core/result.rb +36 -5
- data/lib/saper/core/runtime.rb +17 -11
- data/lib/saper/core/stack.rb +17 -1
- data/lib/saper/items/html.rb +1 -1
- data/lib/saper/items/nothing.rb +9 -0
- data/lib/saper/items/xml.rb +5 -1
- data/lib/saper/version.rb +1 -1
- data/lib/tungsten/lib/README +5 -0
- data/lib/tungsten/lib/test.rb +18 -0
- data/lib/tungsten/lib/tungsten.rb +33 -0
- data/lib/tungsten/lib/tungsten/headers.rb +37 -0
- data/lib/tungsten/lib/tungsten/jar.rb +17 -0
- data/lib/tungsten/lib/tungsten/request.rb +102 -0
- data/lib/tungsten/lib/tungsten/response.rb +101 -0
- data/spec/actions/append_with_spec.rb +144 -21
- data/spec/actions/convert_to_html_spec.rb +126 -11
- data/spec/actions/convert_to_json_spec.rb +126 -11
- data/spec/actions/convert_to_markdown_spec.rb +126 -11
- data/spec/actions/convert_to_time_spec.rb +150 -15
- data/spec/actions/convert_to_xml_spec.rb +136 -11
- data/spec/actions/create_atom_spec.rb +116 -7
- data/spec/actions/fetch_spec.rb +110 -3
- data/spec/actions/find_first_spec.rb +149 -24
- data/spec/actions/find_spec.rb +167 -19
- data/spec/actions/get_attribute_spec.rb +145 -15
- data/spec/actions/get_contents_spec.rb +125 -4
- data/spec/actions/get_text_spec.rb +125 -4
- data/spec/actions/nothing_spec.rb +119 -4
- data/spec/actions/prepend_with_spec.rb +148 -22
- data/spec/actions/remove_after_spec.rb +160 -4
- data/spec/actions/remove_before_spec.rb +160 -4
- data/spec/actions/remove_matching_spec.rb +164 -4
- data/spec/actions/remove_tags_spec.rb +1 -1
- data/spec/actions/replace_spec.rb +1 -1
- data/spec/actions/run_recipe_and_save_spec.rb +1 -1
- data/spec/actions/run_recipe_spec.rb +1 -1
- data/spec/actions/save_spec.rb +1 -1
- data/spec/actions/select_matching_spec.rb +164 -4
- data/spec/actions/set_input_spec.rb +1 -1
- data/spec/actions/skip_tags_spec.rb +1 -1
- data/spec/actions/split_spec.rb +1 -1
- data/spec/arguments/attribute_spec.rb +1 -1
- data/spec/arguments/recipe_spec.rb +1 -1
- data/spec/arguments/text_spec.rb +1 -1
- data/spec/arguments/timezone_spec.rb +1 -1
- data/spec/arguments/variable_spec.rb +1 -1
- data/spec/arguments/xpath_spec.rb +1 -1
- data/spec/core/action_spec.rb +25 -13
- data/spec/core/argument_spec.rb +55 -31
- data/spec/core/browser_spec.rb +21 -11
- data/spec/core/dsl_spec.rb +1 -1
- data/spec/core/item_spec.rb +1 -1
- data/spec/core/keychain_spec.rb +1 -1
- data/spec/core/logger_spec.rb +1 -1
- data/spec/core/namespace_spec.rb +1 -1
- data/spec/core/recipe_spec.rb +85 -51
- data/spec/core/result_spec.rb +1 -1
- data/spec/core/runtime_spec.rb +45 -27
- data/spec/core/stack_spec.rb +1 -1
- data/spec/core/type_spec.rb +1 -1
- data/spec/integration/simple_invalid_spec.rb +46 -9
- data/spec/integration/simple_valid_spec.rb +9 -9
- data/spec/items/atom_spec.rb +7 -7
- data/spec/items/document_spec.rb +29 -29
- data/spec/items/html_spec.rb +80 -48
- data/spec/items/json_spec.rb +17 -11
- data/spec/items/markdown_spec.rb +30 -18
- data/spec/items/nothing_spec.rb +1 -1
- data/spec/items/text_spec.rb +12 -10
- data/spec/items/time_spec.rb +35 -21
- data/spec/items/url_spec.rb +1 -1
- data/spec/items/xml_spec.rb +75 -42
- data/spec/spec_helper.rb +90 -2
- metadata +51 -16
data/spec/core/result_spec.rb
CHANGED
data/spec/core/runtime_spec.rb
CHANGED
|
@@ -1,34 +1,52 @@
|
|
|
1
1
|
require './spec/spec_helper'
|
|
2
2
|
|
|
3
|
-
describe Saper::Runtime do
|
|
3
|
+
RSpec.describe Saper::Runtime do
|
|
4
4
|
let :subject do
|
|
5
5
|
Saper::Runtime.new
|
|
6
6
|
end
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
7
|
+
context "#browser" do
|
|
8
|
+
it "returns Browser instance" do
|
|
9
|
+
expect(subject.browser).to be_a(Saper::Browser)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
context "#bytes_received" do
|
|
13
|
+
it "returns zero by default" do
|
|
14
|
+
expect(subject.bytes_received).to eq 0
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
context "#bytes_sent" do
|
|
18
|
+
it "returns zero by default" do
|
|
19
|
+
expect(subject.bytes_sent).to eq 0
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
context "#http_requests" do
|
|
23
|
+
it "returns zero by default" do
|
|
24
|
+
expect(subject.http_requests).to eq 0
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
context "#keychain" do
|
|
28
|
+
it "returns Keychain instance" do
|
|
29
|
+
expect(subject.keychain).to be_a Saper::Keychain
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
context "#credentials" do
|
|
33
|
+
it "returns empty hash if service not found" do
|
|
34
|
+
expect(subject.credentials(:services)).to eq({})
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
context "#[]" do
|
|
38
|
+
it "returns nil if variable is not defined" do
|
|
39
|
+
expect(subject[:varname]).to be_nil
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
context "#[]=" do
|
|
43
|
+
it "stores variale value" do
|
|
44
|
+
expect(Saper::Runtime.new { |r| r[:var] = 'A' }[:var]).to eq 'A'
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
context "#variables" do
|
|
48
|
+
it "returns list of variable names" do
|
|
49
|
+
expect(Saper::Runtime.new { |r| r[:var] = 'B' }.variables).to eq({ :var => 'B' })
|
|
50
|
+
end
|
|
33
51
|
end
|
|
34
52
|
end
|
data/spec/core/stack_spec.rb
CHANGED
data/spec/core/type_spec.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require './spec/spec_helper'
|
|
2
2
|
|
|
3
|
-
describe "Simple Invalid Recipe" do
|
|
3
|
+
RSpec.describe "Simple Invalid Recipe" do
|
|
4
4
|
let :recipe do
|
|
5
5
|
Saper::Recipe.parse do
|
|
6
6
|
set_input "<p>one</p><p>two</p>"
|
|
@@ -13,27 +13,64 @@ describe "Simple Invalid Recipe" do
|
|
|
13
13
|
recipe.run
|
|
14
14
|
end
|
|
15
15
|
it "returns Result" do
|
|
16
|
-
result.
|
|
16
|
+
expect(result).to be_a Saper::Result
|
|
17
17
|
end
|
|
18
18
|
it "#multiple? returns false" do
|
|
19
|
-
result.
|
|
19
|
+
expect(result).to_not be_multiple
|
|
20
20
|
end
|
|
21
21
|
it "#success? returns false" do
|
|
22
|
-
result.
|
|
22
|
+
expect(result).to_not be_success
|
|
23
23
|
end
|
|
24
24
|
it "#failure? returns true" do
|
|
25
|
-
result.
|
|
25
|
+
expect(result).to be_failure
|
|
26
26
|
end
|
|
27
27
|
it "#size returns 1" do
|
|
28
|
-
result.size.
|
|
28
|
+
expect(result.size).to eq 1
|
|
29
29
|
end
|
|
30
30
|
it "#to_native returns nil" do
|
|
31
|
-
result.to_native.
|
|
31
|
+
expect(result.to_native).to be_nil
|
|
32
32
|
end
|
|
33
33
|
it "#to_saper returns Saper::Items::Nothing" do
|
|
34
|
-
result.to_saper.
|
|
34
|
+
expect(result.to_saper).to be_a Saper::Items::Nothing
|
|
35
35
|
end
|
|
36
36
|
it "#to_json returns valid String" do
|
|
37
|
-
result.to_json.
|
|
37
|
+
expect(result.to_json).to eq 'null'
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
RSpec.describe "Simple Invalid Recipe" do
|
|
42
|
+
let :recipe do
|
|
43
|
+
Saper::Recipe.parse do
|
|
44
|
+
set_input "<p>one</p><p>two</p>"
|
|
45
|
+
convert_to_html
|
|
46
|
+
find "a"
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
let :result do
|
|
50
|
+
recipe.run
|
|
51
|
+
end
|
|
52
|
+
it "returns Result" do
|
|
53
|
+
expect(result).to be_a Saper::Result
|
|
54
|
+
end
|
|
55
|
+
it "#multiple? returns false" do
|
|
56
|
+
expect(result).to_not be_multiple
|
|
57
|
+
end
|
|
58
|
+
it "#success? returns false" do
|
|
59
|
+
expect(result).to_not be_success
|
|
60
|
+
end
|
|
61
|
+
it "#failure? returns true" do
|
|
62
|
+
expect(result).to be_failure
|
|
63
|
+
end
|
|
64
|
+
it "#size returns 1" do
|
|
65
|
+
expect(result.size).to eq 1
|
|
66
|
+
end
|
|
67
|
+
it "#to_native return nil" do
|
|
68
|
+
expect(result.to_native).to be_nil
|
|
69
|
+
end
|
|
70
|
+
it "#to_saper returns nil" do
|
|
71
|
+
expect(result.to_saper).to be_nil
|
|
72
|
+
end
|
|
73
|
+
it "#to_json returns valid JSON" do
|
|
74
|
+
expect(result.to_json).to eq 'null'
|
|
38
75
|
end
|
|
39
76
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require './spec/spec_helper'
|
|
2
2
|
|
|
3
|
-
describe "Simple Valid Recipe" do
|
|
3
|
+
RSpec.describe "Simple Valid Recipe" do
|
|
4
4
|
let :recipe do
|
|
5
5
|
Saper::Recipe.parse do
|
|
6
6
|
set_input "<p>one</p><p>two</p>"
|
|
@@ -13,27 +13,27 @@ describe "Simple Valid Recipe" do
|
|
|
13
13
|
recipe.run
|
|
14
14
|
end
|
|
15
15
|
it "returns Result" do
|
|
16
|
-
result.
|
|
16
|
+
expect(result).to be_a Saper::Result
|
|
17
17
|
end
|
|
18
18
|
it "#multiple? returns true" do
|
|
19
|
-
result.
|
|
19
|
+
expect(result).to be_multiple
|
|
20
20
|
end
|
|
21
21
|
it "#success? returns true" do
|
|
22
|
-
result.
|
|
22
|
+
expect(result).to be_success
|
|
23
23
|
end
|
|
24
24
|
it "#failure? returns false" do
|
|
25
|
-
result.
|
|
25
|
+
expect(result).to_not be_failure
|
|
26
26
|
end
|
|
27
27
|
it "#size returns 2" do
|
|
28
|
-
result.size.
|
|
28
|
+
expect(result.size).to eq 2
|
|
29
29
|
end
|
|
30
30
|
it "#to_native returns valid Array" do
|
|
31
|
-
result.to_native.
|
|
31
|
+
expect(result.to_native).to eq ["one","two"]
|
|
32
32
|
end
|
|
33
33
|
it "#to_saper returns valid Array" do
|
|
34
|
-
result.to_saper.
|
|
34
|
+
expect(result.to_saper).to eq [Saper::Items::Text.new("one"),Saper::Items::Text.new("two")]
|
|
35
35
|
end
|
|
36
36
|
it "#to_json returns valid String" do
|
|
37
|
-
result.to_json.
|
|
37
|
+
expect(result.to_json).to eq '["one","two"]'
|
|
38
38
|
end
|
|
39
39
|
end
|
data/spec/items/atom_spec.rb
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
require './spec/spec_helper'
|
|
2
2
|
|
|
3
|
-
describe Saper::Items::Atom do
|
|
3
|
+
RSpec.describe Saper::Items::Atom do
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
context ".new" # TODO
|
|
6
|
+
context "#[]" # TODO
|
|
7
|
+
context "#serialize" # TODO
|
|
8
|
+
context "#to_hash" # TODO
|
|
9
|
+
context "#to_native" # TODO
|
|
10
|
+
context "#to_json" # TODO
|
|
11
11
|
|
|
12
12
|
end
|
data/spec/items/document_spec.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require './spec/spec_helper'
|
|
2
2
|
|
|
3
|
-
describe Saper::Items::Document do
|
|
3
|
+
RSpec.describe Saper::Items::Document do
|
|
4
4
|
let(:doc) do
|
|
5
5
|
Saper::Items::Document.new("")
|
|
6
6
|
end
|
|
@@ -8,96 +8,96 @@ describe Saper::Items::Document do
|
|
|
8
8
|
Saper::Items::Document.new("", "http://google.com", { "content-type" => "text/html; charset=win-1251" })
|
|
9
9
|
end
|
|
10
10
|
it ".new(nil) raises InvalidItem" do
|
|
11
|
-
|
|
11
|
+
expect { Saper::Items::Document.new(nil) }.to raise_error Saper::InvalidItem
|
|
12
12
|
end
|
|
13
13
|
it "#uri returns nil by default" do
|
|
14
|
-
doc.uri.
|
|
14
|
+
expect(doc.uri).to be_nil
|
|
15
15
|
end
|
|
16
16
|
it "#uri returns URI when defined" do
|
|
17
|
-
doc_with_params.uri.
|
|
17
|
+
expect(doc_with_params.uri).to eq "http://google.com"
|
|
18
18
|
end
|
|
19
19
|
it "#mime returns nil by default" do
|
|
20
|
-
doc.mime.
|
|
20
|
+
expect(doc.mime).to be_nil
|
|
21
21
|
end
|
|
22
22
|
it "#mime returns mime type if defined in headers" do
|
|
23
|
-
doc_with_params.mime.
|
|
23
|
+
expect(doc_with_params.mime).to eq "text/html"
|
|
24
24
|
end
|
|
25
25
|
it "#charset returns nil by defaukt" do
|
|
26
|
-
doc.charset.
|
|
26
|
+
expect(doc.charset).to be_nil
|
|
27
27
|
end
|
|
28
28
|
it "#charset returns charset if defined in headers" do
|
|
29
|
-
doc_with_params.charset.
|
|
29
|
+
expect(doc_with_params.charset).to eq "win-1251"
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
describe "Saper::Items::Document(empty String)" do
|
|
33
|
+
RSpec.describe "Saper::Items::Document(empty String)" do
|
|
34
34
|
subject do
|
|
35
35
|
Saper::Items::Document.new("")
|
|
36
36
|
end
|
|
37
37
|
it "#size returns zero" do
|
|
38
|
-
subject.size.
|
|
38
|
+
expect(subject.size).to eq 0
|
|
39
39
|
end
|
|
40
40
|
it "#to_html raises InvalidItem" do
|
|
41
|
-
|
|
41
|
+
expect { subject.to_html }.to raise_error Saper::InvalidItem
|
|
42
42
|
end
|
|
43
43
|
it "#to_markdown raises InvalidItem" do
|
|
44
|
-
|
|
44
|
+
expect { subject.to_markdown }.to raise_error Saper::InvalidItem
|
|
45
45
|
end
|
|
46
46
|
it "#to_native returns empty string" do
|
|
47
|
-
subject.to_native.
|
|
47
|
+
expect(subject.to_native).to eq ""
|
|
48
48
|
end
|
|
49
49
|
it "#to_text returns Text" do
|
|
50
|
-
subject.to_text.
|
|
50
|
+
expect(subject.to_text).to be_a Saper::Items::Text
|
|
51
51
|
end
|
|
52
52
|
it "#to_xml raises InvalidItem" do
|
|
53
|
-
|
|
53
|
+
expect { subject.to_xml }.to raise_error Saper::InvalidItem
|
|
54
54
|
end
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
-
describe "Saper::Items::Document(HTML as String)" do
|
|
57
|
+
RSpec.describe "Saper::Items::Document(HTML as String)" do
|
|
58
58
|
subject do
|
|
59
59
|
Saper::Items::Document.new("<html></html>")
|
|
60
60
|
end
|
|
61
61
|
it "#size returns string length" do
|
|
62
|
-
subject.size.
|
|
62
|
+
expect(subject.size).to eq 13
|
|
63
63
|
end
|
|
64
64
|
it "#to_html returns HTML" do
|
|
65
|
-
subject.to_html.
|
|
65
|
+
expect(subject.to_html).to be_a Saper::Items::HTML
|
|
66
66
|
end
|
|
67
67
|
it "#to_markdown returns Markdown" do
|
|
68
|
-
subject.to_markdown.
|
|
68
|
+
expect(subject.to_markdown).to be_a Saper::Items::Markdown
|
|
69
69
|
end
|
|
70
70
|
it "#to_native returns document contents" do
|
|
71
|
-
subject.to_native.
|
|
71
|
+
expect(subject.to_native).to eq "<html></html>"
|
|
72
72
|
end
|
|
73
73
|
it "#to_text returns Text" do
|
|
74
|
-
subject.to_text.
|
|
74
|
+
expect(subject.to_text).to be_a Saper::Items::Text
|
|
75
75
|
end
|
|
76
76
|
it "#to_xml raises InvalidItem" do
|
|
77
|
-
subject.to_xml.
|
|
77
|
+
expect(subject.to_xml).to be_a Saper::Items::XML
|
|
78
78
|
end
|
|
79
79
|
end
|
|
80
80
|
|
|
81
|
-
describe "Saper::Items::Document(XML as String)" do
|
|
81
|
+
RSpec.describe "Saper::Items::Document(XML as String)" do
|
|
82
82
|
subject do
|
|
83
83
|
Saper::Items::Document.new("<response></response>")
|
|
84
84
|
end
|
|
85
85
|
it "#size returns string length" do
|
|
86
|
-
subject.size.
|
|
86
|
+
expect(subject.size).to eq 21
|
|
87
87
|
end
|
|
88
88
|
it "#to_html returns HTML" do
|
|
89
|
-
subject.to_html.
|
|
89
|
+
expect(subject.to_html).to be_a Saper::Items::HTML
|
|
90
90
|
end
|
|
91
91
|
it "#to_markdown returns Markdown" do
|
|
92
|
-
subject.to_markdown.
|
|
92
|
+
expect(subject.to_markdown).to be_a Saper::Items::Markdown
|
|
93
93
|
end
|
|
94
94
|
it "#to_native returns document contents" do
|
|
95
|
-
subject.to_native.
|
|
95
|
+
expect(subject.to_native).to eq "<response></response>"
|
|
96
96
|
end
|
|
97
97
|
it "#to_text returns Text" do
|
|
98
|
-
subject.to_text.
|
|
98
|
+
expect(subject.to_text).to be_a Saper::Items::Text
|
|
99
99
|
end
|
|
100
100
|
it "#to_xml returns XML" do
|
|
101
|
-
subject.to_xml.
|
|
101
|
+
expect(subject.to_xml).to be_a Saper::Items::XML
|
|
102
102
|
end
|
|
103
103
|
end
|
data/spec/items/html_spec.rb
CHANGED
|
@@ -1,58 +1,90 @@
|
|
|
1
1
|
require './spec/spec_helper'
|
|
2
2
|
|
|
3
|
-
describe Saper::Items::HTML do
|
|
3
|
+
RSpec.describe Saper::Items::HTML do
|
|
4
4
|
let :html do
|
|
5
5
|
"<html><body><p><a href=\"http://google.com\">Google</a></p><p><a href=\"http://yandex.ru\">Yandex</a></p></body></html>"
|
|
6
6
|
end
|
|
7
7
|
let :subject do
|
|
8
8
|
Saper::Items::HTML.new html
|
|
9
9
|
end
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
|
|
10
|
+
context ".new(nil)" do
|
|
11
|
+
it "raises InvalidItem" do
|
|
12
|
+
expect { Saper::Items::HTML.new(nil) }.to raise_error Saper::InvalidItem
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
context ".new('')" do
|
|
16
|
+
it "raises InvalidItem" do
|
|
17
|
+
expect { Saper::Items::HTML.new("") }.to raise_error Saper::InvalidItem
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
context ".new(String)" do
|
|
21
|
+
it "returns HTML" do
|
|
22
|
+
expect(Saper::Items::HTML.new("string")).to be_a Saper::Items::HTML
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
context "#find(valid)" do
|
|
26
|
+
it "returns HTML" do
|
|
27
|
+
expect(subject.find("a")).to be_a Saper::Items::HTML
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
context "#find(invalid)" do
|
|
31
|
+
it "returns nil" do
|
|
32
|
+
expect(subject.find("li")).to be_nil
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
context "#find_all(valid)" do
|
|
36
|
+
it "returns an Array of HTML instances" do
|
|
37
|
+
expect(subject.find_all("a").first).to be_a Saper::Items::HTML
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
context "#find_all(invalid)" do
|
|
41
|
+
it "returns an empty Array" do
|
|
42
|
+
expect(subject.find_all("li")).to be_empty
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
context "#[](valid)" do
|
|
46
|
+
it "returns Text" do
|
|
47
|
+
expect(subject.find("a")["href"]).to be_a Saper::Items::Text
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
context "#[](invalid)" do
|
|
51
|
+
it "returns nil" do
|
|
52
|
+
expect(subject.find("a")["unknown"]).to be_nil
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
context "#inner_html" do
|
|
56
|
+
it "returns Text" do
|
|
57
|
+
expect(subject.inner_html).to be_a Saper::Items::Text
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
context "#inner_html" do
|
|
61
|
+
it "returns valid contents" do
|
|
62
|
+
expect(subject.inner_html).to eq html
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
context "#inner_text" do
|
|
66
|
+
it "returns Text" do
|
|
67
|
+
expect(subject.inner_text).to be_a Saper::Items::Text
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
context "#remove_children_preserving_content" do
|
|
71
|
+
it "returns modified HTML" do
|
|
72
|
+
expect(subject.remove_children_preserving_content("a").to_native).to eq "<html><body><p>Google</p><p>Yandex</p></body></html>"
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
context "#remove_children_with_content" do
|
|
76
|
+
it "returns modified HTML" do
|
|
77
|
+
expect(subject.remove_children_with_content("a").to_native).to eq "<html><body><p></p><p></p></body></html>"
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
context "#to_markdown" do
|
|
81
|
+
it "returns Markdown" do
|
|
82
|
+
expect(subject.to_markdown).to be_a Saper::Items::Markdown
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
context "#==" do
|
|
86
|
+
it "returns true for matching string" do
|
|
87
|
+
expect(subject.to_s).to eq html
|
|
88
|
+
end
|
|
57
89
|
end
|
|
58
90
|
end
|