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,6 +1,6 @@
1
1
  require './spec/spec_helper'
2
2
 
3
- describe Saper::Actions::SetInput do
3
+ RSpec.describe Saper::Actions::SetInput do
4
4
 
5
5
  it # TODO
6
6
 
@@ -1,6 +1,6 @@
1
1
  require './spec/spec_helper'
2
2
 
3
- describe Saper::Actions::SkipTags do
3
+ RSpec.describe Saper::Actions::SkipTags do
4
4
 
5
5
  it # TODO
6
6
 
@@ -1,6 +1,6 @@
1
1
  require './spec/spec_helper'
2
2
 
3
- describe Saper::Actions::Split do
3
+ RSpec.describe Saper::Actions::Split do
4
4
 
5
5
  it # TODO
6
6
 
@@ -1,6 +1,6 @@
1
1
  require './spec/spec_helper'
2
2
 
3
- describe Saper::Arguments::Attribute do
3
+ RSpec.describe Saper::Arguments::Attribute do
4
4
 
5
5
  it # TODO
6
6
 
@@ -1,6 +1,6 @@
1
1
  require './spec/spec_helper'
2
2
 
3
- describe Saper::Arguments::Recipe do
3
+ RSpec.describe Saper::Arguments::Recipe do
4
4
 
5
5
  it # TODO
6
6
 
@@ -1,6 +1,6 @@
1
1
  require './spec/spec_helper'
2
2
 
3
- describe Saper::Arguments::Text do
3
+ RSpec.describe Saper::Arguments::Text do
4
4
 
5
5
  it # TODO
6
6
 
@@ -1,6 +1,6 @@
1
1
  require './spec/spec_helper'
2
2
 
3
- describe Saper::Arguments::Timezone do
3
+ RSpec.describe Saper::Arguments::Timezone do
4
4
 
5
5
  it # TODO
6
6
 
@@ -1,6 +1,6 @@
1
1
  require './spec/spec_helper'
2
2
 
3
- describe Saper::Arguments::Variable do
3
+ RSpec.describe Saper::Arguments::Variable do
4
4
 
5
5
  it # TODO
6
6
 
@@ -1,6 +1,6 @@
1
1
  require './spec/spec_helper'
2
2
 
3
- describe Saper::Arguments::XPath do
3
+ RSpec.describe Saper::Arguments::XPath do
4
4
 
5
5
  it # TODO
6
6
 
@@ -1,22 +1,34 @@
1
1
  require './spec/spec_helper'
2
2
 
3
- describe Saper::Action do
4
- it ".[] raises ActionNotFound when supplied with invalid type" do
5
- lambda { Saper::Action[:unknown] }.must_raise(Saper::ActionNotFound)
3
+ RSpec.describe Saper::Action do
4
+ context ".[](invalid)" do
5
+ it "raises ActionNotFound" do
6
+ expect { Saper::Action[:unknown] }.to raise_error Saper::ActionNotFound
7
+ end
6
8
  end
7
- it ".new raises ActionNotFound when supplied with invalid type" do
8
- lambda { Saper::Action.new(:unknown) }.must_raise(Saper::ActionNotFound)
9
+ context ".new(invalid)" do
10
+ it "raises ActionNotFound" do
11
+ expect { Saper::Action.new(:unknown) }.to raise_error Saper::ActionNotFound
12
+ end
9
13
  end
10
- it ".new returns Action when supplied with valid type" do
11
- Saper::Action.new(:nothing).must_be_kind_of(Saper::Actions::Nothing)
14
+ context ".new(valid)" do
15
+ it "returns Action" do
16
+ expect(Saper::Action.new(:nothing)).to be_a Saper::Actions::Nothing
17
+ end
12
18
  end
13
- it ".unserialize raises InvalidAction when supplied with nil" do
14
- lambda { Saper::Action.unserialize(nil) }.must_raise(Saper::InvalidAction)
19
+ context ".unserialize(nil)" do
20
+ it "raises InvalidAction" do
21
+ expect { Saper::Action.unserialize(nil) }.to raise_error Saper::InvalidAction
22
+ end
15
23
  end
16
- it ".unserialize returns Action when supplied with a valid Hash" do
17
- Saper::Action.unserialize({ :type => :nothing }).must_be_kind_of(Saper::Action)
24
+ context ".unserialize(Hash)" do
25
+ it "returns Action" do
26
+ expect(Saper::Action.unserialize({ :type => :nothing })).to be_a Saper::Action
27
+ end
18
28
  end
19
- it ".unserialize returns an Array when supplied with an Array" do
20
- Saper::Action.unserialize([{ :type => :nothing }, { :type => :nothing }]).must_be_kind_of(Array)
29
+ context ".unserialize(Array)" do
30
+ it "returns an Array" do
31
+ expect(Saper::Action.unserialize([{ :type => :nothing }, { :type => :nothing }])).to be_a Array
32
+ end
21
33
  end
22
34
  end
@@ -1,46 +1,70 @@
1
1
  require './spec/spec_helper'
2
2
 
3
- describe Saper::Argument do
4
- it ".new raises InvalidArgument when required value is nil" do
5
- lambda { Saper::Argument.new(:text, :value => nil) }.must_raise(Saper::InvalidArgument)
3
+ RSpec.describe Saper::Argument do
4
+ context ".new(:text, nil)" do
5
+ it "raises InvalidArgument" do
6
+ expect { Saper::Argument.new(:text, :value => nil) }.to raise_error Saper::InvalidArgument
7
+ end
6
8
  end
7
- it ".new raises InvalidArgument when required value is missing" do
8
- lambda { Saper::Argument.new(:text) }.must_raise(Saper::InvalidArgument)
9
+ context ".new(:text)" do
10
+ it "raises InvalidArgument" do
11
+ expect { Saper::Argument.new(:text) }.to raise_error Saper::InvalidArgument
12
+ end
9
13
  end
10
- it ".new raises InvalidArgument when required value is invalid" do
11
- lambda { Saper::Argument.new(:text, :value => 1) }.must_raise(Saper::InvalidArgument)
14
+ context ".new(:text, invalid)" do
15
+ it "raises InvalidArgument" do
16
+ expect { Saper::Argument.new(:text, :value => 1) }.to raise_error Saper::InvalidArgument
17
+ end
12
18
  end
13
- it ".new raises no exceptions when required value is valid" do
14
- Saper::Argument.new(:text, :value => "text").must_be_kind_of(Saper::Argument)
19
+ context ".new(:text, valid)" do
20
+ it "raises no exceptions" do
21
+ expect(Saper::Argument.new(:text, :value => "text")).to be_a Saper::Argument
22
+ end
15
23
  end
16
- it ".new raises no exceptions when optional value is missing" do
17
- Saper::Argument.new(:text, :optional => true).must_be_kind_of(Saper::Argument)
24
+ context ".new(:text, optional)" do
25
+ it "raises no exceptions" do
26
+ expect(Saper::Argument.new(:text, :optional => true)).to be_a Saper::Argument
27
+ end
18
28
  end
19
- it ".new raises InvalidArgument when optional value is invalid" do
20
- lambda { Saper::Argument.new(:text, :optional => true, :value => 1) }.must_raise(Saper::InvalidArgument)
29
+ context ".new(:text, optional, invalid)" do
30
+ it "raises InvalidArgument" do
31
+ expect { Saper::Argument.new(:text, :optional => true, :value => 1) }.to raise_error Saper::InvalidArgument
32
+ end
21
33
  end
22
- it ".new returns Action instance when optional value is valid" do
23
- Saper::Argument.new(:text, :optional => true, :value => "text").must_be_kind_of(Saper::Argument)
34
+ context ".new(:text, optional, valid)" do
35
+ it "returns Action instance" do
36
+ expect(Saper::Argument.new(:text, :optional => true, :value => "text")).to be_a Saper::Argument
37
+ end
24
38
  end
25
- it "#set raises InvalidArgument when required value is invalid" do
26
- lambda { Saper::Argument.new(:text, :value => "text").set(1) }.must_raise(Saper::InvalidArgument)
39
+ context "#set(invalid)" do
40
+ it "raises InvalidArgument" do
41
+ expect { Saper::Argument.new(:text, :value => "text").set(1) }.to raise_error Saper::InvalidArgument
42
+ end
27
43
  end
28
- it "#set raises InvalidArgument when optional value is invalid" do
29
- lambda { Saper::Argument.new(:text, :optional => true, :value => "text").set(1) }.must_raise(Saper::InvalidArgument)
44
+ context "#set(optional invalid)" do
45
+ it "raises InvalidArgument" do
46
+ expect { Saper::Argument.new(:text, :optional => true, :value => "text").set(1) }.to raise_error Saper::InvalidArgument
47
+ end
30
48
  end
31
- it "#set returns self when value is valid" do
32
- Saper::Argument.new(:text, :optional => true).set("text").must_be_kind_of(Saper::Argument)
49
+ context "#set(valid)" do
50
+ it "returns self" do
51
+ expect(Saper::Argument.new(:text, :optional => true).set("text")).to be_a Saper::Argument
52
+ end
33
53
  end
34
- it "#value returns nil by default" do
35
- Saper::Argument.new(:text, :optional => true).value.must_be_nil
54
+ context "#value" do
55
+ it "returns nil by default" do
56
+ expect(Saper::Argument.new(:text, :optional => true).value).to be_nil
57
+ end
58
+ it "returns stored value" do
59
+ expect(Saper::Argument.new(:text, :value => "text").value).to eq "text"
60
+ end
36
61
  end
37
- it "#value returns stored value" do
38
- Saper::Argument.new(:text, :value => "text").value.must_equal "text"
39
- end
40
- it "#optional? returns false by default" do
41
- Saper::Argument.new(:text, :value => "text").wont_be :optional?
42
- end
43
- it "#optional? returns true if optionality flag is set" do
44
- Saper::Argument.new(:text, :optional => true).must_be :optional?
62
+ context "#optional?" do
63
+ it "returns false by default" do
64
+ expect(Saper::Argument.new(:text, :value => "text")).to_not be_optional
65
+ end
66
+ it "returns true if optionality flag is set" do
67
+ expect(Saper::Argument.new(:text, :optional => true)).to be_optional
68
+ end
45
69
  end
46
70
  end
@@ -1,22 +1,32 @@
1
1
  require './spec/spec_helper'
2
2
 
3
- describe Saper::Browser do
3
+ RSpec.describe Saper::Browser do
4
4
  let :subject do
5
5
  Saper::Browser.new
6
6
  end
7
- it "#history returns an empty array by default" do
8
- subject.history.must_equal []
7
+ context "#history" do
8
+ it "returns an empty array by default" do
9
+ expect(subject.history).to eq []
10
+ end
9
11
  end
10
- it "#headers returns an empty Hash by default" do
11
- subject.headers.must_equal({})
12
+ context "#headers" do
13
+ it "returns an empty Hash by default" do
14
+ expect(subject.headers).to eq({})
15
+ end
12
16
  end
13
- it "#received returns zero by default" do
14
- subject.received.must_equal 0
17
+ context "#received" do
18
+ it "returns zero by default" do
19
+ expect(subject.received).to eq 0
20
+ end
15
21
  end
16
- it "#sent returns zero by default" do
17
- subject.sent.must_equal 0
22
+ context "#sent" do
23
+ it "returns zero by default" do
24
+ expect(subject.sent).to eq 0
25
+ end
18
26
  end
19
- it "#agent returns User-Agent string" do
20
- subject.agent.must_include 'Mozilla'
27
+ context "#agent" do
28
+ it "returns User-Agent string" do
29
+ expect(subject.agent).to include 'Mozilla'
30
+ end
21
31
  end
22
32
  end
@@ -1,6 +1,6 @@
1
1
  require './spec/spec_helper'
2
2
 
3
- describe Saper::DSL::Recipe do
3
+ RSpec.describe Saper::DSL::Recipe do
4
4
 
5
5
  it # TODO
6
6
 
@@ -1,6 +1,6 @@
1
1
  require './spec/spec_helper'
2
2
 
3
- describe Saper::Item do
3
+ RSpec.describe Saper::Item do
4
4
 
5
5
  it #TODO
6
6
 
@@ -1,6 +1,6 @@
1
1
  require './spec/spec_helper'
2
2
 
3
- describe Saper::Keychain do
3
+ RSpec.describe Saper::Keychain do
4
4
 
5
5
  it # TODO
6
6
 
@@ -1,6 +1,6 @@
1
1
  require './spec/spec_helper'
2
2
 
3
- describe Saper::Logger do
3
+ RSpec.describe Saper::Logger do
4
4
 
5
5
  it # TODO
6
6
 
@@ -1,6 +1,6 @@
1
1
  require './spec/spec_helper'
2
2
 
3
- describe Saper::Namespace do
3
+ RSpec.describe Saper::Namespace do
4
4
 
5
5
  it # TODO
6
6
 
@@ -1,58 +1,92 @@
1
1
  require './spec/spec_helper'
2
2
 
3
- describe Saper::Recipe do
3
+ RSpec.describe Saper::Recipe do
4
4
  let :subject do
5
5
  Saper::Recipe.new
6
6
  end
7
- it ".unserialize returns a Recipe when supplied with a valid Hash" do
8
- Saper::Recipe.unserialize({ :id => 0 }).must_be_kind_of(Saper::Recipe)
9
- end
10
- it ".unserialize returns an Array when supplied with a valid Array" do
11
- Saper::Recipe.unserialize([{ :id => 0 }, { :id => 1 }]).must_be_kind_of(Array)
12
- end
13
- it ".unserialize raises InvalidRecipe when supplied with nil" do
14
- lambda { Saper::Recipe.unserialize(nil) }.must_raise(Saper::InvalidRecipe)
15
- end
16
- it "#id returns recipe ID" do
17
- subject.id.must_be_kind_of(String)
18
- end
19
- it "#actions returns an empty array by default" do
20
- subject.actions.must_equal []
21
- end
22
- it "#<< returns self when supplied with a valid action" do
23
- (Saper::Recipe.new << Saper::Action.new(:nothing)).must_be_kind_of(Saper::Recipe)
24
- end
25
- it "#<< raises ActionExpected when supplied with an invalid argument" do
26
- lambda { Saper::Recipe.new << 'not an action' }.must_raise(Saper::ActionExpected)
27
- end
28
- it "#push returns self when supplied with a valid action" do
29
- Saper::Recipe.new.push(Saper::Action.new(:nothing)).must_be_kind_of(Saper::Recipe)
30
- end
31
- it "#push raises ActionExpected when supplied with an invalid argument" do
32
- lambda { Saper::Recipe.new.push('not an action') }.must_raise(Saper::ActionExpected)
33
- end
34
- it "#empty? returns true by default" do
35
- subject.must_be :empty?
36
- end
37
- it "#multiple? returns false by default" do
38
- subject.wont_be :multiple?
39
- end
40
- it "#input_required returns empty array by default" do
41
- subject.input_required.must_equal []
42
- end
43
- it "#input_required? returns false by default" do
44
- subject.wont_be :input_required?
45
- end
46
- it"#run returns Result instance" do
47
- subject.run.must_be_kind_of(Saper::Result)
48
- end
49
- it "#serialize returns a Hash" do
50
- subject.serialize.must_be_kind_of(Hash)
51
- end
52
- it "#to_string returns a string" do
53
- subject.to_string.must_be_kind_of(String)
54
- end
55
- it "#to_json returns a string" do
56
- subject.to_json.must_be_kind_of(String)
7
+ context ".unserialize(Hash)" do
8
+ it "returns a Recipe instance" do
9
+ expect(Saper::Recipe.unserialize({ :id => 0 })).to be_a Saper::Recipe
10
+ end
11
+ end
12
+ context ".unserialize(Array)" do
13
+ it "returns an Array" do
14
+ expect(Saper::Recipe.unserialize([{ :id => 0 }, { :id => 1 }])).to be_a Array
15
+ end
16
+ end
17
+ context ".unserialize(nil)" do
18
+ it "raises InvalidRecipe" do
19
+ expect { Saper::Recipe.unserialize(nil) }.to raise_error Saper::InvalidRecipe
20
+ end
21
+ end
22
+ context "#id" do
23
+ it "returns recipe ID" do
24
+ expect(subject.id).to be_a(String)
25
+ end
26
+ end
27
+ context "#actions" do
28
+ it "returns an empty array by default" do
29
+ expect(subject.actions).to eq []
30
+ end
31
+ end
32
+ context "#<<(action)" do
33
+ it "returns self" do
34
+ expect(Saper::Recipe.new << Saper::Action.new(:nothing)).to be_a Saper::Recipe
35
+ end
36
+ end
37
+ context "#<<(invalid)" do
38
+ it "raises ActionExpected" do
39
+ expect { Saper::Recipe.new << 'not an action' }.to raise_error Saper::ActionExpected
40
+ end
41
+ end
42
+ context "#push(action)" do
43
+ it "returns self" do
44
+ expect(Saper::Recipe.new.push(Saper::Action.new(:nothing))).to be_a Saper::Recipe
45
+ end
46
+ end
47
+ context "#push(invalid)" do
48
+ it "raises ActionExpected" do
49
+ expect { Saper::Recipe.new.push('not an action') }.to raise_error Saper::ActionExpected
50
+ end
51
+ end
52
+ context "#empty?" do
53
+ it "returns true by default" do
54
+ expect(subject).to be_empty
55
+ end
56
+ end
57
+ context "#multiple?" do
58
+ it "returns false by default" do
59
+ expect(subject).to_not be_multiple
60
+ end
61
+ end
62
+ context "#requires" do
63
+ it "returns empty array by default" do
64
+ expect(subject.requires).to eq []
65
+ end
66
+ end
67
+ context "#requires?" do
68
+ it "returns false by default" do
69
+ expect(subject.requires?).to be false
70
+ end
71
+ end
72
+ context "#run" do
73
+ it "returns Result instance" do
74
+ expect(subject.run).to be_a Saper::Result
75
+ end
76
+ end
77
+ context "#serialize" do
78
+ it "returns a Hash" do
79
+ expect(subject.serialize).to be_a Hash
80
+ end
81
+ end
82
+ context "#to_string" do
83
+ it "returns a string" do
84
+ expect(subject.to_string).to be_a String
85
+ end
86
+ end
87
+ context "#to_json" do
88
+ it "returns a string" do
89
+ expect(subject.to_json).to be_a String
90
+ end
57
91
  end
58
92
  end