saper 0.5.1 → 0.5.2
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 +3 -0
- data/Rakefile +6 -6
- data/bin/saper +17 -36
- data/lib/saper.rb +63 -20
- data/lib/saper/actions/append_with.rb +1 -1
- data/lib/saper/actions/convert_to_html.rb +1 -1
- data/lib/saper/actions/convert_to_json.rb +6 -2
- data/lib/saper/actions/convert_to_markdown.rb +1 -1
- data/lib/saper/actions/convert_to_time.rb +38 -1
- data/lib/saper/actions/convert_to_xml.rb +1 -1
- data/lib/saper/actions/create_atom.rb +6 -2
- data/lib/saper/actions/fetch.rb +3 -2
- data/lib/saper/actions/fetch_with_token.rb +18 -0
- data/lib/saper/actions/find.rb +1 -1
- data/lib/saper/actions/find_first.rb +1 -1
- data/lib/saper/actions/get_attribute.rb +7 -2
- data/lib/saper/actions/get_contents.rb +1 -1
- data/lib/saper/actions/get_text.rb +1 -1
- data/lib/saper/actions/nothing.rb +11 -0
- data/lib/saper/actions/prepend_with.rb +2 -2
- data/lib/saper/actions/remove_after.rb +2 -2
- data/lib/saper/actions/remove_before.rb +2 -2
- data/lib/saper/actions/remove_matching.rb +2 -2
- data/lib/saper/actions/remove_tags.rb +1 -1
- data/lib/saper/actions/replace.rb +1 -1
- data/lib/saper/actions/run_recipe.rb +2 -2
- data/lib/saper/actions/run_recipe_and_save.rb +3 -3
- data/lib/saper/actions/save.rb +2 -2
- data/lib/saper/actions/select_matching.rb +2 -2
- data/lib/saper/actions/set_input.rb +1 -1
- data/lib/saper/actions/skip_tags.rb +1 -1
- data/lib/saper/actions/split.rb +1 -1
- data/lib/saper/arguments/attribute.rb +6 -0
- data/lib/saper/arguments/recipe.rb +12 -6
- data/lib/saper/arguments/service.rb +12 -0
- data/lib/saper/arguments/text.rb +1 -0
- data/lib/saper/arguments/timezone.rb +2 -1
- data/lib/saper/arguments/url.rb +12 -0
- data/lib/saper/arguments/variable.rb +2 -1
- data/lib/saper/arguments/xpath.rb +2 -1
- data/lib/saper/core/action.rb +43 -13
- data/lib/saper/core/argument.rb +30 -14
- data/lib/saper/core/browser.rb +29 -28
- data/lib/saper/core/dsl.rb +14 -16
- data/lib/saper/core/error.rb +1 -1
- data/lib/saper/core/item.rb +2 -2
- data/lib/saper/core/keychain.rb +58 -5
- data/lib/saper/core/namespace.rb +15 -18
- data/lib/saper/core/recipe.rb +53 -12
- data/lib/saper/core/result.rb +72 -0
- data/lib/saper/core/runtime.rb +44 -177
- data/lib/saper/core/stack.rb +57 -0
- data/lib/saper/items/atom.rb +18 -1
- data/lib/saper/items/document.rb +39 -19
- data/lib/saper/items/html.rb +52 -7
- data/lib/saper/items/json.rb +19 -1
- data/lib/saper/items/markdown.rb +14 -4
- data/lib/saper/items/nothing.rb +6 -0
- data/lib/saper/items/text.rb +28 -3
- data/lib/saper/items/time.rb +25 -2
- data/lib/saper/items/url.rb +8 -2
- data/lib/saper/items/xml.rb +51 -11
- data/lib/{lib → saper/patches}/mechanize.rb +0 -0
- data/lib/{lib → saper/patches}/nokogiri.rb +0 -0
- data/lib/saper/version.rb +2 -2
- data/spec/actions/append_with_spec.rb +29 -52
- data/spec/actions/convert_to_html_spec.rb +13 -30
- data/spec/actions/convert_to_json_spec.rb +13 -30
- data/spec/actions/convert_to_markdown_spec.rb +17 -19
- data/spec/actions/convert_to_time_spec.rb +25 -43
- data/spec/actions/convert_to_xml_spec.rb +15 -11
- data/spec/actions/create_atom_spec.rb +11 -19
- data/spec/actions/fetch_spec.rb +3 -8
- data/spec/actions/find_first_spec.rb +38 -40
- data/spec/actions/find_spec.rb +23 -39
- data/spec/actions/get_attribute_spec.rb +30 -3
- data/spec/actions/{get_contents.rb → get_contents_spec.rb} +0 -0
- data/spec/actions/{get_text.rb → get_text_spec.rb} +0 -0
- data/spec/actions/nothing_spec.rb +7 -0
- data/spec/actions/prepend_with_spec.rb +31 -18
- data/spec/actions/{remove_after.rb → remove_after_spec.rb} +0 -0
- data/spec/actions/{remove_before.rb → remove_before_spec.rb} +0 -0
- data/spec/actions/remove_matching_spec.rb +7 -0
- data/spec/actions/remove_tags_spec.rb +7 -0
- data/spec/actions/run_recipe_and_save_spec.rb +7 -0
- data/spec/actions/run_recipe_spec.rb +7 -0
- data/spec/arguments/attribute_spec.rb +7 -0
- data/spec/arguments/recipe_spec.rb +7 -0
- data/spec/arguments/text_spec.rb +7 -0
- data/spec/arguments/timezone_spec.rb +7 -0
- data/spec/arguments/variable_spec.rb +7 -0
- data/spec/arguments/xpath_spec.rb +7 -0
- data/spec/core/action_spec.rb +13 -142
- data/spec/core/argument_spec.rb +38 -71
- data/spec/core/browser_spec.rb +18 -3
- data/spec/core/dsl_spec.rb +1 -1
- data/spec/core/item_spec.rb +1 -1
- data/spec/core/namespace_spec.rb +0 -11
- data/spec/core/recipe_spec.rb +54 -77
- data/spec/core/result_spec.rb +7 -0
- data/spec/core/runtime_spec.rb +20 -151
- data/spec/core/stack_spec.rb +7 -0
- data/spec/integration/simple_invalid_spec.rb +39 -0
- data/spec/integration/simple_valid_spec.rb +39 -0
- data/spec/items/atom_spec.rb +6 -1
- data/spec/items/document_spec.rb +93 -15
- data/spec/items/html_spec.rb +45 -28
- data/spec/items/json_spec.rb +10 -10
- data/spec/items/markdown_spec.rb +24 -3
- data/spec/items/nothing_spec.rb +1 -1
- data/spec/items/text_spec.rb +13 -41
- data/spec/items/time_spec.rb +25 -4
- data/spec/items/url_spec.rb +1 -7
- data/spec/items/xml_spec.rb +46 -39
- data/spec/spec_helper.rb +2 -21
- metadata +63 -60
- data/lib/lib/json_search.rb +0 -54
- data/spec/actions/run_recipe_and_save_spec.tmp.rb +0 -52
- data/spec/actions/run_recipe_spec.tmp.rb +0 -53
data/spec/actions/find_spec.rb
CHANGED
@@ -1,51 +1,35 @@
|
|
1
1
|
require './spec/spec_helper'
|
2
2
|
|
3
3
|
describe Saper::Actions::Find do
|
4
|
-
|
5
|
-
let(:action) do
|
4
|
+
let :subject do
|
6
5
|
Saper::Actions::Find.new("//p")
|
7
6
|
end
|
8
|
-
|
9
|
-
|
10
|
-
it "raises InvalidArgument" do
|
11
|
-
expect { Saper::Actions::Find.new(nil) }.to raise_error(Saper::InvalidArgument)
|
12
|
-
end
|
7
|
+
let :html do
|
8
|
+
Saper::Items::HTML.new('<div><p>test</p><p>test</p></div>')
|
13
9
|
end
|
14
|
-
|
15
|
-
|
16
|
-
it "raises no errors" do
|
17
|
-
expect { Saper::Actions::Find.new("a") }.to_not raise_error
|
18
|
-
end
|
10
|
+
let :json do
|
11
|
+
Saper::Items::JSON.new('{"p":{"a":0},"z":{"a":1}}')
|
19
12
|
end
|
20
|
-
|
21
|
-
|
22
|
-
it "raises InvalidInput" do
|
23
|
-
expect { action.run(nil) }.to raise_error(Saper::InvalidInput)
|
24
|
-
end
|
13
|
+
it ".new(nil) raises InvalidArgument" do
|
14
|
+
lambda { Saper::Actions::Find.new(nil) }.must_raise(Saper::InvalidArgument)
|
25
15
|
end
|
26
|
-
|
27
|
-
|
28
|
-
let(:input) do
|
29
|
-
Saper::Items::HTML.new('<div><p>test</p><p>test</p></div>')
|
30
|
-
end
|
31
|
-
it "returns an array of results" do
|
32
|
-
action.run(input).should be_a(Array)
|
33
|
-
end
|
34
|
-
it "returns an array with first item an HTML instance" do
|
35
|
-
action.run(input).first.should be_a(Saper::Items::HTML)
|
36
|
-
end
|
16
|
+
it ".new(CSS) raises no errors" do
|
17
|
+
lambda { Saper::Actions::Find.new("a") }.must_be_silent
|
37
18
|
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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)
|
24
|
+
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)
|
27
|
+
end
|
28
|
+
it "#run(JSON) returns an array of results" do
|
29
|
+
subject.run(json).must_be_instance_of(Array)
|
30
|
+
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)
|
49
33
|
end
|
50
34
|
|
51
35
|
end
|
@@ -1,7 +1,34 @@
|
|
1
1
|
require './spec/spec_helper'
|
2
2
|
|
3
3
|
describe Saper::Actions::GetAttribute do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
let :subject do
|
5
|
+
Saper::Actions::GetAttribute.new("class")
|
6
|
+
end
|
7
|
+
let :html do
|
8
|
+
Saper::Items::HTML.new('<div class="ok"></div>').find("div")
|
9
|
+
end
|
10
|
+
let :xml do
|
11
|
+
Saper::Items::XML.new('<item class="ok"></item>').find("item")
|
12
|
+
end
|
13
|
+
it ".new(nil) raises InvalidArgument" do
|
14
|
+
lambda { Saper::Actions::GetAttribute.new(nil) }.must_raise(Saper::InvalidArgument)
|
15
|
+
end
|
16
|
+
it ".new(String) raises no errors" do
|
17
|
+
lambda { Saper::Actions::GetAttribute.new("a") }.must_be_silent
|
18
|
+
end
|
19
|
+
it "#run(nil) raises InvalidInput" do
|
20
|
+
lambda { subject.run(nil) }.must_raise(Saper::InvalidInput)
|
21
|
+
end
|
22
|
+
it "#run(HTML) returns Text instance" do
|
23
|
+
subject.run(html).must_be_instance_of(Saper::Items::Text)
|
24
|
+
end
|
25
|
+
it "#run(HTML) returns valid output" do
|
26
|
+
subject.run(html).must_be :==, 'ok'
|
27
|
+
end
|
28
|
+
it "#run(XML) returns Text instance" do
|
29
|
+
subject.run(xml).must_be_instance_of(Saper::Items::Text)
|
30
|
+
end
|
31
|
+
it "#run(XML) returns valid output" do
|
32
|
+
subject.run(xml).must_be :==, 'ok'
|
33
|
+
end
|
7
34
|
end
|
File without changes
|
File without changes
|
@@ -1,24 +1,37 @@
|
|
1
1
|
require './spec/spec_helper'
|
2
2
|
|
3
3
|
describe Saper::Actions::PrependWith do
|
4
|
-
|
5
|
-
let(:action) do
|
4
|
+
let :subject do
|
6
5
|
Saper::Action.new(:prepend_with, '!')
|
7
6
|
end
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
|
7
|
+
it ".new(nil) raises InvalidArgument" do
|
8
|
+
lambda { Saper::Actions::PrependWith.new }.must_raise(Saper::InvalidArgument)
|
9
|
+
end
|
10
|
+
it ".new(Numeric) raises InvalidArgument" do
|
11
|
+
lambda { Saper::Actions::PrependWith.new(2) }.must_raise(Saper::InvalidArgument)
|
12
|
+
end
|
13
|
+
it ".new(Hash) raises InvalidArgumenth" do
|
14
|
+
lambda { Saper::Actions::PrependWith.new({}) }.must_raise(Saper::InvalidArgument)
|
15
|
+
end
|
16
|
+
it ".new(Array) raises InvalidArgument" do
|
17
|
+
lambda { Saper::Actions::PrependWith.new([]) }.must_raise(Saper::InvalidArgument)
|
18
|
+
end
|
19
|
+
it ".new(String)returns Action instance" do
|
20
|
+
Saper::Actions::PrependWith.new("!").must_be_kind_of(Saper::Action)
|
21
|
+
end
|
22
|
+
it "#run(nil) raises InvalidInput" do
|
23
|
+
lambda { subject.run(nil) }.must_raise(Saper::InvalidInput)
|
24
|
+
end
|
25
|
+
it "#run(Numeric) returns valid output" do
|
26
|
+
lambda { subject.run(1) }.must_raise(Saper::InvalidInput)
|
27
|
+
end
|
28
|
+
it "#run(String) returns valid output" do
|
29
|
+
subject.run('string').must_be :==, '!string'
|
30
|
+
end
|
31
|
+
it "#run(Text) returns valid output" do
|
32
|
+
subject.run(Saper::Items::Text.new('string')).must_be :==, '!string'
|
33
|
+
end
|
34
|
+
it "#run returns Text instance" do
|
35
|
+
subject.run('string').must_be_instance_of(Saper::Items::Text)
|
36
|
+
end
|
24
37
|
end
|
File without changes
|
File without changes
|
data/spec/core/action_spec.rb
CHANGED
@@ -1,151 +1,22 @@
|
|
1
1
|
require './spec/spec_helper'
|
2
2
|
|
3
3
|
describe Saper::Action do
|
4
|
-
|
5
|
-
|
6
|
-
it "raises ActionNotFound with unrecognized type" do
|
7
|
-
expect { Saper::Action[:unknown] }.to raise_error(Saper::ActionNotFound)
|
8
|
-
end
|
4
|
+
it ".[] raises ActionNotFound when supplied with invalid type" do
|
5
|
+
lambda { Saper::Action[:unknown] }.must_raise(Saper::ActionNotFound)
|
9
6
|
end
|
10
|
-
|
11
|
-
|
12
|
-
it "raises ActionNotFound" do
|
13
|
-
expect { Saper::Action.new(:unknown) }.to raise_error(Saper::ActionNotFound)
|
14
|
-
end
|
7
|
+
it ".new raises ActionNotFound when supplied with invalid type" do
|
8
|
+
lambda { Saper::Action.new(:unknown) }.must_raise(Saper::ActionNotFound)
|
15
9
|
end
|
16
|
-
|
17
|
-
|
18
|
-
it "returns an empty array" do
|
19
|
-
Saper::Action.accepts.should == []
|
20
|
-
end
|
10
|
+
it ".new returns Action when supplied with valid type" do
|
11
|
+
Saper::Action.new(:nothing).must_be_kind_of(Saper::Actions::Nothing)
|
21
12
|
end
|
22
|
-
|
23
|
-
|
24
|
-
it "returns Action instance" do
|
25
|
-
Saper::Action.unserialize({ :type => :test_action }).should be_a(Saper::Action)
|
26
|
-
end
|
13
|
+
it ".unserialize raises InvalidAction when supplied with nil" do
|
14
|
+
lambda { Saper::Action.unserialize(nil) }.must_raise(Saper::InvalidAction)
|
27
15
|
end
|
28
|
-
|
29
|
-
|
30
|
-
it "returns an Array" do
|
31
|
-
Saper::Action.unserialize([{ :type => :test_action }, { :type => :test_action }]).should be_a(Array)
|
32
|
-
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)
|
33
18
|
end
|
34
|
-
|
35
|
-
|
36
|
-
it "raises InvalidAction" do
|
37
|
-
expect { Saper::Action.unserialize(nil) }.to raise_error(Saper::InvalidAction)
|
38
|
-
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)
|
39
21
|
end
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
describe TestAction do
|
44
|
-
|
45
|
-
context ".type" do
|
46
|
-
it "returns underscored class name" do
|
47
|
-
TestAction.type.should == 'test_action'
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context ".accepts" do
|
52
|
-
it "returns an array of acceptable input types" do
|
53
|
-
TestAction.accepts.should == [:text]
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context ".[]" do
|
58
|
-
it "returns new class" do
|
59
|
-
Saper::Action[:test_action].should == TestAction
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context ".new" do
|
64
|
-
it "returns an instance of new class" do
|
65
|
-
Saper::Action.new(:test_action).should be_a(TestAction)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context "#name" do
|
70
|
-
it "returns human readable name" do
|
71
|
-
TestAction.new.name.should == 'Test Action'
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context "#options" do
|
76
|
-
it "returns empty Hash by default" do
|
77
|
-
TestAction.new.options.should == {}
|
78
|
-
end
|
79
|
-
it "returns Hash when options are set" do
|
80
|
-
TestAction.new(:test => true).options.should == { :test => true }
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context "#namespace" do
|
85
|
-
it "returns nil by default" do
|
86
|
-
TestAction.new.namespace.should be_nil
|
87
|
-
end
|
88
|
-
it "returns Saper::Namespace when set" do
|
89
|
-
TestAction.new(:namespace => Saper::Namespace.new).namespace.should be_a(Saper::Namespace)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
context "#run with valid input" do
|
94
|
-
it "returns input by default" do
|
95
|
-
TestAction.new.run("OK").should == 'OK'
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
context "#run with invalid input" do
|
100
|
-
it "raises InvalidInput" do
|
101
|
-
expect { TestAction.new.run(nil) }.to raise_error(Saper::InvalidInput)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
context "#serialize" do
|
106
|
-
it "returns a Hash" do
|
107
|
-
TestAction.new.serialize.should be_a(Hash)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
describe ActionWithMandatoryArgument do
|
114
|
-
|
115
|
-
context ".new" do
|
116
|
-
it "raises InvalidArgument when argument is missing" do
|
117
|
-
expect { ActionWithMandatoryArgument.new }.to raise_error(Saper::InvalidArgument)
|
118
|
-
end
|
119
|
-
it "raises no errors when argument is present" do
|
120
|
-
expect { ActionWithMandatoryArgument.new("text") }.to_not raise_error
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
context "#run with valid input" do
|
125
|
-
it "returns valid output" do
|
126
|
-
ActionWithMandatoryArgument.new("append this").run("with that").should == 'append this with that'
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
context "#run with invalid input" do
|
131
|
-
it "raises InvalidInput" do
|
132
|
-
expect { ActionWithMandatoryArgument.new("text").run(nil) }.to raise_error(Saper::InvalidInput)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
end
|
137
|
-
|
138
|
-
describe ActionWithOptionalArgument do
|
139
|
-
|
140
|
-
context ".new" do
|
141
|
-
it "raises no errors when argument is missing" do
|
142
|
-
expect { ActionWithOptionalArgument.new }.to_not raise_error
|
143
|
-
end
|
144
|
-
it "raises no errors when argument is present" do
|
145
|
-
expect { ActionWithOptionalArgument.new("text") }.to_not raise_error
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
end
|
150
|
-
|
151
|
-
|
22
|
+
end
|
data/spec/core/argument_spec.rb
CHANGED
@@ -1,79 +1,46 @@
|
|
1
1
|
require './spec/spec_helper'
|
2
2
|
|
3
3
|
describe Saper::Argument do
|
4
|
-
|
5
|
-
|
6
|
-
context "when required value is nil" do
|
7
|
-
it "raises InvalidArgument" do
|
8
|
-
expect { Saper::Argument.new(:text, :value => nil) }.to raise_error(Saper::InvalidArgument)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
context "when required value is missing" do
|
12
|
-
it "raises InvalidArgument" do
|
13
|
-
expect { Saper::Argument.new(:text) }.to raise_error(Saper::InvalidArgument)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
context "when required value is invalid" do
|
17
|
-
it "raises InvalidArgument" do
|
18
|
-
expect { Saper::Argument.new(:text, :value => 1) }.to raise_error(Saper::InvalidArgument)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
context "when required value is valid" do
|
22
|
-
it "raises no exceptions" do
|
23
|
-
expect { Saper::Argument.new(:text, :value => "text") }.to_not raise_error
|
24
|
-
end
|
25
|
-
end
|
26
|
-
context "when optional value is missing" do
|
27
|
-
it "raises no exceptions" do
|
28
|
-
expect { Saper::Argument.new(:text, :optional => true) }.to_not raise_error
|
29
|
-
end
|
30
|
-
end
|
31
|
-
context "when optional value is invalid" do
|
32
|
-
it "raises InvalidArgument" do
|
33
|
-
expect { Saper::Argument.new(:text, :optional => true, :value => 1) }.to raise_error(Saper::InvalidArgument)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
context "when optional value is valid" do
|
37
|
-
it "returns Action instance" do
|
38
|
-
expect { Saper::Argument.new(:text, :optional => true, :value => "text") }.to_not raise_error
|
39
|
-
end
|
40
|
-
end
|
4
|
+
it ".new raises InvalidArgument when required value is nil" do
|
5
|
+
lambda { Saper::Argument.new(:text, :value => nil) }.must_raise(Saper::InvalidArgument)
|
41
6
|
end
|
42
|
-
|
43
|
-
|
44
|
-
context "when required value is invalid" do
|
45
|
-
it "raises InvalidArgument" do
|
46
|
-
expect { Saper::Argument.new(:text, :value => "text").set(1) }.to raise_error(Saper::InvalidArgument)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
context "when optional value is invalid" do
|
50
|
-
it "raises InvalidArgument" do
|
51
|
-
expect { Saper::Argument.new(:text, :optional => true, :value => "text").set(1) }.to raise_error(Saper::InvalidArgument)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
context "when value is valid" do
|
55
|
-
it "returns self" do
|
56
|
-
Saper::Argument.new(:text, :optional => true).set("text").should be_a(Saper::Argument)
|
57
|
-
end
|
58
|
-
end
|
7
|
+
it ".new raises InvalidArgument when required value is missing" do
|
8
|
+
lambda { Saper::Argument.new(:text) }.must_raise(Saper::InvalidArgument)
|
59
9
|
end
|
60
|
-
|
61
|
-
|
62
|
-
it "returns nil by default" do
|
63
|
-
Saper::Argument.new(:text, :optional => true).value.should be_nil
|
64
|
-
end
|
65
|
-
it "returns stored value" do
|
66
|
-
Saper::Argument.new(:text, :value => "text").value.should == "text"
|
67
|
-
end
|
10
|
+
it ".new raises InvalidArgument when required value is invalid" do
|
11
|
+
lambda { Saper::Argument.new(:text, :value => 1) }.must_raise(Saper::InvalidArgument)
|
68
12
|
end
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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)
|
15
|
+
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)
|
18
|
+
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)
|
21
|
+
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)
|
24
|
+
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)
|
27
|
+
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)
|
30
|
+
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)
|
33
|
+
end
|
34
|
+
it "#value returns nil by default" do
|
35
|
+
Saper::Argument.new(:text, :optional => true).value.must_be_nil
|
36
|
+
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?
|
77
45
|
end
|
78
|
-
|
79
46
|
end
|