saper 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -3
  3. data/Rakefile +7 -5
  4. data/bin/saper +51 -1
  5. data/lib/saper/actions/create_atom.rb +0 -5
  6. data/lib/saper/actions/nothing.rb +2 -0
  7. data/lib/saper/actions/remove_matching.rb +1 -1
  8. data/lib/saper/actions/run_recipe.rb +5 -5
  9. data/lib/saper/actions/run_recipe_and_save.rb +5 -5
  10. data/lib/saper/actions/select_matching.rb +1 -1
  11. data/lib/saper/actions/set_input.rb +0 -5
  12. data/lib/saper/core/action.rb +69 -53
  13. data/lib/saper/core/argument.rb +3 -0
  14. data/lib/saper/core/browser.rb +3 -2
  15. data/lib/saper/core/error.rb +4 -1
  16. data/lib/saper/core/keychain.rb +2 -2
  17. data/lib/saper/core/logger.rb +9 -54
  18. data/lib/saper/core/recipe.rb +36 -5
  19. data/lib/saper/core/result.rb +36 -5
  20. data/lib/saper/core/runtime.rb +17 -11
  21. data/lib/saper/core/stack.rb +17 -1
  22. data/lib/saper/items/html.rb +1 -1
  23. data/lib/saper/items/nothing.rb +9 -0
  24. data/lib/saper/items/xml.rb +5 -1
  25. data/lib/saper/version.rb +1 -1
  26. data/lib/tungsten/lib/README +5 -0
  27. data/lib/tungsten/lib/test.rb +18 -0
  28. data/lib/tungsten/lib/tungsten.rb +33 -0
  29. data/lib/tungsten/lib/tungsten/headers.rb +37 -0
  30. data/lib/tungsten/lib/tungsten/jar.rb +17 -0
  31. data/lib/tungsten/lib/tungsten/request.rb +102 -0
  32. data/lib/tungsten/lib/tungsten/response.rb +101 -0
  33. data/spec/actions/append_with_spec.rb +144 -21
  34. data/spec/actions/convert_to_html_spec.rb +126 -11
  35. data/spec/actions/convert_to_json_spec.rb +126 -11
  36. data/spec/actions/convert_to_markdown_spec.rb +126 -11
  37. data/spec/actions/convert_to_time_spec.rb +150 -15
  38. data/spec/actions/convert_to_xml_spec.rb +136 -11
  39. data/spec/actions/create_atom_spec.rb +116 -7
  40. data/spec/actions/fetch_spec.rb +110 -3
  41. data/spec/actions/find_first_spec.rb +149 -24
  42. data/spec/actions/find_spec.rb +167 -19
  43. data/spec/actions/get_attribute_spec.rb +145 -15
  44. data/spec/actions/get_contents_spec.rb +125 -4
  45. data/spec/actions/get_text_spec.rb +125 -4
  46. data/spec/actions/nothing_spec.rb +119 -4
  47. data/spec/actions/prepend_with_spec.rb +148 -22
  48. data/spec/actions/remove_after_spec.rb +160 -4
  49. data/spec/actions/remove_before_spec.rb +160 -4
  50. data/spec/actions/remove_matching_spec.rb +164 -4
  51. data/spec/actions/remove_tags_spec.rb +1 -1
  52. data/spec/actions/replace_spec.rb +1 -1
  53. data/spec/actions/run_recipe_and_save_spec.rb +1 -1
  54. data/spec/actions/run_recipe_spec.rb +1 -1
  55. data/spec/actions/save_spec.rb +1 -1
  56. data/spec/actions/select_matching_spec.rb +164 -4
  57. data/spec/actions/set_input_spec.rb +1 -1
  58. data/spec/actions/skip_tags_spec.rb +1 -1
  59. data/spec/actions/split_spec.rb +1 -1
  60. data/spec/arguments/attribute_spec.rb +1 -1
  61. data/spec/arguments/recipe_spec.rb +1 -1
  62. data/spec/arguments/text_spec.rb +1 -1
  63. data/spec/arguments/timezone_spec.rb +1 -1
  64. data/spec/arguments/variable_spec.rb +1 -1
  65. data/spec/arguments/xpath_spec.rb +1 -1
  66. data/spec/core/action_spec.rb +25 -13
  67. data/spec/core/argument_spec.rb +55 -31
  68. data/spec/core/browser_spec.rb +21 -11
  69. data/spec/core/dsl_spec.rb +1 -1
  70. data/spec/core/item_spec.rb +1 -1
  71. data/spec/core/keychain_spec.rb +1 -1
  72. data/spec/core/logger_spec.rb +1 -1
  73. data/spec/core/namespace_spec.rb +1 -1
  74. data/spec/core/recipe_spec.rb +85 -51
  75. data/spec/core/result_spec.rb +1 -1
  76. data/spec/core/runtime_spec.rb +45 -27
  77. data/spec/core/stack_spec.rb +1 -1
  78. data/spec/core/type_spec.rb +1 -1
  79. data/spec/integration/simple_invalid_spec.rb +46 -9
  80. data/spec/integration/simple_valid_spec.rb +9 -9
  81. data/spec/items/atom_spec.rb +7 -7
  82. data/spec/items/document_spec.rb +29 -29
  83. data/spec/items/html_spec.rb +80 -48
  84. data/spec/items/json_spec.rb +17 -11
  85. data/spec/items/markdown_spec.rb +30 -18
  86. data/spec/items/nothing_spec.rb +1 -1
  87. data/spec/items/text_spec.rb +12 -10
  88. data/spec/items/time_spec.rb +35 -21
  89. data/spec/items/url_spec.rb +1 -1
  90. data/spec/items/xml_spec.rb +75 -42
  91. data/spec/spec_helper.rb +90 -2
  92. metadata +51 -16
@@ -1,35 +1,183 @@
1
1
  require './spec/spec_helper'
2
2
 
3
- describe Saper::Actions::Find do
4
- let :subject do
3
+ RSpec.describe Saper::Actions::Find do
4
+ subject do
5
5
  Saper::Actions::Find.new("//p")
6
6
  end
7
+ let :string do
8
+ '<html><body><div><p>test</p><p>test</p></div></body></html>'
9
+ end
7
10
  let :html do
8
- Saper::Items::HTML.new('<div><p>test</p><p>test</p></div>')
11
+ Saper::Items::HTML.new(string)
12
+ end
13
+ let :non_matching_html do
14
+ Saper::Items::HTML.new("<html><body><div></div></body></html>")
9
15
  end
10
16
  let :json do
11
17
  Saper::Items::JSON.new('{"p":{"a":0},"z":{"a":1}}')
12
18
  end
13
- it ".new(nil) raises InvalidArgument" do
14
- lambda { Saper::Actions::Find.new(nil) }.must_raise(Saper::InvalidArgument)
19
+ context ".type" do
20
+ it "returns find" do
21
+ expect(described_class.type).to eq 'find'
22
+ end
23
+ end
24
+ context ".accepts?(:atom)" do
25
+ it "returns false" do
26
+ expect(described_class.accepts?(:atom)).to be false
27
+ end
28
+ end
29
+ context ".accepts?(:html)" do
30
+ it "returns true" do
31
+ expect(described_class.accepts?(:html)).to be true
32
+ end
33
+ end
34
+ context ".accepts?(:json)" do
35
+ it "returns true" do
36
+ expect(described_class.accepts?(:json)).to be true
37
+ end
38
+ end
39
+ context ".accepts?(:markdown)" do
40
+ it "returns false" do
41
+ expect(described_class.accepts?(:markdown)).to be false
42
+ end
43
+ end
44
+ context ".accepts?(:nothing)" do
45
+ it "returns false" do
46
+ expect(described_class.accepts?(:nothing)).to be false
47
+ end
48
+ end
49
+ context ".accepts?(:text)" do
50
+ it "returns false" do
51
+ expect(described_class.accepts?(:text)).to be false
52
+ end
53
+ end
54
+ context ".accepts?(:time)" do
55
+ it "returns false" do
56
+ expect(described_class.accepts?(:time)).to be false
57
+ end
58
+ end
59
+ context ".accepts?(:url)" do
60
+ it "returns false" do
61
+ expect(described_class.accepts?(:url)).to be false
62
+ end
63
+ end
64
+ context ".accepts?(:xml)" do
65
+ it "returns true" do
66
+ expect(described_class.accepts?(:xml)).to be true
67
+ end
68
+ end
69
+ context ".output_for(:atom)" do
70
+ it "returns :nothing" do
71
+ expect(described_class.output_for(:atom)).to be :nothing
72
+ end
73
+ end
74
+ context ".output_for(:document)" do
75
+ it "returns :nothing" do
76
+ expect(described_class.output_for(:document)).to be :nothing
77
+ end
78
+ end
79
+ context ".output_for(:html)" do
80
+ it "returns :html" do
81
+ expect(described_class.output_for(:html)).to be :html
82
+ end
83
+ end
84
+ context ".output_for(:json)" do
85
+ it "returns :json" do
86
+ expect(described_class.output_for(:json)).to be :json
87
+ end
88
+ end
89
+ context ".output_for(:markdown)" do
90
+ it "returns :nothing" do
91
+ expect(described_class.output_for(:markdown)).to be :nothing
92
+ end
93
+ end
94
+ context ".output_for(:text)" do
95
+ it "returns :nothing" do
96
+ expect(described_class.output_for(:text)).to be :nothing
97
+ end
98
+ end
99
+ context ".output_for(:time)" do
100
+ it "returns :nothing" do
101
+ expect(described_class.output_for(:time)).to be :nothing
102
+ end
103
+ end
104
+ context ".output_for(:url)" do
105
+ it "returns :nothing" do
106
+ expect(described_class.output_for(:url)).to be :nothing
107
+ end
108
+ end
109
+ context ".output_for(:xml)" do
110
+ it "returns :xml" do
111
+ expect(described_class.output_for(:xml)).to be :xml
112
+ end
113
+ end
114
+ context ".returns_multiple_items?" do
115
+ it "returns true" do
116
+ expect(described_class.returns_multiple_items?).to be true
117
+ end
118
+ end
119
+ context ".new(nil)" do
120
+ it "raises InvalidArgument" do
121
+ expect { described_class.new(nil) }.to raise_error Saper::InvalidArgument
122
+ end
123
+ end
124
+ context ".new(Numeric)" do
125
+ it "raises InvalidArgument" do
126
+ expect { described_class.new(1) }.to raise_error Saper::InvalidArgument
127
+ end
128
+ end
129
+ context ".new(Hash)" do
130
+ it "raises InvalidArgument" do
131
+ expect { described_class.new({}) }.to raise_error Saper::InvalidArgument
132
+ end
133
+ end
134
+ context ".new(Array)" do
135
+ it "raises InvalidArgument" do
136
+ expect { described_class.new([]) }.to raise_error Saper::InvalidArgument
137
+ end
138
+ end
139
+ context ".new(CSS)" do
140
+ it "raises no errors" do
141
+ expect { described_class.new("a") }.to_not raise_error
142
+ end
143
+ end
144
+ context ".new(Saper::Arguments::XPath)" do
145
+ it "raises no errors" do
146
+ expect { described_class.new(Saper::Arguments::XPath.new(:value => "a")) }.to_not raise_error
147
+ end
15
148
  end
16
- it ".new(CSS) raises no errors" do
17
- lambda { Saper::Actions::Find.new("a") }.must_be_silent
149
+ context "#run(nil)" do
150
+ it "raises InvalidInput" do
151
+ expect { subject.run(nil) }.to raise_error Saper::InvalidInput
152
+ end
18
153
  end
19
- it "#run(nil) raises InvalidInput" do
20
- lambda { subject.run(nil) }.must_raise(Saper::InvalidInput)
21
- end
22
- it "#run(HTML) returns an array of results" do
23
- subject.run(html).must_be_instance_of(Array)
154
+ context "#run(String)" do
155
+ it "returns an array of results" do
156
+ expect(subject.run(string)).to be_a Array
157
+ end
158
+ it "returns valid output" do
159
+ expect(subject.run(string).first.to_s).to eq '<p>test</p>'
160
+ end
24
161
  end
25
- it "#run(HTML) returns an array with first item an HTML instance" do
26
- subject.run(html).first.must_be_instance_of(Saper::Items::HTML)
162
+ context "#run(HTML)" do
163
+ it "returns an array of results" do
164
+ expect(subject.run(html)).to be_a Array
165
+ end
166
+ it "returns valid output" do
167
+ expect(subject.run(html).first.to_s).to eq '<p>test</p>'
168
+ end
27
169
  end
28
- it "#run(JSON) returns an array of results" do
29
- subject.run(json).must_be_instance_of(Array)
170
+ context "#run(JSON)" do
171
+ it "returns an array of results" do
172
+ expect(subject.run(json)).to be_a Array
173
+ end
174
+ it "returns valid output" do
175
+ expect(subject.run(json).first.to_s).to eq '{"a":0}'
176
+ end
30
177
  end
31
- it "#run(JSON) returns an array with first item a JSON instance" do
32
- subject.run(json).first.must_be_instance_of(Saper::Items::JSON)
178
+ context "#run(non-matching HTML)" do
179
+ it "raises InvalidOutput" do
180
+ expect { subject.run(non_matching_html) }.to raise_error Saper::InvalidOutput
181
+ end
33
182
  end
34
-
35
183
  end
@@ -1,6 +1,6 @@
1
1
  require './spec/spec_helper'
2
2
 
3
- describe Saper::Actions::GetAttribute do
3
+ RSpec.describe Saper::Actions::GetAttribute do
4
4
  let :subject do
5
5
  Saper::Actions::GetAttribute.new("class")
6
6
  end
@@ -10,25 +10,155 @@ describe Saper::Actions::GetAttribute do
10
10
  let :xml do
11
11
  Saper::Items::XML.new('<item class="ok"></item>').find("item")
12
12
  end
13
- it ".new(nil) raises InvalidArgument" do
14
- lambda { Saper::Actions::GetAttribute.new(nil) }.must_raise(Saper::InvalidArgument)
13
+ context ".type" do
14
+ it "returns get_attribute" do
15
+ expect(described_class.type).to eq 'get_attribute'
16
+ end
15
17
  end
16
- it ".new(String) raises no errors" do
17
- lambda { Saper::Actions::GetAttribute.new("a") }.must_be_silent
18
+ context ".accepts?(:atom)" do
19
+ it "returns false" do
20
+ expect(described_class.accepts?(:atom)).to be false
21
+ end
18
22
  end
19
- it "#run(nil) raises InvalidInput" do
20
- lambda { subject.run(nil) }.must_raise(Saper::InvalidInput)
23
+ context ".accepts?(:html)" do
24
+ it "returns true" do
25
+ expect(described_class.accepts?(:html)).to be true
26
+ end
21
27
  end
22
- it "#run(HTML) returns Text instance" do
23
- subject.run(html).must_be_instance_of(Saper::Items::Text)
28
+ context ".accepts?(:json)" do
29
+ it "returns false" do
30
+ expect(described_class.accepts?(:json)).to be false
31
+ end
24
32
  end
25
- it "#run(HTML) returns valid output" do
26
- subject.run(html).must_be :==, 'ok'
33
+ context ".accepts?(:markdown)" do
34
+ it "returns false" do
35
+ expect(described_class.accepts?(:markdown)).to be false
36
+ end
27
37
  end
28
- it "#run(XML) returns Text instance" do
29
- subject.run(xml).must_be_instance_of(Saper::Items::Text)
38
+ context ".accepts?(:nothing)" do
39
+ it "returns false" do
40
+ expect(described_class.accepts?(:nothing)).to be false
41
+ end
30
42
  end
31
- it "#run(XML) returns valid output" do
32
- subject.run(xml).must_be :==, 'ok'
43
+ context ".accepts?(:text)" do
44
+ it "returns false" do
45
+ expect(described_class.accepts?(:text)).to be false
46
+ end
47
+ end
48
+ context ".accepts?(:time)" do
49
+ it "returns false" do
50
+ expect(described_class.accepts?(:time)).to be false
51
+ end
52
+ end
53
+ context ".accepts?(:url)" do
54
+ it "returns false" do
55
+ expect(described_class.accepts?(:url)).to be false
56
+ end
57
+ end
58
+ context ".accepts?(:xml)" do
59
+ it "returns true" do
60
+ expect(described_class.accepts?(:xml)).to be true
61
+ end
62
+ end
63
+ context ".output_for(:atom)" do
64
+ it "returns :nothing" do
65
+ expect(described_class.output_for(:atom)).to be :nothing
66
+ end
67
+ end
68
+ context ".output_for(:document)" do
69
+ it "returns :nothing" do
70
+ expect(described_class.output_for(:document)).to be :nothing
71
+ end
72
+ end
73
+ context ".output_for(:html)" do
74
+ it "returns :text" do
75
+ expect(described_class.output_for(:html)).to be :text
76
+ end
77
+ end
78
+ context ".output_for(:json)" do
79
+ it "returns :nothing" do
80
+ expect(described_class.output_for(:json)).to be :nothing
81
+ end
82
+ end
83
+ context ".output_for(:markdown)" do
84
+ it "returns :nothing" do
85
+ expect(described_class.output_for(:markdown)).to be :nothing
86
+ end
87
+ end
88
+ context ".output_for(:text)" do
89
+ it "returns :nothing" do
90
+ expect(described_class.output_for(:text)).to be :nothing
91
+ end
92
+ end
93
+ context ".output_for(:time)" do
94
+ it "returns :nothing" do
95
+ expect(described_class.output_for(:time)).to be :nothing
96
+ end
97
+ end
98
+ context ".output_for(:url)" do
99
+ it "returns :nothing" do
100
+ expect(described_class.output_for(:url)).to be :nothing
101
+ end
102
+ end
103
+ context ".output_for(:xml)" do
104
+ it "returns :text" do
105
+ expect(described_class.output_for(:xml)).to be :text
106
+ end
107
+ end
108
+ context ".returns_multiple_items?" do
109
+ it "returns false" do
110
+ expect(described_class.returns_multiple_items?).to be false
111
+ end
112
+ end
113
+ context ".new(nil)" do
114
+ it "raises InvalidArgument" do
115
+ expect { described_class.new(nil) }.to raise_error Saper::InvalidArgument
116
+ end
117
+ end
118
+ context ".new(Numeric)" do
119
+ it "raises InvalidArgument" do
120
+ expect { described_class.new(1) }.to raise_error Saper::InvalidArgument
121
+ end
122
+ end
123
+ context ".new(Hash)" do
124
+ it "raises InvalidArgument" do
125
+ expect { described_class.new({}) }.to raise_error Saper::InvalidArgument
126
+ end
127
+ end
128
+ context ".new(Array)" do
129
+ it "raises InvalidArgument" do
130
+ expect { described_class.new([]) }.to raise_error Saper::InvalidArgument
131
+ end
132
+ end
133
+ context ".new(String)" do
134
+ it "raises no errors" do
135
+ expect { described_class.new("a") }.to_not raise_error
136
+ end
137
+ end
138
+ context ".new(Text)" do
139
+ it "raises no errors" do
140
+ expect { described_class.new(Saper::Arguments::Text.new(:value => "a")) }.to_not raise_error
141
+ end
142
+ end
143
+ context "#run(nil)" do
144
+ it "raises InvalidInput" do
145
+ expect { subject.run(nil) }.to raise_error(Saper::InvalidInput)
146
+ end
147
+ end
148
+ context "#run(HTML)" do
149
+ it "returns Text instance" do
150
+ expect(subject.run(html)).to be_a Saper::Items::Text
151
+ end
152
+ it "returns valid output" do
153
+ expect(subject.run(html)).to eq 'ok'
154
+ end
155
+ end
156
+ context "#run(XML)" do
157
+ it "returns Text instance" do
158
+ expect(subject.run(xml)).to be_a Saper::Items::Text
159
+ end
160
+ it "returns valid output" do
161
+ expect(subject.run(xml)).to eq 'ok'
162
+ end
33
163
  end
34
164
  end
@@ -1,7 +1,128 @@
1
1
  require './spec/spec_helper'
2
2
 
3
- describe Saper::Actions::GetContents do
4
-
5
- it # TODO
6
-
3
+ RSpec.describe Saper::Actions::GetContents do
4
+ subject do
5
+ Saper::Actions::GetContents.new()
6
+ end
7
+ let :html do
8
+ Saper::Items::HTML.new("<html><body><p>test</p></body></html>")
9
+ end
10
+ context ".type" do
11
+ it "returns get_contents" do
12
+ expect(described_class.type).to eq 'get_contents'
13
+ end
14
+ end
15
+ context ".accepts?(:atom)" do
16
+ it "returns false" do
17
+ expect(described_class.accepts?(:atom)).to be false
18
+ end
19
+ end
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 false" do
27
+ expect(described_class.accepts?(:json)).to be false
28
+ end
29
+ end
30
+ context ".accepts?(:markdown)" do
31
+ it "returns false" do
32
+ expect(described_class.accepts?(:markdown)).to be false
33
+ end
34
+ end
35
+ context ".accepts?(:nothing)" do
36
+ it "returns false" do
37
+ expect(described_class.accepts?(:nothing)).to be false
38
+ end
39
+ end
40
+ context ".accepts?(:text)" do
41
+ it "returns false" do
42
+ expect(described_class.accepts?(:text)).to be false
43
+ end
44
+ end
45
+ context ".accepts?(:time)" do
46
+ it "returns false" do
47
+ expect(described_class.accepts?(:time)).to be false
48
+ end
49
+ end
50
+ context ".accepts?(:url)" do
51
+ it "returns false" do
52
+ expect(described_class.accepts?(:url)).to be false
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 :nothing" do
62
+ expect(described_class.output_for(:atom)).to be :nothing
63
+ end
64
+ end
65
+ context ".output_for(:document)" do
66
+ it "returns :nothing" do
67
+ expect(described_class.output_for(:document)).to be :nothing
68
+ end
69
+ end
70
+ context ".output_for(:html)" do
71
+ it "returns :text" do
72
+ expect(described_class.output_for(:html)).to be :text
73
+ end
74
+ end
75
+ context ".output_for(:json)" do
76
+ it "returns :nothing" do
77
+ expect(described_class.output_for(:json)).to be :nothing
78
+ end
79
+ end
80
+ context ".output_for(:markdown)" do
81
+ it "returns :nothing" do
82
+ expect(described_class.output_for(:markdown)).to be :nothing
83
+ end
84
+ end
85
+ context ".output_for(:text)" do
86
+ it "returns :nothing" do
87
+ expect(described_class.output_for(:text)).to be :nothing
88
+ end
89
+ end
90
+ context ".output_for(:time)" do
91
+ it "returns :nothing" do
92
+ expect(described_class.output_for(:time)).to be :nothing
93
+ end
94
+ end
95
+ context ".output_for(:url)" do
96
+ it "returns :nothing" do
97
+ expect(described_class.output_for(:url)).to be :nothing
98
+ end
99
+ end
100
+ context ".output_for(:xml)" do
101
+ it "returns :text" do
102
+ expect(described_class.output_for(:xml)).to be :text
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(nil)" do
111
+ it "raises no errors" do
112
+ expect { described_class.new(nil) }.to_not raise_error
113
+ end
114
+ end
115
+ context "#run(nil)" do
116
+ it "raises InvalidInput" do
117
+ expect { subject.run(nil) }.to raise_error Saper::InvalidInput
118
+ end
119
+ end
120
+ context "#run(HTML)" do
121
+ it "returns HTML instance" do
122
+ expect(subject.run(html)).to be_a Saper::Items::Text
123
+ end
124
+ it "returns valid output" do
125
+ expect(subject.run(html).to_s).to eq '<html><body><p>test</p></body></html>'
126
+ end
127
+ end
7
128
  end