saper 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -0
  3. data/Rakefile +6 -6
  4. data/bin/saper +17 -36
  5. data/lib/saper.rb +63 -20
  6. data/lib/saper/actions/append_with.rb +1 -1
  7. data/lib/saper/actions/convert_to_html.rb +1 -1
  8. data/lib/saper/actions/convert_to_json.rb +6 -2
  9. data/lib/saper/actions/convert_to_markdown.rb +1 -1
  10. data/lib/saper/actions/convert_to_time.rb +38 -1
  11. data/lib/saper/actions/convert_to_xml.rb +1 -1
  12. data/lib/saper/actions/create_atom.rb +6 -2
  13. data/lib/saper/actions/fetch.rb +3 -2
  14. data/lib/saper/actions/fetch_with_token.rb +18 -0
  15. data/lib/saper/actions/find.rb +1 -1
  16. data/lib/saper/actions/find_first.rb +1 -1
  17. data/lib/saper/actions/get_attribute.rb +7 -2
  18. data/lib/saper/actions/get_contents.rb +1 -1
  19. data/lib/saper/actions/get_text.rb +1 -1
  20. data/lib/saper/actions/nothing.rb +11 -0
  21. data/lib/saper/actions/prepend_with.rb +2 -2
  22. data/lib/saper/actions/remove_after.rb +2 -2
  23. data/lib/saper/actions/remove_before.rb +2 -2
  24. data/lib/saper/actions/remove_matching.rb +2 -2
  25. data/lib/saper/actions/remove_tags.rb +1 -1
  26. data/lib/saper/actions/replace.rb +1 -1
  27. data/lib/saper/actions/run_recipe.rb +2 -2
  28. data/lib/saper/actions/run_recipe_and_save.rb +3 -3
  29. data/lib/saper/actions/save.rb +2 -2
  30. data/lib/saper/actions/select_matching.rb +2 -2
  31. data/lib/saper/actions/set_input.rb +1 -1
  32. data/lib/saper/actions/skip_tags.rb +1 -1
  33. data/lib/saper/actions/split.rb +1 -1
  34. data/lib/saper/arguments/attribute.rb +6 -0
  35. data/lib/saper/arguments/recipe.rb +12 -6
  36. data/lib/saper/arguments/service.rb +12 -0
  37. data/lib/saper/arguments/text.rb +1 -0
  38. data/lib/saper/arguments/timezone.rb +2 -1
  39. data/lib/saper/arguments/url.rb +12 -0
  40. data/lib/saper/arguments/variable.rb +2 -1
  41. data/lib/saper/arguments/xpath.rb +2 -1
  42. data/lib/saper/core/action.rb +43 -13
  43. data/lib/saper/core/argument.rb +30 -14
  44. data/lib/saper/core/browser.rb +29 -28
  45. data/lib/saper/core/dsl.rb +14 -16
  46. data/lib/saper/core/error.rb +1 -1
  47. data/lib/saper/core/item.rb +2 -2
  48. data/lib/saper/core/keychain.rb +58 -5
  49. data/lib/saper/core/namespace.rb +15 -18
  50. data/lib/saper/core/recipe.rb +53 -12
  51. data/lib/saper/core/result.rb +72 -0
  52. data/lib/saper/core/runtime.rb +44 -177
  53. data/lib/saper/core/stack.rb +57 -0
  54. data/lib/saper/items/atom.rb +18 -1
  55. data/lib/saper/items/document.rb +39 -19
  56. data/lib/saper/items/html.rb +52 -7
  57. data/lib/saper/items/json.rb +19 -1
  58. data/lib/saper/items/markdown.rb +14 -4
  59. data/lib/saper/items/nothing.rb +6 -0
  60. data/lib/saper/items/text.rb +28 -3
  61. data/lib/saper/items/time.rb +25 -2
  62. data/lib/saper/items/url.rb +8 -2
  63. data/lib/saper/items/xml.rb +51 -11
  64. data/lib/{lib → saper/patches}/mechanize.rb +0 -0
  65. data/lib/{lib → saper/patches}/nokogiri.rb +0 -0
  66. data/lib/saper/version.rb +2 -2
  67. data/spec/actions/append_with_spec.rb +29 -52
  68. data/spec/actions/convert_to_html_spec.rb +13 -30
  69. data/spec/actions/convert_to_json_spec.rb +13 -30
  70. data/spec/actions/convert_to_markdown_spec.rb +17 -19
  71. data/spec/actions/convert_to_time_spec.rb +25 -43
  72. data/spec/actions/convert_to_xml_spec.rb +15 -11
  73. data/spec/actions/create_atom_spec.rb +11 -19
  74. data/spec/actions/fetch_spec.rb +3 -8
  75. data/spec/actions/find_first_spec.rb +38 -40
  76. data/spec/actions/find_spec.rb +23 -39
  77. data/spec/actions/get_attribute_spec.rb +30 -3
  78. data/spec/actions/{get_contents.rb → get_contents_spec.rb} +0 -0
  79. data/spec/actions/{get_text.rb → get_text_spec.rb} +0 -0
  80. data/spec/actions/nothing_spec.rb +7 -0
  81. data/spec/actions/prepend_with_spec.rb +31 -18
  82. data/spec/actions/{remove_after.rb → remove_after_spec.rb} +0 -0
  83. data/spec/actions/{remove_before.rb → remove_before_spec.rb} +0 -0
  84. data/spec/actions/remove_matching_spec.rb +7 -0
  85. data/spec/actions/remove_tags_spec.rb +7 -0
  86. data/spec/actions/run_recipe_and_save_spec.rb +7 -0
  87. data/spec/actions/run_recipe_spec.rb +7 -0
  88. data/spec/arguments/attribute_spec.rb +7 -0
  89. data/spec/arguments/recipe_spec.rb +7 -0
  90. data/spec/arguments/text_spec.rb +7 -0
  91. data/spec/arguments/timezone_spec.rb +7 -0
  92. data/spec/arguments/variable_spec.rb +7 -0
  93. data/spec/arguments/xpath_spec.rb +7 -0
  94. data/spec/core/action_spec.rb +13 -142
  95. data/spec/core/argument_spec.rb +38 -71
  96. data/spec/core/browser_spec.rb +18 -3
  97. data/spec/core/dsl_spec.rb +1 -1
  98. data/spec/core/item_spec.rb +1 -1
  99. data/spec/core/namespace_spec.rb +0 -11
  100. data/spec/core/recipe_spec.rb +54 -77
  101. data/spec/core/result_spec.rb +7 -0
  102. data/spec/core/runtime_spec.rb +20 -151
  103. data/spec/core/stack_spec.rb +7 -0
  104. data/spec/integration/simple_invalid_spec.rb +39 -0
  105. data/spec/integration/simple_valid_spec.rb +39 -0
  106. data/spec/items/atom_spec.rb +6 -1
  107. data/spec/items/document_spec.rb +93 -15
  108. data/spec/items/html_spec.rb +45 -28
  109. data/spec/items/json_spec.rb +10 -10
  110. data/spec/items/markdown_spec.rb +24 -3
  111. data/spec/items/nothing_spec.rb +1 -1
  112. data/spec/items/text_spec.rb +13 -41
  113. data/spec/items/time_spec.rb +25 -4
  114. data/spec/items/url_spec.rb +1 -7
  115. data/spec/items/xml_spec.rb +46 -39
  116. data/spec/spec_helper.rb +2 -21
  117. metadata +63 -60
  118. data/lib/lib/json_search.rb +0 -54
  119. data/spec/actions/run_recipe_and_save_spec.tmp.rb +0 -52
  120. data/spec/actions/run_recipe_spec.tmp.rb +0 -53
@@ -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
- context ".new(nil)" do
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
- context ".new(CSS)" do
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
- context "#run(nil)" do
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
- context "#run(HTML)" do
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
- context "#run(JSON)" do
40
- let(:input) do
41
- Saper::Items::JSON.new('{"p":{"a":0},"z":{"a":1}}')
42
- end
43
- it "returns an array of results" do
44
- action.run(input).should be_a(Array)
45
- end
46
- it "returns an array with first item a JSON instance" do
47
- action.run(input).first.should be_a(Saper::Items::JSON)
48
- 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)
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
- it # TODO
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
@@ -0,0 +1,7 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe Saper::Actions::Nothing do
4
+
5
+ it # TODO
6
+
7
+ end
@@ -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
- context ".new" do
10
- it "raises InvalidArgument when argument is missing" do
11
- expect { subject }.to raise_error(Saper::InvalidArgument)
12
- end
13
- end
14
-
15
- context "#run" do
16
- it "raises InvalidInput when input is nil" do
17
- expect { action.run(nil) }.to raise_error(Saper::InvalidInput)
18
- end
19
- it "returns valid output when input is Text" do
20
- action.run('string').should == '!string'
21
- end
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
@@ -0,0 +1,7 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe Saper::Actions::RemoveMatching do
4
+
5
+ it # TODO
6
+
7
+ end
@@ -0,0 +1,7 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe Saper::Actions::RemoveTags do
4
+
5
+ it # TODO
6
+
7
+ end
@@ -0,0 +1,7 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe Saper::Actions::RunRecipeAndSave do
4
+
5
+ it # TODO
6
+
7
+ end
@@ -0,0 +1,7 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe Saper::Actions::RunRecipe do
4
+
5
+ it # TODO
6
+
7
+ end
@@ -0,0 +1,7 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe Saper::Arguments::Attribute do
4
+
5
+ it # TODO
6
+
7
+ end
@@ -0,0 +1,7 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe Saper::Arguments::Recipe do
4
+
5
+ it # TODO
6
+
7
+ end
@@ -0,0 +1,7 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe Saper::Arguments::Text do
4
+
5
+ it # TODO
6
+
7
+ end
@@ -0,0 +1,7 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe Saper::Arguments::Timezone do
4
+
5
+ it # TODO
6
+
7
+ end
@@ -0,0 +1,7 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe Saper::Arguments::Variable do
4
+
5
+ it # TODO
6
+
7
+ end
@@ -0,0 +1,7 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe Saper::Arguments::XPath do
4
+
5
+ it # TODO
6
+
7
+ end
@@ -1,151 +1,22 @@
1
1
  require './spec/spec_helper'
2
2
 
3
3
  describe Saper::Action do
4
-
5
- context ".[]" do
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
- context ".new with unrecognized type" do
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
- context ".accepts" do
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
- context ".unserialize(Hash)" do
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
- context ".unserialize(Array)" do
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
- context ".unserialize(nil)" do
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
@@ -1,79 +1,46 @@
1
1
  require './spec/spec_helper'
2
2
 
3
3
  describe Saper::Argument do
4
-
5
- context ".new" do
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
- context "#set" do
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
- context "#value" do
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
- context "#optional?" do
71
- it "returns false by default" do
72
- Saper::Argument.new(:text, :value => "text").should_not be_optional
73
- end
74
- it "returns true if optionality flag is set" do
75
- Saper::Argument.new(:text, :optional => true).should be_optional
76
- 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)
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