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.
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,22 +1,137 @@
1
1
  require './spec/spec_helper'
2
2
 
3
- describe Saper::Actions::ConvertToJSON do
3
+ RSpec.describe Saper::Actions::ConvertToJSON do
4
4
  let :subject do
5
5
  Saper::Actions::ConvertToJSON.new
6
6
  end
7
- it "#run(nil) raises InvalidInput" do
8
- lambda { subject.run(nil) }.must_raise(Saper::InvalidInput)
7
+ context ".type" do
8
+ it "returns convert_to_json" do
9
+ expect(described_class.type).to eq 'convert_to_json'
10
+ end
9
11
  end
10
- it "#run(Numeric) raises InvalidInput" do
11
- lambda { subject.run(2) }.must_raise(Saper::InvalidInput)
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
- it "#run(invalid String) raises InvalidInput" do
14
- subject.run('not json').must_be_nil
17
+ context ".accepts?(:document)" do
18
+ it "returns false" do
19
+ expect(described_class.accepts?(:document)).to be true
20
+ end
15
21
  end
16
- it "#run(valid String) returns JSON instance" do
17
- subject.run('{"test":"ok"}').must_be_instance_of(Saper::Items::JSON)
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
- it "#run(valid Text) returns JSON instance" do
20
- subject.run(Saper::Items::Text.new('{"test":"ok"}')).must_be_instance_of(Saper::Items::JSON)
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 :nothing" do
69
+ expect(described_class.output_for(:document)).to be :json
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 :text" do
89
+ expect(described_class.output_for(:text)).to be :json
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 "#run(nil)" do
113
+ it "raises InvalidInput" do
114
+ expect { subject.run(nil) }.to raise_error Saper::InvalidInput
115
+ end
116
+ end
117
+ context "#run(Numeric)" do
118
+ it "raises InvalidInput" do
119
+ expect { subject.run(2) }.to raise_error Saper::InvalidInput
120
+ end
121
+ end
122
+ context "#run(invalid String)" do
123
+ it "raises InvalidOutput" do
124
+ expect { subject.run('not json') }.to raise_error Saper::InvalidOutput
125
+ end
126
+ end
127
+ context "#run(valid String)" do
128
+ it "returns JSON instance" do
129
+ expect(subject.run('{"test":"ok"}')).to be_a Saper::Items::JSON
130
+ end
131
+ end
132
+ context "#run(valid Text)" do
133
+ it "returns JSON instance" do
134
+ expect(subject.run(Saper::Items::Text.new('{"test":"ok"}'))).to be_a Saper::Items::JSON
135
+ end
21
136
  end
22
137
  end
@@ -1,25 +1,140 @@
1
1
  require './spec/spec_helper'
2
2
 
3
- describe Saper::Actions::ConvertToMarkdown do
3
+ RSpec.describe Saper::Actions::ConvertToMarkdown do
4
4
  let :subject do
5
5
  Saper::Actions::ConvertToMarkdown.new
6
6
  end
7
7
  let :html do
8
8
  Saper::Items::HTML.new('<p>test</p>')
9
9
  end
10
- it "#run(nil) raises InvalidInput" do
11
- lambda { subject.run(nil) }.must_raise(Saper::InvalidInput)
10
+ context ".type" do
11
+ it "returns convert_to_markdown" do
12
+ expect(described_class.type).to eq 'convert_to_markdown'
13
+ end
12
14
  end
13
- it "#run(Numeric) raises InvalidInput" do
14
- lambda { subject.run(2) }.must_raise(Saper::InvalidInput)
15
+ context ".accepts?(:atom)" do
16
+ it "returns false" do
17
+ expect(described_class.accepts?(:atom)).to be false
18
+ end
15
19
  end
16
- it "#run(String) raises InvalidInput" do
17
- subject.run("string").must_be_instance_of(Saper::Items::Markdown)
20
+ context ".accepts?(:document)" do
21
+ it "returns false" do
22
+ expect(described_class.accepts?(:document)).to be false
23
+ end
18
24
  end
19
- it "#run(HTML) returns Markdown instance" do
20
- subject.run(html).must_be_instance_of(Saper::Items::Markdown)
25
+ context ".accepts?(:html)" do
26
+ it "returns false" do
27
+ expect(described_class.accepts?(:html)).to be true
28
+ end
21
29
  end
22
- it "#run(HTML) returns valid output" do
23
- subject.run(html).must_be :==, "test"
30
+ context ".accepts?(:json)" do
31
+ it "returns false" do
32
+ expect(described_class.accepts?(:json)).to be false
33
+ end
34
+ end
35
+ context ".accepts?(:markdown)" do
36
+ it "returns false" do
37
+ expect(described_class.accepts?(:markdown)).to be false
38
+ end
39
+ end
40
+ context ".accepts?(:nothing)" do
41
+ it "returns false" do
42
+ expect(described_class.accepts?(:nothing)).to be false
43
+ end
44
+ end
45
+ context ".accepts?(:text)" do
46
+ it "returns true " do
47
+ expect(described_class.accepts?(:text)).to be false
48
+ end
49
+ end
50
+ context ".accepts?(:time)" do
51
+ it "returns false" do
52
+ expect(described_class.accepts?(:time)).to be false
53
+ end
54
+ end
55
+ context ".accepts?(:url)" do
56
+ it "returns false" do
57
+ expect(described_class.accepts?(:url)).to be false
58
+ end
59
+ end
60
+ context ".accepts?(:xml)" do
61
+ it "returns false" do
62
+ expect(described_class.accepts?(:xml)).to be false
63
+ end
64
+ end
65
+ context ".output_for(:atom)" do
66
+ it "returns :nothing" do
67
+ expect(described_class.output_for(:atom)).to be :nothing
68
+ end
69
+ end
70
+ context ".output_for(:document)" do
71
+ it "returns :nothing" do
72
+ expect(described_class.output_for(:document)).to be :nothing
73
+ end
74
+ end
75
+ context ".output_for(:html)" do
76
+ it "returns :nothing" do
77
+ expect(described_class.output_for(:html)).to be :markdown
78
+ end
79
+ end
80
+ context ".output_for(:json)" do
81
+ it "returns :nothing" do
82
+ expect(described_class.output_for(:json)).to be :nothing
83
+ end
84
+ end
85
+ context ".output_for(:markdown)" do
86
+ it "returns :nothing" do
87
+ expect(described_class.output_for(:markdown)).to be :nothing
88
+ end
89
+ end
90
+ context ".output_for(:text)" do
91
+ it "returns :text" do
92
+ expect(described_class.output_for(:text)).to be :nothing
93
+ end
94
+ end
95
+ context ".output_for(:time)" do
96
+ it "returns :nothing" do
97
+ expect(described_class.output_for(:time)).to be :nothing
98
+ end
99
+ end
100
+ context ".output_for(:url)" do
101
+ it "returns :nothing" do
102
+ expect(described_class.output_for(:url)).to be :nothing
103
+ end
104
+ end
105
+ context ".output_for(:xml)" do
106
+ it "returns :nothing" do
107
+ expect(described_class.output_for(:xml)).to be :nothing
108
+ end
109
+ end
110
+ context ".returns_multiple_items?" do
111
+ it "returns false" do
112
+ expect(described_class.returns_multiple_items?).to be false
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(Numeric)" do
121
+ it "raises InvalidInput" do
122
+ expect { subject.run(2) }.to raise_error Saper::InvalidInput
123
+ end
124
+ end
125
+ context "#run(String)" do
126
+ it "raises InvalidInput" do
127
+ expect(subject.run("string")).to be_a Saper::Items::Markdown
128
+ end
129
+ end
130
+ context "#run(HTML)" do
131
+ it "returns Markdown instance" do
132
+ expect(subject.run(html)).to be_a Saper::Items::Markdown
133
+ end
134
+ end
135
+ context "#run(HTML)" do
136
+ it "returns valid output" do
137
+ expect(subject.run(html)).to eq "test"
138
+ end
24
139
  end
25
140
  end
@@ -1,6 +1,6 @@
1
1
  require './spec/spec_helper'
2
2
 
3
- describe Saper::Actions::ConvertToTime do
3
+ RSpec.describe Saper::Actions::ConvertToTime do
4
4
  let(:subject_without_tz) do
5
5
  Saper::Actions::ConvertToTime.new('%d-%m-%Y %H:%M')
6
6
  end
@@ -10,25 +10,160 @@ describe Saper::Actions::ConvertToTime do
10
10
  let(:input) do
11
11
  '19-04-2014 18:56'
12
12
  end
13
- it ".new(nil, nil) raises InvalidArgument" do
14
- lambda { Saper::Actions::ConvertToTime.new }.must_raise(Saper::InvalidArgument)
13
+ context ".type" do
14
+ it "returns convert_to_time" do
15
+ expect(described_class.type).to eq 'convert_to_time'
16
+ end
15
17
  end
16
- it ".new(format, nil) raises no errors" do
17
- lambda { Saper::Actions::ConvertToTime.new("%H") }.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_without_tz.run(nil) }.must_raise(Saper::InvalidInput)
23
+ context ".accepts?(:document)" do
24
+ it "returns false" do
25
+ expect(described_class.accepts?(:document)).to be false
26
+ end
21
27
  end
22
- it "#run(valid String) returns valid output with defined TZ" do
23
- subject_with_tz.run(input).to_s.must_be :==, '2014-04-19T18:56:00+04:00'
28
+ context ".accepts?(:html)" do
29
+ it "returns false" do
30
+ expect(described_class.accepts?(:html)).to be false
31
+ end
24
32
  end
25
- it "#run(valid String) returns valid output with undefined TZ" do
26
- subject_without_tz.run(input).to_s.must_be :==, '2014-04-19T18:56:00+00:00'
33
+ context ".accepts?(:json)" do
34
+ it "returns false" do
35
+ expect(described_class.accepts?(:json)).to be false
36
+ end
27
37
  end
28
- it "#run(valid String) returns Time instance" do
29
- subject_with_tz.run(input).must_be_instance_of(Saper::Items::Time)
38
+ context ".accepts?(:markdown)" do
39
+ it "returns false" do
40
+ expect(described_class.accepts?(:markdown)).to be false
41
+ end
30
42
  end
31
- it "#run(invalid String) raises InvalidItem" do
32
- lambda { subject_with_tz.run("ABCDEF") }.must_raise(Saper::InvalidItem)
43
+ context ".accepts?(:nothing)" do
44
+ it "returns false" do
45
+ expect(described_class.accepts?(:nothing)).to be false
46
+ end
47
+ end
48
+ context ".accepts?(:text)" do
49
+ it "returns true " do
50
+ expect(described_class.accepts?(:text)).to be true
51
+ end
52
+ end
53
+ context ".accepts?(:time)" do
54
+ it "returns false" do
55
+ expect(described_class.accepts?(:time)).to be false
56
+ end
57
+ end
58
+ context ".accepts?(:url)" do
59
+ it "returns false" do
60
+ expect(described_class.accepts?(:url)).to be false
61
+ end
62
+ end
63
+ context ".accepts?(:xml)" do
64
+ it "returns false" do
65
+ expect(described_class.accepts?(:xml)).to be false
66
+ end
67
+ end
68
+ context ".output_for(:atom)" do
69
+ it "returns :nothing" do
70
+ expect(described_class.output_for(:atom)).to be :nothing
71
+ end
72
+ end
73
+ context ".output_for(:document)" do
74
+ it "returns :nothing" do
75
+ expect(described_class.output_for(:document)).to be :nothing
76
+ end
77
+ end
78
+ context ".output_for(:html)" do
79
+ it "returns :nothing" do
80
+ expect(described_class.output_for(:html)).to be :nothing
81
+ end
82
+ end
83
+ context ".output_for(:json)" do
84
+ it "returns :nothing" do
85
+ expect(described_class.output_for(:json)).to be :nothing
86
+ end
87
+ end
88
+ context ".output_for(:markdown)" do
89
+ it "returns :nothing" do
90
+ expect(described_class.output_for(:markdown)).to be :nothing
91
+ end
92
+ end
93
+ context ".output_for(:text)" do
94
+ it "returns :time" do
95
+ expect(described_class.output_for(:text)).to be :time
96
+ end
97
+ end
98
+ context ".output_for(:time)" do
99
+ it "returns :nothing" do
100
+ expect(described_class.output_for(:time)).to be :nothing
101
+ end
102
+ end
103
+ context ".output_for(:url)" do
104
+ it "returns :nothing" do
105
+ expect(described_class.output_for(:url)).to be :nothing
106
+ end
107
+ end
108
+ context ".output_for(:xml)" do
109
+ it "returns :nothing" do
110
+ expect(described_class.output_for(:xml)).to be :nothing
111
+ end
112
+ end
113
+ context ".returns_multiple_items?" do
114
+ it "returns false" do
115
+ expect(described_class.returns_multiple_items?).to be false
116
+ end
117
+ end
118
+ context ".new(nil, nil)" do
119
+ it "raises InvalidArgument" do
120
+ expect { described_class.new }.to raise_error Saper::InvalidArgument
121
+ end
122
+ end
123
+ context ".new(format, nil)" do
124
+ it "raises no errors" do
125
+ expect { described_class.new("%H") }.to_not raise_error
126
+ end
127
+ end
128
+ context ".new(Numeric)" do
129
+ it "raises InvalidArgument" do
130
+ expect { described_class.new(2) }.to raise_error Saper::InvalidArgument
131
+ end
132
+ end
133
+ context ".new(Hash)" do
134
+ it "raises InvalidArgumenth" do
135
+ expect { described_class.new({}) }.to raise_error Saper::InvalidArgument
136
+ end
137
+ end
138
+ context ".new(Array)" do
139
+ it "raises InvalidArgument" do
140
+ expect { described_class.new([]) }.to raise_error Saper::InvalidArgument
141
+ end
142
+ end
143
+ context ".new(String)" do
144
+ it "returns Action instance" do
145
+ expect(described_class.new("!")).to be_a Saper::Action
146
+ end
147
+ end
148
+ context "#run(nil)" do
149
+ it "raises InvalidInput" do
150
+ expect { subject_without_tz.run(nil) }.to raise_error Saper::InvalidInput
151
+ end
152
+ end
153
+ context "#run(valid String)" do
154
+ it "returns Time instance" do
155
+ expect(subject_with_tz.run(input)).to be_a Saper::Items::Time
156
+ end
157
+ it "returns valid output with defined TZ" do
158
+ expect(subject_with_tz.run(input).to_s).to eq '2014-04-19T18:56:00+04:00'
159
+ end
160
+ it "returns valid output with undefined TZ" do
161
+ expect(subject_without_tz.run(input).to_s).to eq '2014-04-19T18:56:00+00:00'
162
+ end
163
+ end
164
+ context "#run(invalid String)" do
165
+ it "raises InvalidItem" do
166
+ expect { subject_with_tz.run("ABCDEF") }.to raise_error Saper::InvalidItem
167
+ end
33
168
  end
34
169
  end