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
|
@@ -1,22 +1,147 @@
|
|
|
1
1
|
require './spec/spec_helper'
|
|
2
2
|
|
|
3
|
-
describe Saper::Actions::ConvertToXML do
|
|
3
|
+
RSpec.describe Saper::Actions::ConvertToXML do
|
|
4
4
|
let :subject do
|
|
5
5
|
Saper::Actions::ConvertToXML.new
|
|
6
6
|
end
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
context ".type" do
|
|
8
|
+
it "returns convert_to_xml" do
|
|
9
|
+
expect(described_class.type).to eq 'convert_to_xml'
|
|
10
|
+
end
|
|
9
11
|
end
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
context ".accepts?(:atom)" do
|
|
13
|
+
it "returns false" do
|
|
14
|
+
expect(described_class.accepts?(:atom)).to be false
|
|
15
|
+
end
|
|
12
16
|
end
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
context ".accepts?(:document)" do
|
|
18
|
+
it "returns true" do
|
|
19
|
+
expect(described_class.accepts?(:document)).to be true
|
|
20
|
+
end
|
|
15
21
|
end
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
context ".accepts?(:html)" do
|
|
23
|
+
it "returns false" do
|
|
24
|
+
expect(described_class.accepts?(:html)).to be false
|
|
25
|
+
end
|
|
18
26
|
end
|
|
19
|
-
|
|
20
|
-
|
|
27
|
+
context ".accepts?(:json)" do
|
|
28
|
+
it "returns false" do
|
|
29
|
+
expect(described_class.accepts?(:json)).to be false
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
context ".accepts?(:markdown)" do
|
|
33
|
+
it "returns false" do
|
|
34
|
+
expect(described_class.accepts?(:markdown)).to be false
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
context ".accepts?(:nothing)" do
|
|
38
|
+
it "returns false" do
|
|
39
|
+
expect(described_class.accepts?(:nothing)).to be false
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
context ".accepts?(:text)" do
|
|
43
|
+
it "returns true " do
|
|
44
|
+
expect(described_class.accepts?(:text)).to be true
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
context ".accepts?(:time)" do
|
|
48
|
+
it "returns false" do
|
|
49
|
+
expect(described_class.accepts?(:time)).to be false
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
context ".accepts?(:url)" do
|
|
53
|
+
it "returns false" do
|
|
54
|
+
expect(described_class.accepts?(:url)).to be false
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
context ".accepts?(:xml)" do
|
|
58
|
+
it "returns false" do
|
|
59
|
+
expect(described_class.accepts?(:xml)).to be false
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
context ".output_for(:atom)" do
|
|
63
|
+
it "returns :nothing" do
|
|
64
|
+
expect(described_class.output_for(:atom)).to be :nothing
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
context ".output_for(:document)" do
|
|
68
|
+
it "returns :xml" do
|
|
69
|
+
expect(described_class.output_for(:document)).to be :xml
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
context ".output_for(:html)" do
|
|
73
|
+
it "returns :nothing" do
|
|
74
|
+
expect(described_class.output_for(:html)).to be :nothing
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
context ".output_for(:json)" do
|
|
78
|
+
it "returns :nothing" do
|
|
79
|
+
expect(described_class.output_for(:json)).to be :nothing
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
context ".output_for(:markdown)" do
|
|
83
|
+
it "returns :nothing" do
|
|
84
|
+
expect(described_class.output_for(:markdown)).to be :nothing
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
context ".output_for(:text)" do
|
|
88
|
+
it "returns :xml" do
|
|
89
|
+
expect(described_class.output_for(:text)).to be :xml
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
context ".output_for(:time)" do
|
|
93
|
+
it "returns :nothing" do
|
|
94
|
+
expect(described_class.output_for(:time)).to be :nothing
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
context ".output_for(:url)" do
|
|
98
|
+
it "returns :nothing" do
|
|
99
|
+
expect(described_class.output_for(:url)).to be :nothing
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
context ".output_for(:xml)" do
|
|
103
|
+
it "returns :nothing" do
|
|
104
|
+
expect(described_class.output_for(:xml)).to be :nothing
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
context ".returns_multiple_items?" do
|
|
108
|
+
it "returns false" do
|
|
109
|
+
expect(described_class.returns_multiple_items?).to be false
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
context ".new()" do
|
|
113
|
+
it "raises no errors" do
|
|
114
|
+
expect { described_class.new }.to_not raise_error
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
context "#run(nil)" do
|
|
118
|
+
it "raises InvalidInput" do
|
|
119
|
+
expect { subject.run(nil) }.to raise_error Saper::InvalidInput
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
context "#run(Numeric)" do
|
|
123
|
+
it "raises InvalidInput" do
|
|
124
|
+
expect { subject.run(2) }.to raise_error Saper::InvalidInput
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
context "#run(empty String)" do
|
|
128
|
+
it "raises InvalidInput" do
|
|
129
|
+
expect { subject.run("") }.to raise_error Saper::InvalidItem
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
context "#run(invalid String)" do
|
|
133
|
+
it "raises InvalidInput" do
|
|
134
|
+
expect { subject.run("not xml") }.to raise_error Saper::InvalidItem
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
context "#run(valid String)" do
|
|
138
|
+
it "returns XML instance" do
|
|
139
|
+
expect(subject.run('<root>test</root>')).to be_a Saper::Items::XML
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
context "#run(valid Text)" do
|
|
143
|
+
it "returns XML instance" do
|
|
144
|
+
expect(subject.run(Saper::Items::Text.new('<root>test</root>'))).to be_a Saper::Items::XML
|
|
145
|
+
end
|
|
21
146
|
end
|
|
22
147
|
end
|
|
@@ -1,19 +1,128 @@
|
|
|
1
1
|
require './spec/spec_helper'
|
|
2
2
|
|
|
3
|
-
describe Saper::Actions::CreateAtom do
|
|
3
|
+
RSpec.describe Saper::Actions::CreateAtom do
|
|
4
4
|
let :subject do
|
|
5
5
|
Saper::Actions::CreateAtom.new
|
|
6
6
|
end
|
|
7
7
|
let :runtime do
|
|
8
8
|
Saper::Runtime.new :test => 'ok'
|
|
9
9
|
end
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
context ".type" do
|
|
11
|
+
it "returns create_atom" do
|
|
12
|
+
expect(described_class.type).to eq 'create_atom'
|
|
13
|
+
end
|
|
12
14
|
end
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
context ".accepts?(:atom)" do
|
|
16
|
+
it "returns true" do
|
|
17
|
+
expect(described_class.accepts?(:atom)).to be true
|
|
18
|
+
end
|
|
15
19
|
end
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
context ".accepts?(:html)" do
|
|
21
|
+
it "returns true" do
|
|
22
|
+
expect(described_class.accepts?(:html)).to be true
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
context ".accepts?(:json)" do
|
|
26
|
+
it "returns true" do
|
|
27
|
+
expect(described_class.accepts?(:json)).to be true
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
context ".accepts?(:markdown)" do
|
|
31
|
+
it "returns true" do
|
|
32
|
+
expect(described_class.accepts?(:markdown)).to be true
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
context ".accepts?(:nothing)" do
|
|
36
|
+
it "returns true" do
|
|
37
|
+
expect(described_class.accepts?(:nothing)).to be true
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
context ".accepts?(:text)" do
|
|
41
|
+
it "returns true" do
|
|
42
|
+
expect(described_class.accepts?(:text)).to be true
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
context ".accepts?(:time)" do
|
|
46
|
+
it "returns true" do
|
|
47
|
+
expect(described_class.accepts?(:time)).to be true
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
context ".accepts?(:url)" do
|
|
51
|
+
it "returns true" do
|
|
52
|
+
expect(described_class.accepts?(:url)).to be true
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
context ".accepts?(:xml)" do
|
|
56
|
+
it "returns true" do
|
|
57
|
+
expect(described_class.accepts?(:xml)).to be true
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
context ".output_for(:atom)" do
|
|
61
|
+
it "returns :atom" do
|
|
62
|
+
expect(described_class.output_for(:atom)).to be :atom
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
context ".output_for(:document)" do
|
|
66
|
+
it "returns :atom" do
|
|
67
|
+
expect(described_class.output_for(:document)).to be :atom
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
context ".output_for(:html)" do
|
|
71
|
+
it "returns :atom" do
|
|
72
|
+
expect(described_class.output_for(:html)).to be :atom
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
context ".output_for(:json)" do
|
|
76
|
+
it "returns :atom" do
|
|
77
|
+
expect(described_class.output_for(:json)).to be :atom
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
context ".output_for(:markdown)" do
|
|
81
|
+
it "returns :atom" do
|
|
82
|
+
expect(described_class.output_for(:markdown)).to be :atom
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
context ".output_for(:text)" do
|
|
86
|
+
it "returns :atom" do
|
|
87
|
+
expect(described_class.output_for(:text)).to be :atom
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
context ".output_for(:time)" do
|
|
91
|
+
it "returns :atom" do
|
|
92
|
+
expect(described_class.output_for(:time)).to be :atom
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
context ".output_for(:url)" do
|
|
96
|
+
it "returns :atom" do
|
|
97
|
+
expect(described_class.output_for(:url)).to be :atom
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
context ".output_for(:xml)" do
|
|
101
|
+
it "returns :atom" do
|
|
102
|
+
expect(described_class.output_for(:xml)).to be :atom
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
context ".returns_multiple_items?" do
|
|
106
|
+
it "returns false" do
|
|
107
|
+
expect(described_class.returns_multiple_items?).to be false
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
context ".new()" do
|
|
111
|
+
it "raises no errors" do
|
|
112
|
+
expect { described_class.new }.to_not raise_error
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
context "#run(nil)" do
|
|
116
|
+
it "returns Saper::Atom" do
|
|
117
|
+
expect(subject.run(nil)).to be_a Saper::Items::Atom
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
context "#run(nil, Runtime)" do
|
|
121
|
+
it "returns Saper::Atom" do
|
|
122
|
+
expect(subject.run(nil, runtime)).to be_a Saper::Items::Atom
|
|
123
|
+
end
|
|
124
|
+
it "returns valid output" do
|
|
125
|
+
expect(subject.run(nil, runtime).to_native).to eq :test => 'ok'
|
|
126
|
+
end
|
|
18
127
|
end
|
|
19
128
|
end
|
data/spec/actions/fetch_spec.rb
CHANGED
|
@@ -1,10 +1,117 @@
|
|
|
1
1
|
require './spec/spec_helper'
|
|
2
2
|
|
|
3
|
-
describe Saper::Actions::Fetch do
|
|
3
|
+
RSpec.describe Saper::Actions::Fetch do
|
|
4
4
|
let :subject do
|
|
5
5
|
Saper::Actions::Fetch.new
|
|
6
6
|
end
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
context ".type" do
|
|
8
|
+
it "returns fetch" do
|
|
9
|
+
expect(described_class.type).to eq 'fetch'
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
context ".accepts?(:atom)" do
|
|
13
|
+
it "returns false" do
|
|
14
|
+
expect(described_class.accepts?(:atom)).to be false
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
context ".accepts?(:html)" do
|
|
18
|
+
it "returns false" do
|
|
19
|
+
expect(described_class.accepts?(:html)).to be false
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
context ".accepts?(:json)" do
|
|
23
|
+
it "returns false" do
|
|
24
|
+
expect(described_class.accepts?(:json)).to be false
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
context ".accepts?(:markdown)" do
|
|
28
|
+
it "returns false" do
|
|
29
|
+
expect(described_class.accepts?(:markdown)).to be false
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
context ".accepts?(:nothing)" do
|
|
33
|
+
it "returns false" do
|
|
34
|
+
expect(described_class.accepts?(:nothing)).to be false
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
context ".accepts?(:text)" do
|
|
38
|
+
it "returns true" do
|
|
39
|
+
expect(described_class.accepts?(:text)).to be true
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
context ".accepts?(:time)" do
|
|
43
|
+
it "returns false" do
|
|
44
|
+
expect(described_class.accepts?(:time)).to be false
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
context ".accepts?(:url)" do
|
|
48
|
+
it "returns true" do
|
|
49
|
+
expect(described_class.accepts?(:url)).to be true
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
context ".accepts?(:xml)" do
|
|
53
|
+
it "returns false" do
|
|
54
|
+
expect(described_class.accepts?(:xml)).to be false
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
context ".output_for(:atom)" do
|
|
58
|
+
it "returns :nothing" do
|
|
59
|
+
expect(described_class.output_for(:atom)).to be :nothing
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
context ".output_for(:document)" do
|
|
63
|
+
it "returns :nothing" do
|
|
64
|
+
expect(described_class.output_for(:document)).to be :nothing
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
context ".output_for(:html)" do
|
|
68
|
+
it "returns :nothing" do
|
|
69
|
+
expect(described_class.output_for(:html)).to be :nothing
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
context ".output_for(:json)" do
|
|
73
|
+
it "returns :nothing" do
|
|
74
|
+
expect(described_class.output_for(:json)).to be :nothing
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
context ".output_for(:markdown)" do
|
|
78
|
+
it "returns :nothing" do
|
|
79
|
+
expect(described_class.output_for(:markdown)).to be :nothing
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
context ".output_for(:text)" do
|
|
83
|
+
it "returns :document" do
|
|
84
|
+
expect(described_class.output_for(:text)).to be :document
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
context ".output_for(:time)" do
|
|
88
|
+
it "returns :nothing" do
|
|
89
|
+
expect(described_class.output_for(:time)).to be :nothing
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
context ".output_for(:url)" do
|
|
93
|
+
it "returns :document" do
|
|
94
|
+
expect(described_class.output_for(:url)).to be :document
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
context ".output_for(:xml)" do
|
|
98
|
+
it "returns :nothing" do
|
|
99
|
+
expect(described_class.output_for(:xml)).to be :nothing
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
context ".returns_multiple_items?" do
|
|
103
|
+
it "returns false" do
|
|
104
|
+
expect(described_class.returns_multiple_items?).to be false
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
context ".new()" do
|
|
108
|
+
it "raises no errors" do
|
|
109
|
+
expect { described_class.new }.to_not raise_error
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
context "#run(nil)" do
|
|
113
|
+
it "raises InvalidInput" do
|
|
114
|
+
expect { subject.run(nil) }.to raise_error Saper::InvalidInput
|
|
115
|
+
end
|
|
9
116
|
end
|
|
10
117
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require './spec/spec_helper'
|
|
2
2
|
|
|
3
|
-
describe Saper::Actions::FindFirst do
|
|
3
|
+
RSpec.describe Saper::Actions::FindFirst do
|
|
4
4
|
subject do
|
|
5
5
|
Saper::Actions::FindFirst.new("//p")
|
|
6
6
|
end
|
|
@@ -13,38 +13,163 @@ describe Saper::Actions::FindFirst do
|
|
|
13
13
|
let :json do
|
|
14
14
|
Saper::Items::JSON.new('{"p":{"a":0}}')
|
|
15
15
|
end
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
context ".type" do
|
|
17
|
+
it "returns find_first" do
|
|
18
|
+
expect(described_class.type).to eq 'find_first'
|
|
19
|
+
end
|
|
18
20
|
end
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
context ".accepts?(:atom)" do
|
|
22
|
+
it "returns false" do
|
|
23
|
+
expect(described_class.accepts?(:atom)).to be false
|
|
24
|
+
end
|
|
21
25
|
end
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
context ".accepts?(:html)" do
|
|
27
|
+
it "returns true" do
|
|
28
|
+
expect(described_class.accepts?(:html)).to be true
|
|
29
|
+
end
|
|
24
30
|
end
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
context ".accepts?(:json)" do
|
|
32
|
+
it "returns true" do
|
|
33
|
+
expect(described_class.accepts?(:json)).to be true
|
|
34
|
+
end
|
|
27
35
|
end
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
context ".accepts?(:markdown)" do
|
|
37
|
+
it "returns false" do
|
|
38
|
+
expect(described_class.accepts?(:markdown)).to be false
|
|
39
|
+
end
|
|
30
40
|
end
|
|
31
|
-
|
|
32
|
-
|
|
41
|
+
context ".accepts?(:nothing)" do
|
|
42
|
+
it "returns false" do
|
|
43
|
+
expect(described_class.accepts?(:nothing)).to be false
|
|
44
|
+
end
|
|
33
45
|
end
|
|
34
|
-
|
|
35
|
-
|
|
46
|
+
context ".accepts?(:text)" do
|
|
47
|
+
it "returns false" do
|
|
48
|
+
expect(described_class.accepts?(:text)).to be false
|
|
49
|
+
end
|
|
36
50
|
end
|
|
37
|
-
|
|
38
|
-
|
|
51
|
+
context ".accepts?(:time)" do
|
|
52
|
+
it "returns false" do
|
|
53
|
+
expect(described_class.accepts?(:time)).to be false
|
|
54
|
+
end
|
|
39
55
|
end
|
|
40
|
-
|
|
41
|
-
|
|
56
|
+
context ".accepts?(:url)" do
|
|
57
|
+
it "returns false" do
|
|
58
|
+
expect(described_class.accepts?(:url)).to be false
|
|
59
|
+
end
|
|
42
60
|
end
|
|
43
|
-
|
|
44
|
-
|
|
61
|
+
context ".accepts?(:xml)" do
|
|
62
|
+
it "returns true" do
|
|
63
|
+
expect(described_class.accepts?(:xml)).to be true
|
|
64
|
+
end
|
|
45
65
|
end
|
|
46
|
-
|
|
47
|
-
|
|
66
|
+
context ".output_for(:atom)" do
|
|
67
|
+
it "returns :nothing" do
|
|
68
|
+
expect(described_class.output_for(:atom)).to be :nothing
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
context ".output_for(:document)" do
|
|
72
|
+
it "returns :nothing" do
|
|
73
|
+
expect(described_class.output_for(:document)).to be :nothing
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
context ".output_for(:html)" do
|
|
77
|
+
it "returns :html" do
|
|
78
|
+
expect(described_class.output_for(:html)).to be :html
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
context ".output_for(:json)" do
|
|
82
|
+
it "returns :json" do
|
|
83
|
+
expect(described_class.output_for(:json)).to be :json
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
context ".output_for(:markdown)" do
|
|
87
|
+
it "returns :nothing" do
|
|
88
|
+
expect(described_class.output_for(:markdown)).to be :nothing
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
context ".output_for(:text)" do
|
|
92
|
+
it "returns :nothing" do
|
|
93
|
+
expect(described_class.output_for(:text)).to be :nothing
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
context ".output_for(:time)" do
|
|
97
|
+
it "returns :nothing" do
|
|
98
|
+
expect(described_class.output_for(:time)).to be :nothing
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
context ".output_for(:url)" do
|
|
102
|
+
it "returns :nothing" do
|
|
103
|
+
expect(described_class.output_for(:url)).to be :nothing
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
context ".output_for(:xml)" do
|
|
107
|
+
it "returns :xml" do
|
|
108
|
+
expect(described_class.output_for(:xml)).to be :xml
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
context ".returns_multiple_items?" do
|
|
112
|
+
it "returns false" do
|
|
113
|
+
expect(described_class.returns_multiple_items?).to be false
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
context ".new(nil)" do
|
|
117
|
+
it "raises InvalidArgument" do
|
|
118
|
+
expect { described_class.new(nil) }.to raise_error Saper::InvalidArgument
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
context ".new(Numeric)" do
|
|
122
|
+
it "raises InvalidArgument" do
|
|
123
|
+
expect { described_class.new(1) }.to raise_error Saper::InvalidArgument
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
context ".new(Hash)" do
|
|
127
|
+
it "raises InvalidArgument" do
|
|
128
|
+
expect { described_class.new({}) }.to raise_error Saper::InvalidArgument
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
context ".new(Array)" do
|
|
132
|
+
it "raises InvalidArgument" do
|
|
133
|
+
expect { described_class.new([]) }.to raise_error Saper::InvalidArgument
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
context ".new(CSS)" do
|
|
137
|
+
it "raises no errors" do
|
|
138
|
+
expect { described_class.new("a") }.to_not raise_error
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
context ".new(Saper::Arguments::XPath)" do
|
|
142
|
+
it "raises no errors" do
|
|
143
|
+
expect { described_class.new(Saper::Arguments::XPath.new(:value => "a")) }.to_not raise_error
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
context "#run(nil)" do
|
|
147
|
+
it "raises InvalidInput" do
|
|
148
|
+
expect { subject.run(nil) }.to raise_error Saper::InvalidInput
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
context "#run(String)" do
|
|
152
|
+
it "returns HTML instance" do
|
|
153
|
+
expect(subject.run(string)).to be_a Saper::Items::HTML
|
|
154
|
+
end
|
|
155
|
+
it "returns valid output" do
|
|
156
|
+
expect(subject.run(string).to_s).to eq '<p>test</p>'
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
context "#run(HTML)" do
|
|
160
|
+
it "returns HTML instance" do
|
|
161
|
+
expect(subject.run(html)).to be_a Saper::Items::HTML
|
|
162
|
+
end
|
|
163
|
+
it "returns valid output" do
|
|
164
|
+
expect(subject.run(html).to_s).to eq '<p>test</p>'
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
context "#run(JSON)" do
|
|
168
|
+
it "returns JSON instance" do
|
|
169
|
+
expect(subject.run(json)).to be_a Saper::Items::JSON
|
|
170
|
+
end
|
|
171
|
+
it "returns valid output" do
|
|
172
|
+
expect(subject.run(json)).to eq({ "a" => 0 })
|
|
173
|
+
end
|
|
48
174
|
end
|
|
49
|
-
|
|
50
175
|
end
|